mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
handle large ranges of skipped slots (#3602)
This commit is contained in:
committed by
Raul Jordan
parent
2690c2080d
commit
32ffb70a1a
@@ -38,6 +38,7 @@ func (s *InitialSync) roundRobinSync(genesis time.Time) error {
|
||||
|
||||
counter := ratecounter.NewRateCounter(counterSeconds * time.Second)
|
||||
|
||||
var lastEmptyRequests int
|
||||
// Step 1 - Sync to end of finalized epoch.
|
||||
for s.chain.HeadSlot() < helpers.StartSlot(highestFinalizedEpoch()+1) {
|
||||
root, finalizedEpoch, peers := bestFinalized()
|
||||
@@ -57,6 +58,9 @@ func (s *InitialSync) roundRobinSync(genesis time.Time) error {
|
||||
return nil, errors.WithStack(errors.New("no peers left to request blocks"))
|
||||
}
|
||||
|
||||
// Handle block large block ranges of skipped slots.
|
||||
start += count * uint64(lastEmptyRequests*len(peers))
|
||||
|
||||
for i, pid := range peers {
|
||||
start := start + uint64(i)*step
|
||||
step := step * uint64(len(peers))
|
||||
@@ -134,6 +138,13 @@ func (s *InitialSync) roundRobinSync(genesis time.Time) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
// If there were no blocks in the last request range, increment the counter so the same
|
||||
// range isn't requested again on the next loop as the headSlot didn't change.
|
||||
if len(blocks) == 0 {
|
||||
lastEmptyRequests++
|
||||
} else {
|
||||
lastEmptyRequests = 0
|
||||
}
|
||||
}
|
||||
|
||||
log.Debug("Synced to finalized epoch. Syncing blocks to head slot now.")
|
||||
|
||||
@@ -105,6 +105,29 @@ func TestRoundRobinSync(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Multiple peers with many skipped slots",
|
||||
currentSlot: 640, // 10 epochs
|
||||
expectedBlockSlots: append(makeSequence(1, 64), makeSequence(500, 640)...),
|
||||
peers: []*peerData{
|
||||
{
|
||||
blocks: append(makeSequence(1, 64), makeSequence(500, 640)...),
|
||||
finalizedEpoch: 9,
|
||||
headSlot: 640,
|
||||
},
|
||||
{
|
||||
blocks: append(makeSequence(1, 64), makeSequence(500, 640)...),
|
||||
finalizedEpoch: 9,
|
||||
headSlot: 640,
|
||||
},
|
||||
{
|
||||
blocks: append(makeSequence(1, 64), makeSequence(500, 640)...),
|
||||
finalizedEpoch: 9,
|
||||
headSlot: 640,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// TODO(3147): Handle multiple failures.
|
||||
//{
|
||||
// name: "Multiple peers with multiple failures",
|
||||
@@ -237,16 +260,6 @@ func connectPeers(t *testing.T, host *p2pt.TestP2P, data []*peerData) {
|
||||
// Determine the correct subset of blocks to return as dictated by the test scenario.
|
||||
blocks := sliceutil.IntersectionUint64(datum.blocks, requestedBlocks)
|
||||
|
||||
if len(blocks) == 0 {
|
||||
if _, err := stream.Write([]byte{0x01}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, err := peer.Encoding().EncodeWithLength(stream, "i don't have those blocks"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
ret := make([]*eth.BeaconBlock, 0)
|
||||
for _, slot := range blocks {
|
||||
if (slot-req.StartSlot)%req.Step != 0 {
|
||||
|
||||
Reference in New Issue
Block a user