fix(disc): schedule revalidation also when all nodes are excluded

This commit is contained in:
Daniel Knopik 2024-07-29 16:23:16 +02:00
parent b0f66e34ca
commit 7508f4d5d2
No known key found for this signature in database
GPG key ID: C56F35A74383E739

View file

@ -77,13 +77,11 @@ 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 { if n := tr.fast.getAndSchedule(now, &tab.rand, tr.activeReq); n != nil {
tr.startRequest(tab, n) tr.startRequest(tab, n)
tr.fast.schedule(now, &tab.rand)
} }
if n := tr.slow.get(now, &tab.rand, tr.activeReq); n != nil { if n := tr.slow.getAndSchedule(now, &tab.rand, tr.activeReq); n != nil {
tr.startRequest(tab, n) tr.startRequest(tab, n)
tr.slow.schedule(now, &tab.rand)
} }
return min(tr.fast.nextTime, tr.slow.nextTime) return min(tr.fast.nextTime, tr.slow.nextTime)
@ -198,9 +196,14 @@ type revalidationList struct {
name string name string
} }
// get returns a random node from the queue. Nodes in the 'exclude' map are not returned. // getAndSchedule 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 { // It also schedules the next invocation if nextTime has already passed.
if now < list.nextTime || len(list.nodes) == 0 { func (list *revalidationList) getAndSchedule(now mclock.AbsTime, rand randomSource, exclude map[enode.ID]struct{}) *tableNode {
if now < list.nextTime {
return nil
}
list.schedule(now, rand)
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++ {