From 83f8c12a3aae566da6e205381afcc3ff587f0e0a Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Sun, 10 Nov 2019 22:02:21 +0100 Subject: [PATCH] les: fixed tests --- les/clientpool.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/les/clientpool.go b/les/clientpool.go index 96a7b90332..2a18abfde1 100644 --- a/les/clientpool.go +++ b/les/clientpool.go @@ -251,11 +251,16 @@ func (f *clientPool) connect(peer clientPeer, capacity uint64) bool { } // If the client is a free client, assign with a low free capacity, // Otherwise assign with the given value(priority client) - if !e.priority { + if !e.priority || capacity == 0 { capacity = f.freeClientCap } e.capacity = capacity + // Starts a balance tracker + e.balanceTracker.init(f.clock, capacity) + e.balanceTracker.setBalance(posBalance, negBalance) + e.updatePriceFactors() + // If the number of clients already connected in the clientpool exceeds its // capacity, evict some clients with lowest priority. // @@ -293,16 +298,12 @@ func (f *clientPool) connect(peer clientPeer, capacity uint64) bool { f.dropClient(c, now, true) } } + // Register new client to connection queue. f.connectedMap[id] = e f.connectedQueue.Push(e) f.connectedCap += e.capacity - // Starts a balance tracker - e.balanceTracker.init(f.clock, capacity) - e.balanceTracker.setBalance(posBalance, negBalance) - e.updatePriceFactors() - // If the current client is a paid client, monitor the status of client, // downgrade it to normal client if positive balance is used up. if e.priority {