Skip to content

Commit

Permalink
Revert "ReceiveBlock: Only retrieve head block from DB if necessary (#…
Browse files Browse the repository at this point in the history
…4506)" (#4514)

This reverts commit 9a4bf6c.
  • Loading branch information
terencechain committed Jan 12, 2020
1 parent 9a4bf6c commit a79dab7
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions beacon-chain/blockchain/receive_block.go
Expand Up @@ -85,19 +85,16 @@ func (s *Service) ReceiveBlockNoPubsub(ctx context.Context, block *ethpb.SignedB
if err != nil {
return errors.Wrap(err, "could not get head from fork choice service")
}
signedHeadBlock, err := s.beaconDB.Block(ctx, bytesutil.ToBytes32(headRoot))
if err != nil {
return errors.Wrap(err, "could not compute state from block head")
}
if signedHeadBlock == nil || signedHeadBlock.Block == nil {
return errors.New("nil head block")
}

// Only save head if it's different than the current head.
if !bytes.Equal(headRoot, s.HeadRoot()) {
signedHeadBlock, err := s.beaconDB.Block(ctx, bytesutil.ToBytes32(headRoot))
if err != nil {
return errors.Wrap(err, "could not compute state from block head")
}
if signedHeadBlock == nil || signedHeadBlock.Block == nil {
return errors.New("nil head block")
}

logCompetingBlock(root[:], blockCopy.Block.Slot, headRoot, signedHeadBlock.Block.Slot)

if err := s.saveHead(ctx, signedHeadBlock, bytesutil.ToBytes32(headRoot)); err != nil {
return errors.Wrap(err, "could not save head")
}
Expand All @@ -121,6 +118,9 @@ func (s *Service) ReceiveBlockNoPubsub(ctx context.Context, block *ethpb.SignedB
// Reports on block and fork choice metrics.
s.reportSlotMetrics(blockCopy.Block.Slot)

// Log if block is a competing block.
isCompetingBlock(root[:], blockCopy.Block.Slot, headRoot, signedHeadBlock.Block.Slot)

// Log state transition data.
logStateTransitionData(blockCopy.Block)

Expand Down Expand Up @@ -244,12 +244,14 @@ func (s *Service) ReceiveBlockNoVerify(ctx context.Context, block *ethpb.SignedB
}

// This checks if the block is from a competing chain, emits warning and updates metrics.
func logCompetingBlock(root []byte, slot uint64, headRoot []byte, headSlot uint64) {
log.WithFields(logrus.Fields{
"blkSlot": slot,
"blkRoot": hex.EncodeToString(root[:]),
"headSlot": headSlot,
"headRoot": hex.EncodeToString(headRoot),
}).Warn("Calculated head diffs from new block")
competingBlks.Inc()
func isCompetingBlock(root []byte, slot uint64, headRoot []byte, headSlot uint64) {
if !bytes.Equal(root[:], headRoot) {
log.WithFields(logrus.Fields{
"blkSlot": slot,
"blkRoot": hex.EncodeToString(root[:]),
"headSlot": headSlot,
"headRoot": hex.EncodeToString(headRoot),
}).Warn("Calculated head diffs from new block")
competingBlks.Inc()
}
}

0 comments on commit a79dab7

Please sign in to comment.