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

p2p/discover: schedule revalidation also when all nodes are excluded #30239

Merged
merged 2 commits into from
Jul 31, 2024
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
20 changes: 12 additions & 8 deletions p2p/discover/table_reval.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,18 @@ func (tr *tableRevalidation) nodeEndpointChanged(tab *Table, n *tableNode) {
// It returns the next time it should be invoked, which is used in the Table main loop
// to schedule a timer. However, run can be called at any time.
func (tr *tableRevalidation) run(tab *Table, now mclock.AbsTime) (nextTime mclock.AbsTime) {
if n := tr.fast.get(now, &tab.rand, tr.activeReq); n != nil {
tr.startRequest(tab, n)
tr.fast.schedule(now, &tab.rand)
}
if n := tr.slow.get(now, &tab.rand, tr.activeReq); n != nil {
tr.startRequest(tab, n)
tr.slow.schedule(now, &tab.rand)
reval := func(list *revalidationList) {
if list.nextTime <= now {
if n := list.get(now, &tab.rand, tr.activeReq); n != nil {
tr.startRequest(tab, n)
}
// Update nextTime regardless if any requests were started because
// current value has passed.
list.schedule(now, &tab.rand)
}
}
reval(&tr.fast)
reval(&tr.slow)

return min(tr.fast.nextTime, tr.slow.nextTime)
}
Expand Down Expand Up @@ -200,7 +204,7 @@ type revalidationList struct {

// get returns a random node from the queue. Nodes in the 'exclude' map are not returned.
func (list *revalidationList) get(now mclock.AbsTime, rand randomSource, exclude map[enode.ID]struct{}) *tableNode {
if now < list.nextTime || len(list.nodes) == 0 {
if len(list.nodes) == 0 {
return nil
}
for i := 0; i < len(list.nodes)*3; i++ {
Expand Down