Skip to content

Commit

Permalink
p2p/simulations: fix unlikely crash in probabilistic connect (ethereu…
Browse files Browse the repository at this point in the history
…m#23200)

When the nodeCount is less than 10, it will panic with the out of bound error.
How about we just skip this round, when rand1 and rand2 are equal?
  • Loading branch information
Evolution404 authored and atif-konasl committed Oct 15, 2021
1 parent 1c29f33 commit e64ac58
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions p2p/simulations/mocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,12 @@ func probabilistic(net *Network, quit chan struct{}, nodeCount int) {
randWait := time.Duration(rand.Intn(5000)+1000) * time.Millisecond
rand1 := rand.Intn(nodeCount - 1)
rand2 := rand.Intn(nodeCount - 1)
if rand1 < rand2 {
if rand1 <= rand2 {
lowid = rand1
highid = rand2
} else if rand1 > rand2 {
highid = rand1
lowid = rand2
} else {
if rand1 == 0 {
rand2 = 9
} else if rand1 == 9 {
rand1 = 0
}
lowid = rand1
highid = rand2
}
var steps = highid - lowid
wg.Add(steps)
Expand Down

0 comments on commit e64ac58

Please sign in to comment.