Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in oversubscription pruning D_out constraint #344

Merged
merged 1 commit into from
May 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -1302,15 +1302,33 @@ func (gs *GossipSubRouter) heartbeat() {

// if it's less than D_out, bubble up some outbound peers from the random selection
if outbound < gs.Dout {
rotate := func(i int) {
// rotate the plst to the right and put the ith peer in the front
p := plst[i]
for j := i; j > 0; j-- {
plst[j] = plst[j-1]
}
plst[0] = p
}

// first bubble up all outbound peers already in the selection to the front
if outbound > 0 {
ihave := outbound
for i := 1; i < gs.D && ihave > 0; i++ {
p := plst[i]
if gs.outbound[p] {
rotate(i)
ihave--
}
}
}

// now bubble up enough outbound peers outside the selection to the front
ineed := gs.Dout - outbound
for i := gs.D; i < len(plst) && ineed > 0; i++ {
p := plst[i]
if gs.outbound[p] {
// rotate the plst to the right and put the outbound peer in the front
for j := i; j > 0; j-- {
plst[j] = plst[j-1]
}
plst[0] = p
rotate(i)
ineed--
}
}
Expand Down