mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
Sort list before processing batched blocks (#2531)
This commit is contained in:
parent
76881fd1ae
commit
e5cb1db5bc
@ -128,6 +128,9 @@ func TestProcessingBatchedBlocks_OK(t *testing.T) {
|
||||
Slot: params.BeaconConfig().GenesisSlot + uint64(i),
|
||||
}
|
||||
}
|
||||
// edge case: handle out of order block list. Specifically with the highest
|
||||
// block first. This is swapping the first and last blocks in the list.
|
||||
batchedBlocks[0], batchedBlocks[batchSize-1] = batchedBlocks[batchSize-1], batchedBlocks[0]
|
||||
|
||||
msg := p2p.Message{
|
||||
Ctx: context.Background(),
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
@ -67,6 +68,10 @@ func (s *InitialSync) processBatchedBlocks(msg p2p.Message) {
|
||||
}
|
||||
|
||||
log.Debug("Processing batched block response")
|
||||
// Sort batchBlocks in ascending order.
|
||||
sort.Slice(batchedBlocks, func(i, j int) bool {
|
||||
return batchedBlocks[i].Slot < batchedBlocks[j].Slot
|
||||
})
|
||||
for _, block := range batchedBlocks {
|
||||
s.processBlock(ctx, block)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user