mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
les, les/lespay/server: refactor client pool (#21236)
* les, les/lespay/server: refactor client pool * les: use ns.Operation and sub calls where needed * les: fixed tests * les: removed active/inactive logic from peerSet * les: removed active/inactive peer logic * les: fixed linter warnings * les: fixed more linter errors and added missing metrics * les: addressed comments * cmd/geth: fixed TestPriorityClient * les: simplified clientPool state machine * les/lespay/server: do not use goroutine for balance callbacks * internal/web3ext: fix addBalance required parameters * les: removed freeCapacity, always connect at minCapacity initially * les: only allow capacity change with priority status Co-authored-by: rjl493456442 <garyrong0905@gmail.com> # Conflicts: # cmd/geth/les_test.go # les/api.go # les/api_test.go # les/clientpool.go # les/clientpool_test.go # les/metrics.go # les/peer.go # les/server.go # les/server_handler.go # les/test_helper.go # les/utils/expiredvalue.go
This commit is contained in:
parent
79f7f2853f
commit
f4d9f05acf
@ -36,14 +36,15 @@ type LazyQueue struct {
|
||||
// Items are stored in one of two internal queues ordered by estimated max
|
||||
// priority until the next and the next-after-next refresh. Update and Refresh
|
||||
// always places items in queue[1].
|
||||
queue [2]*sstack
|
||||
popQueue *sstack
|
||||
period time.Duration
|
||||
maxUntil mclock.AbsTime
|
||||
indexOffset int
|
||||
setIndex SetIndexCallback
|
||||
priority PriorityCallback
|
||||
maxPriority MaxPriorityCallback
|
||||
queue [2]*sstack
|
||||
popQueue *sstack
|
||||
period time.Duration
|
||||
maxUntil mclock.AbsTime
|
||||
indexOffset int
|
||||
setIndex SetIndexCallback
|
||||
priority PriorityCallback
|
||||
maxPriority MaxPriorityCallback
|
||||
lastRefresh1, lastRefresh2 mclock.AbsTime
|
||||
}
|
||||
|
||||
type (
|
||||
@ -54,14 +55,17 @@ type (
|
||||
// NewLazyQueue creates a new lazy queue
|
||||
func NewLazyQueue(setIndex SetIndexCallback, priority PriorityCallback, maxPriority MaxPriorityCallback, clock mclock.Clock, refreshPeriod time.Duration) *LazyQueue {
|
||||
q := &LazyQueue{
|
||||
popQueue: newSstack(nil),
|
||||
setIndex: setIndex,
|
||||
priority: priority,
|
||||
maxPriority: maxPriority,
|
||||
clock: clock,
|
||||
period: refreshPeriod}
|
||||
popQueue: newSstack(nil),
|
||||
setIndex: setIndex,
|
||||
priority: priority,
|
||||
maxPriority: maxPriority,
|
||||
clock: clock,
|
||||
period: refreshPeriod,
|
||||
lastRefresh1: clock.Now(),
|
||||
lastRefresh2: clock.Now(),
|
||||
}
|
||||
q.Reset()
|
||||
q.Refresh()
|
||||
q.refresh(clock.Now())
|
||||
return q
|
||||
}
|
||||
|
||||
@ -71,9 +75,19 @@ func (q *LazyQueue) Reset() {
|
||||
q.queue[1] = newSstack(q.setIndex1)
|
||||
}
|
||||
|
||||
// Refresh should be called at least with the frequency specified by the refreshPeriod parameter
|
||||
// Refresh performs queue re-evaluation if necessary
|
||||
func (q *LazyQueue) Refresh() {
|
||||
q.maxUntil = q.clock.Now() + mclock.AbsTime(q.period)
|
||||
now := q.clock.Now()
|
||||
for time.Duration(now-q.lastRefresh2) >= q.period*2 {
|
||||
q.refresh(now)
|
||||
q.lastRefresh2 = q.lastRefresh1
|
||||
q.lastRefresh1 = now
|
||||
}
|
||||
}
|
||||
|
||||
// refresh re-evaluates items in the older queue and swaps the two queues
|
||||
func (q *LazyQueue) refresh(now mclock.AbsTime) {
|
||||
q.maxUntil = now + mclock.AbsTime(q.period)
|
||||
for q.queue[0].Len() != 0 {
|
||||
q.Push(heap.Pop(q.queue[0]).(*item).value)
|
||||
}
|
||||
@ -139,6 +153,7 @@ func (q *LazyQueue) MultiPop(callback func(data interface{}, priority int64) boo
|
||||
}
|
||||
return
|
||||
}
|
||||
nextIndex = q.peekIndex() // re-check because callback is allowed to push items back
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -844,7 +844,7 @@ web3._extend({
|
||||
new web3._extend.Method({
|
||||
name: 'addBalance',
|
||||
call: 'les_addBalance',
|
||||
params: 3
|
||||
params: 2
|
||||
}),
|
||||
],
|
||||
properties:
|
||||
|
@ -330,11 +330,4 @@ Date: Mon Sep 14 22:44:20 2020 +0200
|
||||
|
||||
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
|
||||
|
||||
commit f7112cc182ec9ec43ff56d4ff3c84d2518aa30ff
|
||||
Author: Felix Lange <fjl@twurst.com>
|
||||
Date: Mon Sep 14 19:23:01 2020 +0200
|
||||
|
||||
rlp: add SplitUint64 (#21563)
|
||||
|
||||
This can be useful when working with raw RLP data.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user