From e1239db41ffff7e29e3794dedf1279916fafe2d8 Mon Sep 17 00:00:00 2001 From: lklimek <842586+lklimek@users.noreply.github.com> Date: Mon, 20 May 2024 15:36:13 +0200 Subject: [PATCH] chore(log): add Warn log level and decrease verbosity of some logs (#790) * refactor(log): introduce warn log level and decrease verbosity of some logs * chore(types): remove unused code --- abci/server/socket_server.go | 2 +- internal/p2p/router.go | 10 +++++----- internal/statesync/reactor.go | 2 +- libs/log/default.go | 4 ++++ libs/log/logger.go | 8 ++++++++ types/block.go | 19 ------------------- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/abci/server/socket_server.go b/abci/server/socket_server.go index ac40a604bb..650d9828f2 100644 --- a/abci/server/socket_server.go +++ b/abci/server/socket_server.go @@ -106,7 +106,7 @@ func (s *SocketServer) acceptConnectionsRoutine(ctx context.Context) { if !s.IsRunning() { return // Ignore error from listener closing. } - s.logger.Error("Failed to accept connection", "err", err) + s.logger.Warn("Failed to accept connection", "err", err) continue } diff --git a/internal/p2p/router.go b/internal/p2p/router.go index 31830139bd..0a593fb58d 100644 --- a/internal/p2p/router.go +++ b/internal/p2p/router.go @@ -433,7 +433,7 @@ func (r *Router) acceptPeers(ctx context.Context, transport Transport) { return case err != nil: // in this case we got an error from the net.Listener. - r.logger.Error("failed to accept connection", "transport", transport, "err", err) + r.logger.Warn("failed to accept connection", "transport", transport, "err", err) continue } @@ -497,7 +497,7 @@ func (r *Router) openConnection(ctx context.Context, conn Connection) { err = r.peerManager.Accepted(peerInfo.NodeID, SetProTxHashToPeerInfo(peerInfo.ProTxHash)) if err != nil { - r.logger.Error("failed to accept connection", + r.logger.Warn("failed to accept connection", "op", "incoming/accepted", "peer", peerInfo.NodeID, "err", err) return } @@ -760,16 +760,16 @@ func (r *Router) routePeer(ctx context.Context, peerID types.NodeID, conn Connec _ = conn.Close() sendQueue.close() - r.logger.Debug("routePeer: closed conn and send queue, waiting for all goroutines to finish", "peer", peerID, "err", err) + r.logger.Trace("routePeer: closed conn and send queue, waiting for all goroutines to finish", "peer", peerID, "err", err) wg.Wait() - r.logger.Debug("routePeer: all goroutines finished", "peer", peerID, "err", err) + r.logger.Trace("routePeer: all goroutines finished", "peer", peerID, "err", err) // Drain the error channel; these should typically not be interesting FOR: for { select { case e := <-errCh: - r.logger.Debug("routePeer: received error when draining errCh", "peer", peerID, "err", e) + r.logger.Trace("routePeer: received error when draining errCh", "peer", peerID, "err", e) // if we received non-context error, we should return it if err == nil && !errors.Is(e, context.Canceled) && !errors.Is(e, context.DeadlineExceeded) { err = e diff --git a/internal/statesync/reactor.go b/internal/statesync/reactor.go index e51ae4de6a..0440e047ba 100644 --- a/internal/statesync/reactor.go +++ b/internal/statesync/reactor.go @@ -992,7 +992,7 @@ func (r *Reactor) processPeerUp(ctx context.Context, peerUpdate p2p.PeerUpdate) r.peers.Append(peerUpdate.NodeID) } else { - r.logger.Error("could not use peer for statesync", "peer", peerUpdate.NodeID) + r.logger.Warn("could not use peer for statesync", "peer", peerUpdate.NodeID) } newProvider := NewBlockProvider(peerUpdate.NodeID, r.chainID, r.dispatcher) diff --git a/libs/log/default.go b/libs/log/default.go index 6a57b35502..ade3d0d5fd 100644 --- a/libs/log/default.go +++ b/libs/log/default.go @@ -88,6 +88,10 @@ func (l defaultLogger) Info(msg string, keyVals ...interface{}) { l.Logger.Info().Fields(getLogFields(keyVals...)).Msg(msg) } +func (l defaultLogger) Warn(msg string, keyVals ...interface{}) { + l.Logger.Warn().Fields(getLogFields(keyVals...)).Msg(msg) +} + func (l defaultLogger) Error(msg string, keyVals ...interface{}) { l.Logger.Error().Fields(getLogFields(keyVals...)).Msg(msg) } diff --git a/libs/log/logger.go b/libs/log/logger.go index ccad9e0742..3caf0991c1 100644 --- a/libs/log/logger.go +++ b/libs/log/logger.go @@ -34,9 +34,17 @@ const ( type Logger interface { io.Closer + // Trace events are logged from the primary path of execution (eg. when everything goes well) Trace(msg string, keyVals ...interface{}) + // Debug events are used in non-primary path to provide fine-grained information useful for debugging Debug(msg string, keyVals ...interface{}) + // Info events provide general, business-level information about what's happening inside the application, to + // let the user know what the application is doing Info(msg string, keyVals ...interface{}) + // Warn events are used when something unexpected happened, but the application can recover/continue + Warn(msg string, keyVals ...interface{}) + // Error events are used when something unexpected happened and the application cannot recover, or the + // issue is serious and the user needs to take action Error(msg string, keyVals ...interface{}) With(keyVals ...interface{}) Logger diff --git a/types/block.go b/types/block.go index fcace70bfb..10901ca371 100644 --- a/types/block.go +++ b/types/block.go @@ -13,7 +13,6 @@ import ( sync "github.com/sasha-s/go-deadlock" - "github.com/dashpay/dashd-go/btcjson" "github.com/gogo/protobuf/proto" gogotypes "github.com/gogo/protobuf/types" "github.com/rs/zerolog" @@ -816,24 +815,6 @@ func (commit *Commit) VoteBlockRequestID() []byte { return hash[:] } -// CanonicalVoteVerifySignBytes returns the bytes of the Canonical Vote that is threshold signed. -func (commit *Commit) CanonicalVoteVerifySignBytes(chainID string) []byte { - voteCanonical := commit.GetCanonicalVote() - vCanonical := voteCanonical.ToProto() - bz, err := vCanonical.SignBytes(chainID) - if err != nil { - panic(fmt.Errorf("canonical vote sign bytes: %w", err)) - } - return bz -} - -// CanonicalVoteVerifySignID returns the signID bytes of the Canonical Vote that is threshold signed. -func (commit *Commit) CanonicalVoteVerifySignID(chainID string, quorumType btcjson.LLMQType, quorumHash []byte) []byte { - voteCanonical := commit.GetCanonicalVote() - vCanonical := voteCanonical.ToProto() - return VoteBlockSignID(chainID, vCanonical, quorumType, quorumHash) -} - // Type returns the vote type of the commit, which is always VoteTypePrecommit // Implements VoteSetReader. func (commit *Commit) Type() byte {