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 <lightclient@protonmail.com>
This commit is contained in:
parent
6e33dbf96a
commit
de6d597679
@ -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
|
// 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.
|
// to schedule a timer. However, run can be called at any time.
|
||||||
func (tr *tableRevalidation) run(tab *Table, now mclock.AbsTime) (nextTime mclock.AbsTime) {
|
func (tr *tableRevalidation) run(tab *Table, now mclock.AbsTime) (nextTime mclock.AbsTime) {
|
||||||
if n := tr.fast.get(now, &tab.rand, tr.activeReq); n != nil {
|
reval := func(list *revalidationList) {
|
||||||
tr.startRequest(tab, n)
|
if list.nextTime <= now {
|
||||||
tr.fast.schedule(now, &tab.rand)
|
if n := list.get(now, &tab.rand, tr.activeReq); n != nil {
|
||||||
}
|
tr.startRequest(tab, n)
|
||||||
if n := tr.slow.get(now, &tab.rand, tr.activeReq); n != nil {
|
}
|
||||||
tr.startRequest(tab, n)
|
// Update nextTime regardless if any requests were started because
|
||||||
tr.slow.schedule(now, &tab.rand)
|
// current value has passed.
|
||||||
|
list.schedule(now, &tab.rand)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
reval(&tr.fast)
|
||||||
|
reval(&tr.slow)
|
||||||
|
|
||||||
return min(tr.fast.nextTime, tr.slow.nextTime)
|
return min(tr.fast.nextTime, tr.slow.nextTime)
|
||||||
}
|
}
|
||||||
@ -200,7 +204,7 @@ type revalidationList struct {
|
|||||||
|
|
||||||
// get returns a random node from the queue. Nodes in the 'exclude' map are not returned.
|
// 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 {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
for i := 0; i < len(list.nodes)*3; i++ {
|
for i := 0; i < len(list.nodes)*3; i++ {
|
||||||
|
Loading…
Reference in New Issue
Block a user