Compare commits

...

1 Commits

Author SHA1 Message Date
Potuz
7a7daadf22 Ignore blocks if their parent is older than justified 2023-12-07 07:47:23 -03:00

View File

@@ -144,7 +144,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms
cp := s.cfg.chain.FinalizedCheckpt()
startSlot, err := slots.EpochStart(cp.Epoch)
if err != nil {
log.WithError(err).WithFields(getBlockFields(blk)).Debug("Ignored block: could not calculate epoch start slot")
log.WithError(err).WithFields(getBlockFields(blk)).Debug("Ignored block: could not calculate finalized epoch start slot")
return pubsub.ValidationIgnore, nil
}
if startSlot >= blk.Block().Slot() {
@@ -190,6 +190,20 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms
return pubsub.ValidationIgnore, err
}
if !s.cfg.chain.InForkchoice(blk.Block().ParentRoot()) {
s.setBadBlock(ctx, blockRoot)
log.WithError(err).WithFields(getBlockFields(blk)).Debug("Could not validate beacon block")
return pubsub.ValidationReject, blockchain.ErrNotDescendantOfFinalized
}
cp = s.cfg.chain.CurrentJustifiedCheckpt()
slot, err := s.cfg.chain.RecentBlockSlot(blk.Block().ParentRoot())
if err != nil {
log.WithError(err).WithFields(getBlockFields(blk)).Debug("could not get parent block's slot")
} else if slots.ToEpoch(slot) < cp.Epoch {
log.WithError(err).WithFields(getBlockFields(blk)).Debug("Ignored block: parent is older than justified block")
}
err = s.validateBeaconBlock(ctx, blk, blockRoot)
if err != nil {
// If the parent is optimistic, process the block as usual
@@ -241,11 +255,6 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk interfaces.ReadOn
return err
}
if !s.cfg.chain.InForkchoice(blk.Block().ParentRoot()) {
s.setBadBlock(ctx, blockRoot)
return blockchain.ErrNotDescendantOfFinalized
}
parentState, err := s.cfg.stateGen.StateByRoot(ctx, blk.Block().ParentRoot())
if err != nil {
return err