mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 23:48:06 -05:00
Penalize peers for bad rpc data in range sync (#15149)
* Penalize peers for bad rpc data in range sync * gofmt --------- Co-authored-by: Kasey <kasey@users.noreply.github.com>
This commit is contained in:
@@ -314,7 +314,8 @@ func TestService_roundRobinSync(t *testing.T) {
|
||||
chainStarted: abool.NewBool(true),
|
||||
clock: clock,
|
||||
}
|
||||
assert.NoError(t, s.roundRobinSync(makeGenesisTime(tt.currentSlot)))
|
||||
s.genesisTime = makeGenesisTime(tt.currentSlot)
|
||||
assert.NoError(t, s.roundRobinSync())
|
||||
if s.cfg.Chain.HeadSlot() < tt.currentSlot {
|
||||
t.Errorf("Head slot (%d) is less than expected currentSlot (%d)", s.cfg.Chain.HeadSlot(), tt.currentSlot)
|
||||
}
|
||||
@@ -428,6 +429,7 @@ func TestService_processBlockBatch(t *testing.T) {
|
||||
})
|
||||
ctx := context.Background()
|
||||
genesis := makeGenesisTime(32)
|
||||
s.genesisTime = genesis
|
||||
|
||||
t.Run("process non-linear batch", func(t *testing.T) {
|
||||
var batch []blocks.BlockWithROBlobs
|
||||
@@ -470,16 +472,18 @@ func TestService_processBlockBatch(t *testing.T) {
|
||||
return nil
|
||||
}
|
||||
// Process block normally.
|
||||
err = s.processBatchedBlocks(ctx, genesis, batch, cbnormal)
|
||||
count, err := s.processBatchedBlocks(ctx, batch, cbnormal)
|
||||
assert.NoError(t, err)
|
||||
require.Equal(t, uint64(len(batch)), count)
|
||||
|
||||
cbnil := func(ctx context.Context, blocks []blocks.ROBlock, _ das.AvailabilityStore) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Duplicate processing should trigger error.
|
||||
err = s.processBatchedBlocks(ctx, genesis, batch, cbnil)
|
||||
count, err = s.processBatchedBlocks(ctx, batch, cbnil)
|
||||
assert.ErrorContains(t, "block is already processed", err)
|
||||
require.Equal(t, uint64(0), count)
|
||||
|
||||
var badBatch2 []blocks.BlockWithROBlobs
|
||||
for i, b := range batch2 {
|
||||
@@ -491,14 +495,16 @@ func TestService_processBlockBatch(t *testing.T) {
|
||||
}
|
||||
|
||||
// Bad batch should fail because it is non linear
|
||||
err = s.processBatchedBlocks(ctx, genesis, badBatch2, cbnil)
|
||||
count, err = s.processBatchedBlocks(ctx, badBatch2, cbnil)
|
||||
expectedSubErr := "expected linear block list"
|
||||
assert.ErrorContains(t, expectedSubErr, err)
|
||||
require.Equal(t, uint64(0), count)
|
||||
|
||||
// Continue normal processing, should proceed w/o errors.
|
||||
err = s.processBatchedBlocks(ctx, genesis, batch2, cbnormal)
|
||||
count, err = s.processBatchedBlocks(ctx, batch2, cbnormal)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, primitives.Slot(19), s.cfg.Chain.HeadSlot(), "Unexpected head slot")
|
||||
require.Equal(t, uint64(len(batch2)), count)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -576,7 +582,8 @@ func TestService_blockProviderScoring(t *testing.T) {
|
||||
assert.Equal(t, scorer.MaxScore(), scorer.Score(peer2))
|
||||
assert.Equal(t, scorer.MaxScore(), scorer.Score(peer3))
|
||||
|
||||
assert.NoError(t, s.roundRobinSync(makeGenesisTime(currentSlot)))
|
||||
s.genesisTime = makeGenesisTime(currentSlot)
|
||||
assert.NoError(t, s.roundRobinSync())
|
||||
if s.cfg.Chain.HeadSlot() < currentSlot {
|
||||
t.Errorf("Head slot (%d) is less than expected currentSlot (%d)", s.cfg.Chain.HeadSlot(), currentSlot)
|
||||
}
|
||||
@@ -648,7 +655,8 @@ func TestService_syncToFinalizedEpoch(t *testing.T) {
|
||||
headSlot: 195,
|
||||
}, p.Peers())
|
||||
genesis := makeGenesisTime(currentSlot)
|
||||
assert.NoError(t, s.syncToFinalizedEpoch(context.Background(), genesis))
|
||||
s.genesisTime = genesis
|
||||
assert.NoError(t, s.syncToFinalizedEpoch(context.Background()))
|
||||
if s.cfg.Chain.HeadSlot() < currentSlot {
|
||||
t.Errorf("Head slot (%d) is less than expected currentSlot (%d)", s.cfg.Chain.HeadSlot(), currentSlot)
|
||||
}
|
||||
@@ -665,7 +673,8 @@ func TestService_syncToFinalizedEpoch(t *testing.T) {
|
||||
|
||||
// Try to re-sync, should be exited immediately (node is already synced to finalized epoch).
|
||||
hook.Reset()
|
||||
assert.NoError(t, s.syncToFinalizedEpoch(context.Background(), genesis))
|
||||
s.genesisTime = genesis
|
||||
assert.NoError(t, s.syncToFinalizedEpoch(context.Background()))
|
||||
assert.LogsContain(t, hook, "Already synced to finalized epoch")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user