Skip to content

Commit 65689e7

Browse files
authored
les/vflux/server: fix priority cornercase causing fuzzer timeout (#22650)
* les/vflux/server: fix estimatePriority corner case * les/vflux/server: simplify inactiveAllowance == 0 case
1 parent f8afb68 commit 65689e7

4 files changed

Lines changed: 19 additions & 17 deletions

File tree

‎les/vflux/server/balance.go‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,15 @@ func (n *nodeBalance) estimatePriority(capacity uint64, addBalance int64, future
358358
if bias > 0 {
359359
b = n.reducedBalance(b, now+mclock.AbsTime(future), bias, capacity, 0)
360360
}
361-
// Note: we subtract one from the estimated priority in order to ensure that biased
362-
// estimates are always lower than actual priorities, even if the bias is very small.
361+
pri := n.balanceToPriority(now, b, capacity)
362+
// Ensure that biased estimates are always lower than actual priorities, even if
363+
// the bias is very small.
363364
// This ensures that two nodes will not ping-pong update signals forever if both of
364365
// them have zero estimated priority drop in the projected future.
365-
pri := n.balanceToPriority(now, b, capacity) - 1
366+
current := n.balanceToPriority(now, n.balance, capacity)
367+
if pri >= current {
368+
pri = current - 1
369+
}
366370
if update {
367371
n.addCallback(balanceCallbackUpdate, pri, n.signalPriorityUpdate)
368372
}

‎les/vflux/server/balance_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func TestEstimatedPriority(t *testing.T) {
283283
{time.Second, 3 * time.Second, 1000000000, 48},
284284

285285
// All positive balance is used up
286-
{time.Second * 55, 0, 0, 0},
286+
{time.Second * 55, 0, 0, -1},
287287

288288
// 1 minute estimated time cost, 4/58 * 10^9 estimated request cost per sec.
289289
{0, time.Minute, 0, -int64(time.Minute) - int64(time.Second)*120/29},
@@ -292,8 +292,8 @@ func TestEstimatedPriority(t *testing.T) {
292292
b.clock.Run(i.runTime)
293293
node.RequestServed(i.reqCost)
294294
priority := node.estimatePriority(1000000000, 0, i.futureTime, 0, false)
295-
if priority != i.priority-1 {
296-
t.Fatalf("Estimated priority mismatch, want %v, got %v", i.priority-1, priority)
295+
if priority != i.priority {
296+
t.Fatalf("Estimated priority mismatch, want %v, got %v", i.priority, priority)
297297
}
298298
}
299299
}

‎les/vflux/server/clientpool.go‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,7 @@ func NewClientPool(balanceDb ethdb.KeyValueStore, minCap uint64, connectedBias t
103103
if c, ok := ns.GetField(node, setup.clientField).(clientPeer); ok {
104104
timeout = c.InactiveAllowance()
105105
}
106-
if timeout > 0 {
107-
ns.AddTimeout(node, setup.inactiveFlag, timeout)
108-
} else {
109-
// Note: if capacity is immediately available then priorityPool will set the active
110-
// flag simultaneously with removing the inactive flag and therefore this will not
111-
// initiate disconnection
112-
ns.SetStateSub(node, nodestate.Flags{}, setup.inactiveFlag, 0)
113-
}
106+
ns.AddTimeout(node, setup.inactiveFlag, timeout)
114107
}
115108
if oldState.Equals(setup.inactiveFlag) && newState.Equals(setup.inactiveFlag.Or(setup.priorityFlag)) {
116109
ns.SetStateSub(node, setup.inactiveFlag, nodestate.Flags{}, 0) // priority gained; remove timeout

‎les/vflux/server/clientpool_test.go‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,13 @@ func TestPaidClientKickedOut(t *testing.T) {
326326
if cap := connect(pool, newPoolTestPeer(11, kickedCh)); cap == 0 {
327327
t.Fatalf("Free client should be accepted")
328328
}
329+
clock.Run(0)
329330
select {
330331
case id := <-kickedCh:
331332
if id != 0 {
332333
t.Fatalf("Kicked client mismatch, want %v, got %v", 0, id)
333334
}
334-
case <-time.NewTimer(time.Second).C:
335+
default:
335336
t.Fatalf("timeout")
336337
}
337338
}
@@ -399,23 +400,27 @@ func TestFreeClientKickedOut(t *testing.T) {
399400
if cap := connect(pool, newPoolTestPeer(10, kicked)); cap != 0 {
400401
t.Fatalf("New free client should be rejected")
401402
}
403+
clock.Run(0)
402404
select {
403405
case <-kicked:
404-
case <-time.NewTimer(time.Second).C:
406+
default:
405407
t.Fatalf("timeout")
406408
}
407409
disconnect(pool, newPoolTestPeer(10, kicked))
408410
clock.Run(5 * time.Minute)
409411
for i := 0; i < 10; i++ {
410412
connect(pool, newPoolTestPeer(i+10, kicked))
413+
411414
}
415+
clock.Run(0)
416+
412417
for i := 0; i < 10; i++ {
413418
select {
414419
case id := <-kicked:
415420
if id >= 10 {
416421
t.Fatalf("Old client should be kicked, now got: %d", id)
417422
}
418-
case <-time.NewTimer(time.Second).C:
423+
default:
419424
t.Fatalf("timeout")
420425
}
421426
}

0 commit comments

Comments
 (0)