Skip to content

Commit de6d597

Browse files
dknopiklightclient
andauthored
p2p/discover: schedule revalidation also when all nodes are excluded (#30239)
## Issue If `nextTime` has passed, but all nodes are excluded, `get` would return `nil` and `run` would therefore not invoke `schedule`. Then, we schedule a timer for the past, as neither `nextTime` value has been updated. This creates a busy loop, as the timer immediately returns. ## Fix With this PR, revalidation will be also rescheduled when all nodes are excluded. --------- Co-authored-by: lightclient <[email protected]>
1 parent 6e33dbf commit de6d597

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

p2p/discover/table_reval.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,18 @@ func (tr *tableRevalidation) nodeEndpointChanged(tab *Table, n *tableNode) {
7777
// It returns the next time it should be invoked, which is used in the Table main loop
7878
// to schedule a timer. However, run can be called at any time.
7979
func (tr *tableRevalidation) run(tab *Table, now mclock.AbsTime) (nextTime mclock.AbsTime) {
80-
if n := tr.fast.get(now, &tab.rand, tr.activeReq); n != nil {
81-
tr.startRequest(tab, n)
82-
tr.fast.schedule(now, &tab.rand)
83-
}
84-
if n := tr.slow.get(now, &tab.rand, tr.activeReq); n != nil {
85-
tr.startRequest(tab, n)
86-
tr.slow.schedule(now, &tab.rand)
80+
reval := func(list *revalidationList) {
81+
if list.nextTime <= now {
82+
if n := list.get(now, &tab.rand, tr.activeReq); n != nil {
83+
tr.startRequest(tab, n)
84+
}
85+
// Update nextTime regardless if any requests were started because
86+
// current value has passed.
87+
list.schedule(now, &tab.rand)
88+
}
8789
}
90+
reval(&tr.fast)
91+
reval(&tr.slow)
8892

8993
return min(tr.fast.nextTime, tr.slow.nextTime)
9094
}
@@ -200,7 +204,7 @@ type revalidationList struct {
200204

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

0 commit comments

Comments
 (0)