Skip to content

Commit 378e961

Browse files
authored
cmd, eth, les: enable serving light clients when non-synced (#22250)
This PR adds a more CLI flag, so that the les-server can serve light clients even the local node is not synced yet. This functionality is needed in some testing environments(e.g. hive). After launching the les server, no more blocks will be imported so the node is always marked as "non-synced".
1 parent 96d9306 commit 378e961

6 files changed

Lines changed: 21 additions & 1 deletion

File tree

‎cmd/geth/main.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ var (
102102
utils.UltraLightServersFlag,
103103
utils.UltraLightFractionFlag,
104104
utils.UltraLightOnlyAnnounceFlag,
105+
utils.LightNoSyncServeFlag,
105106
utils.WhitelistFlag,
106107
utils.BloomFilterSizeFlag,
107108
utils.CacheFlag,

‎cmd/geth/usage.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
6868
utils.UltraLightFractionFlag,
6969
utils.UltraLightOnlyAnnounceFlag,
7070
utils.LightNoPruneFlag,
71+
utils.LightNoSyncServeFlag,
7172
},
7273
},
7374
{

‎cmd/utils/flags.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ var (
269269
Name: "light.nopruning",
270270
Usage: "Disable ancient light chain data pruning",
271271
}
272+
LightNoSyncServeFlag = cli.BoolFlag{
273+
Name: "light.nosyncserve",
274+
Usage: "Enables serving light clients before syncing",
275+
}
272276
// Ethash settings
273277
EthashCacheDirFlag = DirectoryFlag{
274278
Name: "ethash.cachedir",
@@ -1042,6 +1046,9 @@ func setLes(ctx *cli.Context, cfg *ethconfig.Config) {
10421046
if ctx.GlobalIsSet(LightNoPruneFlag.Name) {
10431047
cfg.LightNoPrune = ctx.GlobalBool(LightNoPruneFlag.Name)
10441048
}
1049+
if ctx.GlobalIsSet(LightNoSyncServeFlag.Name) {
1050+
cfg.LightNoSyncServe = ctx.GlobalBool(LightNoSyncServeFlag.Name)
1051+
}
10451052
}
10461053

10471054
// MakeDatabaseHandles raises out the number of allowed file handles per process

‎eth/ethconfig/config.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ type Config struct {
140140
LightEgress int `toml:",omitempty"` // Outgoing bandwidth limit for light servers
141141
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
142142
LightNoPrune bool `toml:",omitempty"` // Whether to disable light chain pruning
143+
LightNoSyncServe bool `toml:",omitempty"` // Whether to serve light clients before syncing
143144
SyncFromCheckpoint bool `toml:",omitempty"` // Whether to sync the header chain from the configured checkpoint
144145

145146
// Ultra Light client options

‎eth/ethconfig/gen_config.go‎

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

‎les/server.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ func NewLesServer(node *node.Node, e ethBackend, config *ethconfig.Config) (*Les
118118
threadsIdle: threads,
119119
p2pSrv: node.Server(),
120120
}
121-
srv.handler = newServerHandler(srv, e.BlockChain(), e.ChainDb(), e.TxPool(), e.Synced)
121+
issync := e.Synced
122+
if config.LightNoSyncServe {
123+
issync = func() bool { return true }
124+
}
125+
srv.handler = newServerHandler(srv, e.BlockChain(), e.ChainDb(), e.TxPool(), issync)
122126
srv.costTracker, srv.minCapacity = newCostTracker(e.ChainDb(), config)
123127
srv.oracle = srv.setupOracle(node, e.BlockChain().Genesis().Hash(), config)
124128

0 commit comments

Comments
 (0)