Skip to content

Commit

Permalink
Fix Round Robin Test (#3775)
Browse files Browse the repository at this point in the history
* fix round robin test

* add comment
  • Loading branch information
nisdas authored Oct 15, 2019
1 parent 0d1aeee commit 00a5a25
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
11 changes: 10 additions & 1 deletion beacon-chain/sync/initial-sync/round_robin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,18 @@ func (s *InitialSync) roundRobinSync(genesis time.Time) error {
if ctx.Err() != nil {
return nil, ctx.Err()
}

originalStart := start
originalCount := count
start := start + uint64(i)*step
step := step * uint64(len(peers))
count := mathutil.Min(count, (helpers.StartSlot(finalizedEpoch+1)-start)/step)
count := mathutil.Min(count, (helpers.StartSlot(finalizedEpoch+1)-originalStart)/step)
// If there is only 1 peer left, rather than further minimising the count in the situation
// of a large step value. we remove the variable entirely. This also handles the case if
// there is only 1 peer overall(step = 1).
if len(peers) == 1 {
count = mathutil.Min(originalCount, helpers.StartSlot(finalizedEpoch+1)-originalStart)
}
// If the count was divided by an odd number of peers, there will be some blocks
// missing from the first requests so we accommodate that scenario.
if i < remainder {
Expand Down
61 changes: 30 additions & 31 deletions beacon-chain/sync/initial-sync/round_robin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,37 +128,36 @@ func TestRoundRobinSync(t *testing.T) {
},
},

// TODO(3147): Handle multiple failures.
//{
// name: "Multiple peers with multiple failures",
// currentSlot: 320, // 5 epochs
// expectedBlockSlots: makeSequence(1, 320),
// peers: []*peerData{
// {
// blocks: makeSequence(1, 320),
// finalizedEpoch: 4,
// headSlot: 320,
// },
// {
// blocks: makeSequence(1, 320),
// finalizedEpoch: 4,
// headSlot: 320,
// failureSlots: makeSequence(1, 320),
// },
// {
// blocks: makeSequence(1, 320),
// finalizedEpoch: 4,
// headSlot: 320,
// failureSlots: makeSequence(1, 320),
// },
// {
// blocks: makeSequence(1, 320),
// finalizedEpoch: 4,
// headSlot: 320,
// failureSlots: makeSequence(1, 320),
// },
// },
//},
{
name: "Multiple peers with multiple failures",
currentSlot: 320, // 5 epochs
expectedBlockSlots: makeSequence(1, 320),
peers: []*peerData{
{
blocks: makeSequence(1, 320),
finalizedEpoch: 4,
headSlot: 320,
},
{
blocks: makeSequence(1, 320),
finalizedEpoch: 4,
headSlot: 320,
failureSlots: makeSequence(1, 320),
},
{
blocks: makeSequence(1, 320),
finalizedEpoch: 4,
headSlot: 320,
failureSlots: makeSequence(1, 320),
},
{
blocks: makeSequence(1, 320),
finalizedEpoch: 4,
headSlot: 320,
failureSlots: makeSequence(1, 320),
},
},
},
{
name: "Multiple peers with different finalized epoch",
currentSlot: 320, // 5 epochs
Expand Down

0 comments on commit 00a5a25

Please sign in to comment.