From 05d618692c4ffca5ba3fe7d92674684343e335f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= <93934272+Stefan-Ethernal@users.noreply.github.com> Date: Wed, 22 Mar 2023 12:36:52 +0100 Subject: [PATCH] Lower log level of the `ProposerCalculator` logs (#1300) * Change logs * Lint fix --- consensus/polybft/proposer_calculator.go | 27 ++++---- .../statesyncrelayer/state_sync_relayer.go | 66 ++++++++++--------- tracker/event_tracker_store.go | 2 +- 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/consensus/polybft/proposer_calculator.go b/consensus/polybft/proposer_calculator.go index e541a51b32..acbc301991 100644 --- a/consensus/polybft/proposer_calculator.go +++ b/consensus/polybft/proposer_calculator.go @@ -198,24 +198,27 @@ func (pc *ProposerCalculator) GetSnapshot() (*ProposerSnapshot, bool) { // It will update priorities and save the updated snapshot to db func (pc *ProposerCalculator) PostBlock(req *PostBlockRequest) error { blockNumber := req.FullBlock.Block.Number() - pc.logger.Info("Update proposal snapshot started", "block", blockNumber) + pc.logger.Debug("Update proposers snapshot started", "target block", blockNumber) from := pc.snapshot.Height // using a for loop if in some previous block, an error occurred while updating snapshot - // so that we can recalculate it to have accurate priorities + // so that we can recalculate it to have accurate priorities. // Note, this will change once we introduce component wide global transaction for height := from; height <= blockNumber; height++ { if err := pc.updatePerBlock(height); err != nil { return err } + + pc.logger.Debug("Proposers snapshot has been updated", "current block", blockNumber+1, + "validators count", len(pc.snapshot.Validators)) } if err := pc.state.ProposerSnapshotStore.writeProposerSnapshot(pc.snapshot); err != nil { - return fmt.Errorf("cannot save proposer calculator snapshot for block %d: %w", blockNumber, err) + return fmt.Errorf("cannot save proposers snapshot for block %d: %w", blockNumber, err) } - pc.logger.Info("Update proposal snapshot finished", "block", blockNumber) + pc.logger.Debug("Update proposers snapshot finished", "target block", blockNumber) return nil } @@ -223,12 +226,13 @@ func (pc *ProposerCalculator) PostBlock(req *PostBlockRequest) error { // Updates ProposerSnapshot to block block with number `blockNumber` func (pc *ProposerCalculator) updatePerBlock(blockNumber uint64) error { if pc.snapshot.Height != blockNumber { - return fmt.Errorf("proposer calculator update wrong block=%d, height = %d", blockNumber, pc.snapshot.Height) + return fmt.Errorf("proposers snapshot update called for wrong block. block number=%d, snapshot block number=%d", + blockNumber, pc.snapshot.Height) } _, extra, err := getBlockData(blockNumber, pc.config.blockchain) if err != nil { - return fmt.Errorf("cannot get block header and extra while updating proposer snapshot %d: %w", blockNumber, err) + return fmt.Errorf("cannot get block header and extra while updating proposers snapshot %d: %w", blockNumber, err) } var newValidatorSet AccountSet = nil @@ -243,7 +247,7 @@ func (pc *ProposerCalculator) updatePerBlock(blockNumber uint64) error { // if round = 0 then we need one iteration _, err = incrementProposerPriorityNTimes(pc.snapshot, extra.Checkpoint.BlockRound+1) if err != nil { - return fmt.Errorf("failed to update calculator for block %d: %w", blockNumber, err) + return fmt.Errorf("failed to update proposers snapshot for block %d: %w", blockNumber, err) } // update to new validator set and center if needed @@ -255,9 +259,6 @@ func (pc *ProposerCalculator) updatePerBlock(blockNumber uint64) error { pc.snapshot.Round = 0 pc.snapshot.Proposer = nil - pc.logger.Info("proposer calculator update has been finished", "height", blockNumber+1, - "len", len(pc.snapshot.Validators)) - return nil } @@ -467,12 +468,14 @@ func computeMaxMinPriorityDiff(validators []*PrioritizedValidator) *big.Int { return diff } +// isBetterProposer compares provided PrioritizedValidator instances +// and chooses either one with higher ProposerPriority or the one with the smaller address (compared lexicographically). func isBetterProposer(a, b *PrioritizedValidator) bool { if b == nil || a.ProposerPriority.Cmp(b.ProposerPriority) > 0 { return true } else if a.ProposerPriority == b.ProposerPriority { return bytes.Compare(a.Metadata.Address.Bytes(), b.Metadata.Address.Bytes()) <= 0 - } else { - return false } + + return false } diff --git a/consensus/polybft/statesyncrelayer/state_sync_relayer.go b/consensus/polybft/statesyncrelayer/state_sync_relayer.go index 07cacfa508..d43df180d2 100644 --- a/consensus/polybft/statesyncrelayer/state_sync_relayer.go +++ b/consensus/polybft/statesyncrelayer/state_sync_relayer.go @@ -111,52 +111,54 @@ func (r *StateSyncRelayer) Stop() { } func (r *StateSyncRelayer) AddLog(log *ethgo.Log) { - r.logger.Info("Received a log", "log", log) + r.logger.Debug("Received a log", "log", log) - if commitEvent.Match(log) { - vals, err := commitEvent.ParseLog(log) - if err != nil { - r.logger.Error("Failed to parse log", "err", err) + if !commitEvent.Match(log) { + return + } - return - } + vals, err := commitEvent.ParseLog(log) + if err != nil { + r.logger.Error("Failed to parse log", "err", err) - var ( - startID, endID *big.Int - ok bool - ) + return + } - if startID, ok = vals["startId"].(*big.Int); !ok { - r.logger.Error("Failed to parse startId") + var ( + startID, endID *big.Int + ok bool + ) - return - } + if startID, ok = vals["startId"].(*big.Int); !ok { + r.logger.Error("Failed to parse startId") - if endID, ok = vals["endId"].(*big.Int); !ok { - r.logger.Error("Failed to parse endId") + return + } - return - } + if endID, ok = vals["endId"].(*big.Int); !ok { + r.logger.Error("Failed to parse endId") - r.logger.Info("Commit", "Block", log.BlockNumber, "StartID", startID, "EndID", endID) + return + } - for i := startID.Uint64(); i <= endID.Uint64(); i++ { - // query the state sync proof - stateSyncProof, err := r.queryStateSyncProof(fmt.Sprintf("0x%x", i)) - if err != nil { - r.logger.Error("Failed to query state sync proof", "err", err) + r.logger.Info("Execute commitment", "Block", log.BlockNumber, "StartID", startID, "EndID", endID) - continue - } + for i := startID.Uint64(); i <= endID.Uint64(); i++ { + // query the state sync proof + stateSyncProof, err := r.queryStateSyncProof(fmt.Sprintf("0x%x", i)) + if err != nil { + r.logger.Error("Failed to query state sync proof", "err", err) - if err := r.executeStateSync(stateSyncProof); err != nil { - r.logger.Error("Failed to execute state sync", "err", err) + continue + } - continue - } + if err := r.executeStateSync(stateSyncProof); err != nil { + r.logger.Error("Failed to execute state sync", "err", err) - r.logger.Info("State sync executed", "stateSyncID", i) + continue } + + r.logger.Info("State sync executed", "ID", i) } } diff --git a/tracker/event_tracker_store.go b/tracker/event_tracker_store.go index a623a3fb37..151e59bc8c 100644 --- a/tracker/event_tracker_store.go +++ b/tracker/event_tracker_store.go @@ -171,7 +171,7 @@ func (b *EventTrackerStore) onNewBlock(filterHash, blockData string) error { b.subscriber.AddLog(log) } - b.logger.Info("event logs have been notified to a subscriber", "len", len(logs), "next", nextToProcessIdx) + b.logger.Debug("Event logs have been notified to a subscriber", "len", len(logs), "next", nextToProcessIdx) return nil }