Skip to content

Commit

Permalink
cleaner logging (#7689)
Browse files Browse the repository at this point in the history
  • Loading branch information
nisdas committed Oct 31, 2020
1 parent f79b168 commit df762bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions beacon-chain/sync/initial-sync/blocks_fetcher.go
Expand Up @@ -50,6 +50,7 @@ var (
errFetcherCtxIsDone = errors.New("fetcher's context is done, reinitialize")
errSlotIsTooHigh = errors.New("slot is higher than the finalized slot")
errBlockAlreadyProcessed = errors.New("block is already processed")
errParentDoesNotExist = errors.New("beacon node doesn't have a parent in db with root")
errInvalidFetchedData = errors.New("invalid data returned from peer")
)

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/sync/initial-sync/blocks_queue_test.go
Expand Up @@ -289,7 +289,7 @@ func TestBlocksQueue_Loop(t *testing.T) {
assert.NoError(t, queue.start())
processBlock := func(block *eth.SignedBeaconBlock) error {
if !beaconDB.HasBlock(ctx, bytesutil.ToBytes32(block.Block.ParentRoot)) {
return fmt.Errorf("beacon node doesn't have a block in db with root %#x", block.Block.ParentRoot)
return fmt.Errorf("%w: %#x", errParentDoesNotExist, block.Block.ParentRoot)
}
root, err := block.Block.HashTreeRoot()
if err != nil {
Expand Down
18 changes: 14 additions & 4 deletions beacon-chain/sync/initial-sync/round_robin.go
Expand Up @@ -121,16 +121,26 @@ func (s *Service) processFetchedDataRegSync(
defer s.updatePeerScorerStats(data.pid, startSlot)

blockReceiver := s.chain.ReceiveBlock
invalidBlocks := 0
for _, blk := range data.blocks {
if err := s.processBlock(ctx, genesis, blk, blockReceiver); err != nil {
if errors.Is(err, errBlockAlreadyProcessed) {
switch {
case errors.Is(err, errBlockAlreadyProcessed):
log.WithField("err", err.Error()).Debug("Block is not processed")
} else {
invalidBlocks++
case errors.Is(err, errParentDoesNotExist):
log.WithField("err", err.Error()).Debug("Block is not processed")
invalidBlocks++
default:
log.WithField("err", err.Error()).Warn("Block is not processed")
}
continue
}
}
// Add more visible logging if all blocks cannot be processed.
if len(data.blocks) == invalidBlocks {
log.WithField("err", "Range had no valid blocks to process").Warn("Range is not processed")
}
}

// highestFinalizedEpoch returns the absolute highest finalized epoch of all connected peers.
Expand Down Expand Up @@ -204,7 +214,7 @@ func (s *Service) processBlock(
s.logSyncStatus(genesis, blk.Block, blkRoot)
parentRoot := bytesutil.ToBytes32(blk.Block.ParentRoot)
if !s.db.HasBlock(ctx, parentRoot) && !s.chain.HasInitSyncBlock(parentRoot) {
return fmt.Errorf("beacon node doesn't have a block in db with root %#x", blk.Block.ParentRoot)
return fmt.Errorf("%w: %#x", errParentDoesNotExist, blk.Block.ParentRoot)
}
if err := blockReceiver(ctx, blk, blkRoot); err != nil {
return err
Expand Down Expand Up @@ -237,7 +247,7 @@ func (s *Service) processBatchedBlocks(ctx context.Context, genesis time.Time,
s.logBatchSyncStatus(genesis, blks, blkRoot)
parentRoot := bytesutil.ToBytes32(firstBlock.Block.ParentRoot)
if !s.db.HasBlock(ctx, parentRoot) && !s.chain.HasInitSyncBlock(parentRoot) {
return fmt.Errorf("beacon node doesn't have a block in db with root %#x", firstBlock.Block.ParentRoot)
return fmt.Errorf("%w: %#x", errParentDoesNotExist, firstBlock.Block.ParentRoot)
}
blockRoots := make([][32]byte, len(blks))
blockRoots[0] = blkRoot
Expand Down

0 comments on commit df762bb

Please sign in to comment.