Skip to content

Commit

Permalink
Another option, remove optimistic sync assumption
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Apr 4, 2022
1 parent 42f6952 commit 0b5bdcb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
16 changes: 7 additions & 9 deletions beacon-chain/sync/pending_blocks_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,13 @@ func (s *Service) processPendingBlocks(ctx context.Context) error {
}

if err := s.validateBeaconBlock(ctx, b, blkRoot); err != nil {
if !errors.Is(ErrOptimisticParent, err) {
log.Debugf("Could not validate block from slot %d: %v", b.Block().Slot(), err)
s.setBadBlock(ctx, blkRoot)
tracing.AnnotateError(span, err)
// In the next iteration of the queue, this block will be removed from
// the pending queue as it has been marked as a 'bad' block.
span.End()
continue
}
log.Debugf("Could not validate block from slot %d: %v", b.Block().Slot(), err)
s.setBadBlock(ctx, blkRoot)
tracing.AnnotateError(span, err)
// In the next iteration of the queue, this block will be removed from
// the pending queue as it has been marked as a 'bad' block.
span.End()
continue
}

if err := s.cfg.chain.ReceiveBlock(ctx, b, blkRoot); err != nil {
Expand Down
22 changes: 1 addition & 21 deletions beacon-chain/sync/validate_beacon_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import (
"go.opencensus.io/trace"
)

var (
ErrOptimisticParent = errors.New("parent of the block is optimistic")
)

// validateBeaconBlockPubSub checks that the incoming block has a valid BLS signature.
// Blocks that have already been seen are ignored. If the BLS signature is any valid signature,
// this method rebroadcasts the message.
Expand Down Expand Up @@ -166,11 +162,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms

err = s.validateBeaconBlock(ctx, blk, blockRoot)
if err != nil {
// If the parent is optimistic, process the block as usual
// This also does not penalize a peer which sends optimistic blocks
if !errors.Is(ErrOptimisticParent, err) {
return pubsub.ValidationReject, err
}
return pubsub.ValidationReject, err
}

// Record attribute of valid block.
Expand Down Expand Up @@ -230,10 +222,6 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk block.SignedBeaco
}

if err = s.validateBellatrixBeaconBlock(ctx, parentState, blk.Block()); err != nil {
if errors.Is(err, ErrOptimisticParent) {
return err
}
// for other kinds of errors, set this block as a bad block.
s.setBadBlock(ctx, blockRoot)
return err
}
Expand Down Expand Up @@ -282,14 +270,6 @@ func (s *Service) validateBellatrixBeaconBlock(ctx context.Context, parentState
return errors.New("incorrect timestamp")
}

parentRoot := bytesutil.ToBytes32(blk.ParentRoot())
isParentOptimistic, err := s.cfg.chain.IsOptimisticForRoot(ctx, parentRoot)
if err != nil {
return err
}
if isParentOptimistic {
return ErrOptimisticParent
}
return nil
}

Expand Down

0 comments on commit 0b5bdcb

Please sign in to comment.