Skip to content

Commit

Permalink
Lower log level of the ProposerCalculator logs (0xPolygon#1300)
Browse files Browse the repository at this point in the history
* Change logs

* Lint fix
  • Loading branch information
Stefan-Ethernal authored Mar 22, 2023
1 parent 8e6c28f commit 05d6186
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 45 deletions.
27 changes: 15 additions & 12 deletions consensus/polybft/proposer_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,37 +198,41 @@ 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
}

// 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
Expand All @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
66 changes: 34 additions & 32 deletions consensus/polybft/statesyncrelayer/state_sync_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tracker/event_tracker_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 05d6186

Please sign in to comment.