Don't mark block as bad in validateBeaconBlock for pending queue (#12983)

* Don't mark block as bad in validateBeaconBlock for pending queue

* Fix tests
This commit is contained in:
terencechain 2023-10-03 09:36:23 -07:00 committed by GitHub
parent 4628c19f51
commit 58c0899676
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -159,7 +159,6 @@ func (s *Service) processPendingBlocks(ctx context.Context) error {
case errors.Is(ErrOptimisticParent, err): // Ok to continue process block with parent that is an optimistic candidate. case errors.Is(ErrOptimisticParent, err): // Ok to continue process block with parent that is an optimistic candidate.
case err != nil: case err != nil:
log.WithError(err).WithField("slot", b.Block().Slot()).Debug("Could not validate block") log.WithError(err).WithField("slot", b.Block().Slot()).Debug("Could not validate block")
s.setBadBlock(ctx, blkRoot)
tracing.AnnotateError(span, err) tracing.AnnotateError(span, err)
span.End() span.End()
continue continue

View File

@ -108,7 +108,7 @@ func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks1(t *testing.T) {
require.NoError(t, r.processPendingBlocks(context.Background())) // Marks a block as bad require.NoError(t, r.processPendingBlocks(context.Background())) // Marks a block as bad
require.NoError(t, r.processPendingBlocks(context.Background())) // Bad block removed on second run require.NoError(t, r.processPendingBlocks(context.Background())) // Bad block removed on second run
assert.Equal(t, 1, len(r.slotToPendingBlocks.Items()), "Incorrect size for slot to pending blocks cache") assert.Equal(t, 2, len(r.slotToPendingBlocks.Items()), "Incorrect size for slot to pending blocks cache")
assert.Equal(t, 2, len(r.seenPendingBlocks), "Incorrect size for seen pending block") assert.Equal(t, 2, len(r.seenPendingBlocks), "Incorrect size for seen pending block")
} }
@ -181,7 +181,7 @@ func TestRegularSyncBeaconBlockSubscriber_OptimisticStatus(t *testing.T) {
require.NoError(t, r.processPendingBlocks(context.Background())) // Marks a block as bad require.NoError(t, r.processPendingBlocks(context.Background())) // Marks a block as bad
require.NoError(t, r.processPendingBlocks(context.Background())) // Bad block removed on second run require.NoError(t, r.processPendingBlocks(context.Background())) // Bad block removed on second run
assert.Equal(t, 1, len(r.slotToPendingBlocks.Items()), "Incorrect size for slot to pending blocks cache") assert.Equal(t, 2, len(r.slotToPendingBlocks.Items()), "Incorrect size for slot to pending blocks cache")
assert.Equal(t, 2, len(r.seenPendingBlocks), "Incorrect size for seen pending block") assert.Equal(t, 2, len(r.seenPendingBlocks), "Incorrect size for seen pending block")
} }
@ -255,9 +255,9 @@ func TestRegularSyncBeaconBlockSubscriber_ExecutionEngineTimesOut(t *testing.T)
require.NoError(t, r.processPendingBlocks(context.Background())) // Marks a block as bad require.NoError(t, r.processPendingBlocks(context.Background())) // Marks a block as bad
require.NoError(t, r.processPendingBlocks(context.Background())) // Bad block removed on second run require.NoError(t, r.processPendingBlocks(context.Background())) // Bad block removed on second run
assert.Equal(t, 1, len(r.slotToPendingBlocks.Items()), "Incorrect size for slot to pending blocks cache") assert.Equal(t, 2, len(r.slotToPendingBlocks.Items()), "Incorrect size for slot to pending blocks cache")
assert.Equal(t, 2, len(r.seenPendingBlocks), "Incorrect size for seen pending block") assert.Equal(t, 2, len(r.seenPendingBlocks), "Incorrect size for seen pending block")
require.Equal(t, 1, len(r.badBlockCache.Keys())) // Account for the bad block above require.Equal(t, 0, len(r.badBlockCache.Keys())) // Account for the bad block above
require.Equal(t, 0, len(r.seenBlockCache.Keys())) require.Equal(t, 0, len(r.seenBlockCache.Keys()))
} }
@ -464,8 +464,8 @@ func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks_2Chains(t *testin
require.NoError(t, r.processPendingBlocks(context.Background())) // Marks a block as bad require.NoError(t, r.processPendingBlocks(context.Background())) // Marks a block as bad
require.NoError(t, r.processPendingBlocks(context.Background())) // Bad block removed on second run require.NoError(t, r.processPendingBlocks(context.Background())) // Bad block removed on second run
assert.Equal(t, 1, len(r.slotToPendingBlocks.Items()), "Incorrect size for slot to pending blocks cache") assert.Equal(t, 2, len(r.slotToPendingBlocks.Items()), "Incorrect size for slot to pending blocks cache")
assert.Equal(t, 1, len(r.seenPendingBlocks), "Incorrect size for seen pending block") assert.Equal(t, 2, len(r.seenPendingBlocks), "Incorrect size for seen pending block")
// Add b2 to the cache // Add b2 to the cache
wsb, err = blocks.NewSignedBeaconBlock(b2) wsb, err = blocks.NewSignedBeaconBlock(b2)
@ -477,8 +477,8 @@ func TestRegularSyncBeaconBlockSubscriber_ProcessPendingBlocks_2Chains(t *testin
require.NoError(t, r.processPendingBlocks(context.Background())) // Marks a block as bad require.NoError(t, r.processPendingBlocks(context.Background())) // Marks a block as bad
require.NoError(t, r.processPendingBlocks(context.Background())) // Bad block removed on second run require.NoError(t, r.processPendingBlocks(context.Background())) // Bad block removed on second run
assert.Equal(t, 0, len(r.slotToPendingBlocks.Items()), "Incorrect size for slot to pending blocks cache") assert.Equal(t, 2, len(r.slotToPendingBlocks.Items()), "Incorrect size for slot to pending blocks cache")
assert.Equal(t, 0, len(r.seenPendingBlocks), "Incorrect size for seen pending block") assert.Equal(t, 2, len(r.seenPendingBlocks), "Incorrect size for seen pending block")
} }
func TestRegularSyncBeaconBlockSubscriber_PruneOldPendingBlocks(t *testing.T) { func TestRegularSyncBeaconBlockSubscriber_PruneOldPendingBlocks(t *testing.T) {

View File

@ -229,6 +229,7 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk interfaces.ReadOn
defer span.End() defer span.End()
if err := validateDenebBeaconBlock(blk.Block()); err != nil { if err := validateDenebBeaconBlock(blk.Block()); err != nil {
s.setBadBlock(ctx, blockRoot)
return err return err
} }