2016-11-09 02:01:56 +01:00
|
|
|
// Copyright 2016 The go-ethereum Authors
|
2016-10-14 05:51:29 +02:00
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package les
|
|
|
|
|
|
|
|
import (
|
2017-10-24 15:19:09 +02:00
|
|
|
"crypto/ecdsa"
|
2019-05-30 20:51:13 +02:00
|
|
|
"time"
|
2016-10-14 05:51:29 +02:00
|
|
|
|
2019-02-26 12:32:48 +01:00
|
|
|
"github.com/ethereum/go-ethereum/common/mclock"
|
2021-02-05 20:51:15 +08:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
2022-10-24 16:13:55 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core/txpool"
|
2021-02-05 20:51:15 +08:00
|
|
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
2016-10-14 05:51:29 +02:00
|
|
|
"github.com/ethereum/go-ethereum/les/flowcontrol"
|
2021-02-19 14:44:16 +01:00
|
|
|
vfs "github.com/ethereum/go-ethereum/les/vflux/server"
|
2016-10-14 05:51:29 +02:00
|
|
|
"github.com/ethereum/go-ethereum/light"
|
2017-02-22 14:10:07 +02:00
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2020-08-03 19:40:46 +02:00
|
|
|
"github.com/ethereum/go-ethereum/node"
|
2016-10-14 05:51:29 +02:00
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
2019-08-03 14:36:10 +02:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2019-10-02 13:14:27 +02:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enr"
|
2018-08-28 15:08:16 +08:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2019-02-26 12:32:48 +01:00
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2016-10-14 05:51:29 +02:00
|
|
|
)
|
|
|
|
|
2020-10-21 10:56:33 +02:00
|
|
|
var (
|
2021-04-06 20:42:50 +02:00
|
|
|
defaultPosFactors = vfs.PriceFactors{TimeFactor: 0, CapacityFactor: 1, RequestFactor: 1}
|
|
|
|
defaultNegFactors = vfs.PriceFactors{TimeFactor: 0, CapacityFactor: 1, RequestFactor: 1}
|
2020-10-21 10:56:33 +02:00
|
|
|
)
|
|
|
|
|
2021-04-06 20:42:50 +02:00
|
|
|
const defaultConnectedBias = time.Minute * 3
|
2020-10-21 10:56:33 +02:00
|
|
|
|
2021-02-05 20:51:15 +08:00
|
|
|
type ethBackend interface {
|
|
|
|
ArchiveMode() bool
|
|
|
|
BlockChain() *core.BlockChain
|
|
|
|
BloomIndexer() *core.ChainIndexer
|
|
|
|
ChainDb() ethdb.Database
|
|
|
|
Synced() bool
|
2022-10-24 16:13:55 +03:00
|
|
|
TxPool() *txpool.TxPool
|
2021-02-05 20:51:15 +08:00
|
|
|
}
|
|
|
|
|
2016-10-14 05:51:29 +02:00
|
|
|
type LesServer struct {
|
2018-08-17 12:21:53 +02:00
|
|
|
lesCommons
|
2017-10-24 15:19:09 +02:00
|
|
|
|
2019-06-11 15:40:32 +08:00
|
|
|
archiveMode bool // Flag whether the ethereum node runs in archive mode.
|
2019-08-21 17:29:34 +08:00
|
|
|
handler *serverHandler
|
2021-04-06 20:42:50 +02:00
|
|
|
peers *clientPeerSet
|
|
|
|
serverset *serverSet
|
2021-03-01 10:24:20 +01:00
|
|
|
vfluxServer *vfs.Server
|
2019-08-21 17:29:34 +08:00
|
|
|
privateKey *ecdsa.PrivateKey
|
2019-06-11 15:40:32 +08:00
|
|
|
|
2019-08-21 17:29:34 +08:00
|
|
|
// Flow control and capacity management
|
|
|
|
fcManager *flowcontrol.ClientManager
|
2019-02-26 12:32:48 +01:00
|
|
|
costTracker *costTracker
|
|
|
|
defParams flowcontrol.ServerParams
|
2019-08-21 17:29:34 +08:00
|
|
|
servingQueue *servingQueue
|
2021-04-06 20:42:50 +02:00
|
|
|
clientPool *vfs.ClientPool
|
2019-02-26 12:32:48 +01:00
|
|
|
|
2020-09-14 22:44:20 +02:00
|
|
|
minCapacity, maxCapacity uint64
|
|
|
|
threadsIdle int // Request serving threads count when system is idle.
|
|
|
|
threadsBusy int // Request serving threads count when system is busy(block insertion).
|
2020-08-03 19:40:46 +02:00
|
|
|
|
|
|
|
p2pSrv *p2p.Server
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|
|
|
|
|
2021-02-05 20:51:15 +08:00
|
|
|
func NewLesServer(node *node.Node, e ethBackend, config *ethconfig.Config) (*LesServer, error) {
|
2021-03-23 02:06:30 +08:00
|
|
|
lesDb, err := node.OpenDatabase("les.server", 0, 0, "eth/db/lesserver/", false)
|
2021-02-19 15:53:12 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-08-21 17:29:34 +08:00
|
|
|
// Calculate the number of threads used to service the light client
|
|
|
|
// requests based on the user-specified value.
|
|
|
|
threads := config.LightServ * 4 / 100
|
|
|
|
if threads < 4 {
|
|
|
|
threads = 4
|
|
|
|
}
|
2017-06-21 03:27:38 -07:00
|
|
|
srv := &LesServer{
|
2018-08-17 12:21:53 +02:00
|
|
|
lesCommons: lesCommons{
|
2019-08-21 17:29:34 +08:00
|
|
|
genesis: e.BlockChain().Genesis().Hash(),
|
2018-08-17 12:21:53 +02:00
|
|
|
config: config,
|
2019-08-21 17:29:34 +08:00
|
|
|
chainConfig: e.BlockChain().Config(),
|
2018-08-28 15:08:16 +08:00
|
|
|
iConfig: light.DefaultServerIndexerConfig,
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 15:34:02 +08:00
|
|
|
chainDb: e.ChainDb(),
|
2021-02-19 15:53:12 +01:00
|
|
|
lesDb: lesDb,
|
2019-08-21 17:29:34 +08:00
|
|
|
chainReader: e.BlockChain(),
|
2020-07-13 17:02:54 +08:00
|
|
|
chtIndexer: light.NewChtIndexer(e.ChainDb(), nil, params.CHTFrequency, params.HelperTrieProcessConfirmations, true),
|
|
|
|
bloomTrieIndexer: light.NewBloomTrieIndexer(e.ChainDb(), nil, params.BloomBitsBlocks, params.BloomTrieFrequency, true),
|
2019-08-21 17:29:34 +08:00
|
|
|
closeCh: make(chan struct{}),
|
2018-08-17 12:21:53 +02:00
|
|
|
},
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 15:34:02 +08:00
|
|
|
archiveMode: e.ArchiveMode(),
|
2021-04-06 20:42:50 +02:00
|
|
|
peers: newClientPeerSet(),
|
|
|
|
serverset: newServerSet(),
|
2021-03-01 10:24:20 +01:00
|
|
|
vfluxServer: vfs.NewServer(time.Millisecond * 10),
|
2019-08-21 17:29:34 +08:00
|
|
|
fcManager: flowcontrol.NewClientManager(nil, &mclock.System{}),
|
|
|
|
servingQueue: newServingQueue(int64(time.Millisecond*10), float64(config.LightServ)/100),
|
|
|
|
threadsBusy: config.LightServ/100 + 1,
|
|
|
|
threadsIdle: threads,
|
2020-08-03 19:40:46 +02:00
|
|
|
p2pSrv: node.Server(),
|
2017-10-24 15:19:09 +02:00
|
|
|
}
|
2021-02-25 20:55:07 +08:00
|
|
|
issync := e.Synced
|
|
|
|
if config.LightNoSyncServe {
|
|
|
|
issync = func() bool { return true }
|
|
|
|
}
|
|
|
|
srv.handler = newServerHandler(srv, e.BlockChain(), e.ChainDb(), e.TxPool(), issync)
|
2019-11-13 23:47:03 +01:00
|
|
|
srv.costTracker, srv.minCapacity = newCostTracker(e.ChainDb(), config)
|
2018-08-17 12:21:53 +02:00
|
|
|
|
2020-08-03 19:40:46 +02:00
|
|
|
// Initialize the bloom trie indexer.
|
|
|
|
e.BloomIndexer().AddChildIndexer(srv.bloomTrieIndexer)
|
2019-08-21 17:29:34 +08:00
|
|
|
|
|
|
|
// Initialize server capacity management fields.
|
|
|
|
srv.defParams = flowcontrol.ServerParams{
|
2020-09-14 22:44:20 +02:00
|
|
|
BufLimit: srv.minCapacity * bufLimitRatio,
|
|
|
|
MinRecharge: srv.minCapacity,
|
2019-08-21 17:29:34 +08:00
|
|
|
}
|
|
|
|
// LES flow control tries to more or less guarantee the possibility for the
|
|
|
|
// clients to send a certain amount of requests at any time and get a quick
|
|
|
|
// response. Most of the clients want this guarantee but don't actually need
|
|
|
|
// to send requests most of the time. Our goal is to serve as many clients as
|
|
|
|
// possible while the actually used server capacity does not exceed the limits
|
|
|
|
totalRecharge := srv.costTracker.totalRecharge()
|
2020-09-14 22:44:20 +02:00
|
|
|
srv.maxCapacity = srv.minCapacity * uint64(srv.config.LightPeers)
|
2019-11-13 23:47:03 +01:00
|
|
|
if totalRecharge > srv.maxCapacity {
|
|
|
|
srv.maxCapacity = totalRecharge
|
2019-08-21 17:29:34 +08:00
|
|
|
}
|
2020-09-14 22:44:20 +02:00
|
|
|
srv.fcManager.SetCapacityLimits(srv.minCapacity, srv.maxCapacity, srv.minCapacity*2)
|
2021-04-06 20:42:50 +02:00
|
|
|
srv.clientPool = vfs.NewClientPool(lesDb, srv.minCapacity, defaultConnectedBias, mclock.System{}, issync)
|
|
|
|
srv.clientPool.Start()
|
|
|
|
srv.clientPool.SetDefaultFactors(defaultPosFactors, defaultNegFactors)
|
|
|
|
srv.vfluxServer.Register(srv.clientPool, "les", "Ethereum light client service")
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 15:34:02 +08:00
|
|
|
srv.chtIndexer.Start(e.BlockChain())
|
2020-08-03 19:40:46 +02:00
|
|
|
|
|
|
|
node.RegisterProtocols(srv.Protocols())
|
|
|
|
node.RegisterAPIs(srv.APIs())
|
|
|
|
node.RegisterLifecycle(srv)
|
2019-02-26 12:32:48 +01:00
|
|
|
return srv, nil
|
|
|
|
}
|
2016-10-14 05:51:29 +02:00
|
|
|
|
2019-02-26 12:32:48 +01:00
|
|
|
func (s *LesServer) APIs() []rpc.API {
|
|
|
|
return []rpc.API{
|
2019-11-13 23:47:03 +01:00
|
|
|
{
|
|
|
|
Namespace: "les",
|
2022-06-21 11:05:43 +02:00
|
|
|
Service: NewLightServerAPI(s),
|
2019-11-13 23:47:03 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Namespace: "debug",
|
2022-06-21 11:05:43 +02:00
|
|
|
Service: NewDebugAPI(s),
|
2019-11-13 23:47:03 +01:00
|
|
|
},
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|
2019-02-26 12:32:48 +01:00
|
|
|
}
|
|
|
|
|
2016-10-14 05:51:29 +02:00
|
|
|
func (s *LesServer) Protocols() []p2p.Protocol {
|
2019-10-02 13:14:27 +02:00
|
|
|
ps := s.makeProtocols(ServerProtocolVersions, s.handler.runPeer, func(id enode.ID) interface{} {
|
2021-04-06 20:42:50 +02:00
|
|
|
if p := s.peers.peer(id); p != nil {
|
2019-08-21 17:29:34 +08:00
|
|
|
return p.Info()
|
|
|
|
}
|
|
|
|
return nil
|
2020-05-22 13:46:34 +02:00
|
|
|
}, nil)
|
2019-10-02 13:14:27 +02:00
|
|
|
// Add "les" ENR entries.
|
|
|
|
for i := range ps {
|
2021-03-01 10:24:20 +01:00
|
|
|
ps[i].Attributes = []enr.Entry{&lesEntry{
|
|
|
|
VfxVersion: 1,
|
|
|
|
}}
|
2019-10-02 13:14:27 +02:00
|
|
|
}
|
|
|
|
return ps
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|
|
|
|
|
2017-01-23 02:35:46 +01:00
|
|
|
// Start starts the LES server
|
2020-08-03 19:40:46 +02:00
|
|
|
func (s *LesServer) Start() error {
|
|
|
|
s.privateKey = s.p2pSrv.PrivateKey
|
2021-04-06 20:42:50 +02:00
|
|
|
s.peers.setSignerKey(s.privateKey)
|
2019-08-21 17:29:34 +08:00
|
|
|
s.handler.start()
|
|
|
|
s.wg.Add(1)
|
|
|
|
go s.capacityManagement()
|
2021-03-01 10:24:20 +01:00
|
|
|
if s.p2pSrv.DiscV5 != nil {
|
|
|
|
s.p2pSrv.DiscV5.RegisterTalkHandler("vfx", s.vfluxServer.ServeEncoded)
|
|
|
|
}
|
2020-08-03 19:40:46 +02:00
|
|
|
return nil
|
2019-08-21 17:29:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop stops the LES service
|
2020-08-03 19:40:46 +02:00
|
|
|
func (s *LesServer) Stop() error {
|
2019-08-21 17:29:34 +08:00
|
|
|
close(s.closeCh)
|
|
|
|
|
2021-04-06 20:42:50 +02:00
|
|
|
s.clientPool.Stop()
|
2021-04-21 10:19:28 +02:00
|
|
|
if s.serverset != nil {
|
|
|
|
s.serverset.close()
|
|
|
|
}
|
2021-04-06 20:42:50 +02:00
|
|
|
s.peers.close()
|
2019-08-21 17:29:34 +08:00
|
|
|
s.fcManager.Stop()
|
|
|
|
s.costTracker.stop()
|
|
|
|
s.handler.stop()
|
|
|
|
s.servingQueue.stop()
|
2021-04-21 10:19:28 +02:00
|
|
|
if s.vfluxServer != nil {
|
|
|
|
s.vfluxServer.Stop()
|
|
|
|
}
|
2019-08-21 17:29:34 +08:00
|
|
|
|
|
|
|
// Note, bloom trie indexer is closed by parent bloombits indexer.
|
2021-04-21 10:19:28 +02:00
|
|
|
if s.chtIndexer != nil {
|
|
|
|
s.chtIndexer.Close()
|
|
|
|
}
|
|
|
|
if s.lesDb != nil {
|
|
|
|
s.lesDb.Close()
|
|
|
|
}
|
2019-08-21 17:29:34 +08:00
|
|
|
s.wg.Wait()
|
|
|
|
log.Info("Les server stopped")
|
2016-10-14 05:51:29 +02:00
|
|
|
|
2020-08-03 19:40:46 +02:00
|
|
|
return nil
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 15:34:02 +08:00
|
|
|
}
|
|
|
|
|
2019-08-21 17:29:34 +08:00
|
|
|
// capacityManagement starts an event handler loop that updates the recharge curve of
|
|
|
|
// the client manager and adjusts the client pool's size according to the total
|
|
|
|
// capacity updates coming from the client manager
|
|
|
|
func (s *LesServer) capacityManagement() {
|
|
|
|
defer s.wg.Done()
|
2016-10-14 05:51:29 +02:00
|
|
|
|
2019-08-21 17:29:34 +08:00
|
|
|
processCh := make(chan bool, 100)
|
|
|
|
sub := s.handler.blockchain.SubscribeBlockProcessingEvent(processCh)
|
|
|
|
defer sub.Unsubscribe()
|
2016-11-13 12:34:50 +01:00
|
|
|
|
2019-08-21 17:29:34 +08:00
|
|
|
totalRechargeCh := make(chan uint64, 100)
|
|
|
|
totalRecharge := s.costTracker.subscribeTotalRecharge(totalRechargeCh)
|
2016-11-13 12:34:50 +01:00
|
|
|
|
2019-08-21 17:29:34 +08:00
|
|
|
totalCapacityCh := make(chan uint64, 100)
|
|
|
|
totalCapacity := s.fcManager.SubscribeTotalCapacity(totalCapacityCh)
|
2021-04-06 20:42:50 +02:00
|
|
|
s.clientPool.SetLimits(uint64(s.config.LightPeers), totalCapacity)
|
2017-10-24 15:19:09 +02:00
|
|
|
|
2019-08-21 17:29:34 +08:00
|
|
|
var (
|
|
|
|
busy bool
|
|
|
|
freePeers uint64
|
|
|
|
blockProcess mclock.AbsTime
|
|
|
|
)
|
|
|
|
updateRecharge := func() {
|
|
|
|
if busy {
|
|
|
|
s.servingQueue.setThreads(s.threadsBusy)
|
|
|
|
s.fcManager.SetRechargeCurve(flowcontrol.PieceWiseLinear{{0, 0}, {totalRecharge, totalRecharge}})
|
|
|
|
} else {
|
|
|
|
s.servingQueue.setThreads(s.threadsIdle)
|
|
|
|
s.fcManager.SetRechargeCurve(flowcontrol.PieceWiseLinear{{0, 0}, {totalRecharge / 10, totalRecharge}, {totalRecharge, totalRecharge}})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateRecharge()
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case busy = <-processCh:
|
|
|
|
if busy {
|
|
|
|
blockProcess = mclock.Now()
|
|
|
|
} else {
|
|
|
|
blockProcessingTimer.Update(time.Duration(mclock.Now() - blockProcess))
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|
2019-08-21 17:29:34 +08:00
|
|
|
updateRecharge()
|
|
|
|
case totalRecharge = <-totalRechargeCh:
|
|
|
|
totalRechargeGauge.Update(int64(totalRecharge))
|
|
|
|
updateRecharge()
|
|
|
|
case totalCapacity = <-totalCapacityCh:
|
|
|
|
totalCapacityGauge.Update(int64(totalCapacity))
|
2020-09-14 22:44:20 +02:00
|
|
|
newFreePeers := totalCapacity / s.minCapacity
|
2019-08-21 17:29:34 +08:00
|
|
|
if newFreePeers < freePeers && newFreePeers < uint64(s.config.LightPeers) {
|
|
|
|
log.Warn("Reduced free peer connections", "from", freePeers, "to", newFreePeers)
|
|
|
|
}
|
|
|
|
freePeers = newFreePeers
|
2021-04-06 20:42:50 +02:00
|
|
|
s.clientPool.SetLimits(uint64(s.config.LightPeers), totalCapacity)
|
2019-08-21 17:29:34 +08:00
|
|
|
case <-s.closeCh:
|
|
|
|
return
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|
2019-08-21 17:29:34 +08:00
|
|
|
}
|
2016-10-14 05:51:29 +02:00
|
|
|
}
|