diff --git a/beacon-chain/sync/initial-sync/blocks_fetcher.go b/beacon-chain/sync/initial-sync/blocks_fetcher.go index 0175ab325..6f71eb137 100644 --- a/beacon-chain/sync/initial-sync/blocks_fetcher.go +++ b/beacon-chain/sync/initial-sync/blocks_fetcher.go @@ -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") ) diff --git a/beacon-chain/sync/initial-sync/blocks_queue_test.go b/beacon-chain/sync/initial-sync/blocks_queue_test.go index 29cc32a1d..4e9947093 100644 --- a/beacon-chain/sync/initial-sync/blocks_queue_test.go +++ b/beacon-chain/sync/initial-sync/blocks_queue_test.go @@ -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 { diff --git a/beacon-chain/sync/initial-sync/round_robin.go b/beacon-chain/sync/initial-sync/round_robin.go index c5d0ed4be..b8e8b5f31 100644 --- a/beacon-chain/sync/initial-sync/round_robin.go +++ b/beacon-chain/sync/initial-sync/round_robin.go @@ -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. @@ -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 @@ -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