Fix Initial Sync PreProcessing (#13007)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Nishant Das
2023-10-05 23:18:53 +08:00
committed by GitHub
parent 734eb98941
commit c1c0cd040c
2 changed files with 39 additions and 2 deletions

View File

@@ -276,7 +276,8 @@ func validUnprocessed(ctx context.Context, bwb []blocks.BlockWithVerifiedBlobs,
for i := range bwb {
b := bwb[i].Block
if headSlot >= b.Block().Slot() && isProc(ctx, b) {
processed = &i
val := i
processed = &val
continue
}
if i > 0 {
@@ -295,7 +296,8 @@ func validUnprocessed(ctx context.Context, bwb []blocks.BlockWithVerifiedBlobs,
maxRoot := maxIncoming.Root()
return nil, fmt.Errorf("headSlot:%d, blockSlot:%d , root %#x:%w", headSlot, maxIncoming.Block().Slot(), maxRoot, errBlockAlreadyProcessed)
}
return bwb[*processed:], nil
nonProcessedIdx := *processed + 1
return bwb[nonProcessedIdx:], nil
}
func (s *Service) processBatchedBlocks(ctx context.Context, genesis time.Time,

View File

@@ -667,3 +667,38 @@ func TestService_syncToFinalizedEpoch(t *testing.T) {
assert.NoError(t, s.syncToFinalizedEpoch(context.Background(), genesis))
assert.LogsContain(t, hook, "Already synced to finalized epoch")
}
func TestService_ValidUnprocessed(t *testing.T) {
beaconDB := dbtest.SetupDB(t)
genesisBlk := util.NewBeaconBlock()
genesisBlkRoot, err := genesisBlk.Block.HashTreeRoot()
require.NoError(t, err)
util.SaveBlock(t, context.Background(), beaconDB, genesisBlk)
var batch []blocks.BlockWithVerifiedBlobs
currBlockRoot := genesisBlkRoot
for i := primitives.Slot(1); i < 10; i++ {
parentRoot := currBlockRoot
blk1 := util.NewBeaconBlock()
blk1.Block.Slot = i
blk1.Block.ParentRoot = parentRoot[:]
blk1Root, err := blk1.Block.HashTreeRoot()
require.NoError(t, err)
util.SaveBlock(t, context.Background(), beaconDB, blk1)
wsb, err := blocks.NewSignedBeaconBlock(blk1)
require.NoError(t, err)
rowsb, err := blocks.NewROBlock(wsb)
require.NoError(t, err)
batch = append(batch, blocks.BlockWithVerifiedBlobs{Block: rowsb})
currBlockRoot = blk1Root
}
retBlocks, err := validUnprocessed(context.Background(), batch, 2, func(ctx context.Context, block blocks.ROBlock) bool {
// Ignore first 2 blocks in the batch.
return block.Block().Slot() <= 2
})
require.NoError(t, err)
// Ensure that the unprocessed batch is returned correctly.
assert.Equal(t, len(retBlocks), len(batch)-2)
}