Skip to content

Commit c2003ed

Browse files
zsfelfoldifjl
authored andcommitted
les, les/flowcontrol: improved request serving and flow control (#18230)
This change - implements concurrent LES request serving even for a single peer. - replaces the request cost estimation method with a cost table based on benchmarks which gives much more consistent results. Until now the allowed number of light peers was just a guess which probably contributed a lot to the fluctuating quality of available service. Everything related to request cost is implemented in a single object, the 'cost tracker'. It uses a fixed cost table with a global 'correction factor'. Benchmark code is included and can be run at any time to adapt costs to low-level implementation changes. - reimplements flowcontrol.ClientManager in a cleaner and more efficient way, with added capabilities: There is now control over bandwidth, which allows using the flow control parameters for client prioritization. Target utilization over 100 percent is now supported to model concurrent request processing. Total serving bandwidth is reduced during block processing to prevent database contention. - implements an RPC API for the LES servers allowing server operators to assign priority bandwidth to certain clients and change prioritized status even while the client is connected. The new API is meant for cases where server operators charge for LES using an off-protocol mechanism. - adds a unit test for the new client manager. - adds an end-to-end test using the network simulator that tests bandwidth control functions through the new API.
1 parent c2b33a1 commit c2003ed

39 files changed

Lines changed: 3690 additions & 984 deletions

‎cmd/geth/main.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ var (
9393
utils.ExitWhenSyncedFlag,
9494
utils.GCModeFlag,
9595
utils.LightServFlag,
96+
utils.LightBandwidthInFlag,
97+
utils.LightBandwidthOutFlag,
9698
utils.LightPeersFlag,
9799
utils.LightKDFFlag,
98100
utils.WhitelistFlag,

‎cmd/geth/usage.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ var AppHelpFlagGroups = []flagGroup{
8181
utils.EthStatsURLFlag,
8282
utils.IdentityFlag,
8383
utils.LightServFlag,
84+
utils.LightBandwidthInFlag,
85+
utils.LightBandwidthOutFlag,
8486
utils.LightPeersFlag,
8587
utils.LightKDFFlag,
8688
utils.WhitelistFlag,

‎cmd/utils/flags.go‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,19 @@ var (
199199
}
200200
LightServFlag = cli.IntFlag{
201201
Name: "lightserv",
202-
Usage: "Maximum percentage of time allowed for serving LES requests (0-90)",
202+
Usage: "Maximum percentage of time allowed for serving LES requests (multi-threaded processing allows values over 100)",
203203
Value: 0,
204204
}
205+
LightBandwidthInFlag = cli.IntFlag{
206+
Name: "lightbwin",
207+
Usage: "Incoming bandwidth limit for light server (1000 bytes/sec, 0 = unlimited)",
208+
Value: 1000,
209+
}
210+
LightBandwidthOutFlag = cli.IntFlag{
211+
Name: "lightbwout",
212+
Usage: "Outgoing bandwidth limit for light server (1000 bytes/sec, 0 = unlimited)",
213+
Value: 5000,
214+
}
205215
LightPeersFlag = cli.IntFlag{
206216
Name: "lightpeers",
207217
Usage: "Maximum number of LES client peers",
@@ -1305,6 +1315,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
13051315
if ctx.GlobalIsSet(LightServFlag.Name) {
13061316
cfg.LightServ = ctx.GlobalInt(LightServFlag.Name)
13071317
}
1318+
cfg.LightBandwidthIn = ctx.GlobalInt(LightBandwidthInFlag.Name)
1319+
cfg.LightBandwidthOut = ctx.GlobalInt(LightBandwidthOutFlag.Name)
13081320
if ctx.GlobalIsSet(LightPeersFlag.Name) {
13091321
cfg.LightPeers = ctx.GlobalInt(LightPeersFlag.Name)
13101322
}

‎core/blockchain.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ type BlockChain struct {
111111
chainSideFeed event.Feed
112112
chainHeadFeed event.Feed
113113
logsFeed event.Feed
114+
blockProcFeed event.Feed
114115
scope event.SubscriptionScope
115116
genesisBlock *types.Block
116117

@@ -1090,6 +1091,10 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
10901091
if len(chain) == 0 {
10911092
return 0, nil
10921093
}
1094+
1095+
bc.blockProcFeed.Send(true)
1096+
defer bc.blockProcFeed.Send(false)
1097+
10931098
// Remove already known canon-blocks
10941099
var (
10951100
block, prev *types.Block
@@ -1725,3 +1730,9 @@ func (bc *BlockChain) SubscribeChainSideEvent(ch chan<- ChainSideEvent) event.Su
17251730
func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription {
17261731
return bc.scope.Track(bc.logsFeed.Subscribe(ch))
17271732
}
1733+
1734+
// SubscribeBlockProcessingEvent registers a subscription of bool where true means
1735+
// block processing has started while false means it has stopped.
1736+
func (bc *BlockChain) SubscribeBlockProcessingEvent(ch chan<- bool) event.Subscription {
1737+
return bc.scope.Track(bc.blockProcFeed.Subscribe(ch))
1738+
}

‎eth/backend.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import (
5454
type LesServer interface {
5555
Start(srvr *p2p.Server)
5656
Stop()
57+
APIs() []rpc.API
5758
Protocols() []p2p.Protocol
5859
SetBloomBitsIndexer(bbIndexer *core.ChainIndexer)
5960
}
@@ -267,6 +268,10 @@ func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainCo
267268
func (s *Ethereum) APIs() []rpc.API {
268269
apis := ethapi.GetAPIs(s.APIBackend)
269270

271+
// Append any APIs exposed explicitly by the les server
272+
if s.lesServer != nil {
273+
apis = append(apis, s.lesServer.APIs()...)
274+
}
270275
// Append any APIs exposed explicitly by the consensus engine
271276
apis = append(apis, s.engine.APIs(s.BlockChain())...)
272277

‎eth/config.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,11 @@ type Config struct {
9898
Whitelist map[uint64]common.Hash `toml:"-"`
9999

100100
// Light client options
101-
LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
102-
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
103-
OnlyAnnounce bool // Maximum number of LES client peers
101+
LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
102+
LightBandwidthIn int `toml:",omitempty"` // Incoming bandwidth limit for light servers
103+
LightBandwidthOut int `toml:",omitempty"` // Outgoing bandwidth limit for light servers
104+
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
105+
OnlyAnnounce bool // Maximum number of LES client peers
104106

105107
// Ultra Light client options
106108
ULC *ULCConfig `toml:",omitempty"`

‎eth/gen_config.go‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)