mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-31 15:31:20 +00:00
Fixes overflow issue in sync/pending_blocks_queue (#6039)
* fixes overflow issue * Merge refs/heads/master into fix-overflow * Merge refs/heads/master into fix-overflow
This commit is contained in:
parent
a0bf8cba52
commit
0243bdcf37
@ -55,7 +55,7 @@ func (r *Service) processPendingBlocks(ctx context.Context) error {
|
||||
span.AddAttributes(trace.Int64Attribute("slot", int64(s)))
|
||||
|
||||
r.pendingQueueLock.RLock()
|
||||
b := r.slotToPendingBlocks[uint64(s)]
|
||||
b := r.slotToPendingBlocks[s]
|
||||
// Skip if block does not exist.
|
||||
if b == nil || b.Block == nil {
|
||||
r.pendingQueueLock.RUnlock()
|
||||
@ -85,7 +85,7 @@ func (r *Service) processPendingBlocks(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read chain state for peer")
|
||||
}
|
||||
if cs != nil && cs.HeadSlot >= uint64(s) {
|
||||
if cs != nil && cs.HeadSlot >= s {
|
||||
pid = p
|
||||
break
|
||||
}
|
||||
@ -122,7 +122,7 @@ func (r *Service) processPendingBlocks(ctx context.Context) error {
|
||||
}
|
||||
|
||||
r.pendingQueueLock.Lock()
|
||||
delete(r.slotToPendingBlocks, uint64(s))
|
||||
delete(r.slotToPendingBlocks, s)
|
||||
delete(r.seenPendingBlocks, blkRoot)
|
||||
r.pendingQueueLock.Unlock()
|
||||
|
||||
@ -137,15 +137,17 @@ func (r *Service) processPendingBlocks(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Service) sortedPendingSlots() []int {
|
||||
func (r *Service) sortedPendingSlots() []uint64 {
|
||||
r.pendingQueueLock.RLock()
|
||||
defer r.pendingQueueLock.RUnlock()
|
||||
|
||||
slots := make([]int, 0, len(r.slotToPendingBlocks))
|
||||
slots := make([]uint64, 0, len(r.slotToPendingBlocks))
|
||||
for s := range r.slotToPendingBlocks {
|
||||
slots = append(slots, int(s))
|
||||
slots = append(slots, s)
|
||||
}
|
||||
sort.Ints(slots)
|
||||
sort.Slice(slots, func(i, j int) bool {
|
||||
return slots[i] < slots[j]
|
||||
})
|
||||
return slots
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@ package sync
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
@ -309,3 +311,21 @@ func TestRegularSyncBeaconBlockSubscriber_PruneOldPendingBlocks(t *testing.T) {
|
||||
t.Errorf("Incorrect size for seen pending block: got %d", len(r.seenPendingBlocks))
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_sortedPendingSlots(t *testing.T) {
|
||||
r := &Service{
|
||||
slotToPendingBlocks: make(map[uint64]*ethpb.SignedBeaconBlock),
|
||||
}
|
||||
|
||||
var lastSlot uint64 = math.MaxUint64
|
||||
r.slotToPendingBlocks[lastSlot] = ðpb.SignedBeaconBlock{}
|
||||
r.slotToPendingBlocks[lastSlot-3] = ðpb.SignedBeaconBlock{}
|
||||
r.slotToPendingBlocks[lastSlot-5] = ðpb.SignedBeaconBlock{}
|
||||
r.slotToPendingBlocks[lastSlot-2] = ðpb.SignedBeaconBlock{}
|
||||
|
||||
want := []uint64{lastSlot - 5, lastSlot - 3, lastSlot - 2, lastSlot}
|
||||
got := r.sortedPendingSlots()
|
||||
if !reflect.DeepEqual(want, got) {
|
||||
t.Errorf("unexpected pending slots list, want: %v, got: %v", want, got)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user