mirror of https://github.com/status-im/op-geth.git
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".
This commit is contained in:
parent
96d9306413
commit
378e961d85
|
@ -102,6 +102,7 @@ var (
|
||||||
utils.UltraLightServersFlag,
|
utils.UltraLightServersFlag,
|
||||||
utils.UltraLightFractionFlag,
|
utils.UltraLightFractionFlag,
|
||||||
utils.UltraLightOnlyAnnounceFlag,
|
utils.UltraLightOnlyAnnounceFlag,
|
||||||
|
utils.LightNoSyncServeFlag,
|
||||||
utils.WhitelistFlag,
|
utils.WhitelistFlag,
|
||||||
utils.BloomFilterSizeFlag,
|
utils.BloomFilterSizeFlag,
|
||||||
utils.CacheFlag,
|
utils.CacheFlag,
|
||||||
|
|
|
@ -68,6 +68,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
|
||||||
utils.UltraLightFractionFlag,
|
utils.UltraLightFractionFlag,
|
||||||
utils.UltraLightOnlyAnnounceFlag,
|
utils.UltraLightOnlyAnnounceFlag,
|
||||||
utils.LightNoPruneFlag,
|
utils.LightNoPruneFlag,
|
||||||
|
utils.LightNoSyncServeFlag,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -269,6 +269,10 @@ var (
|
||||||
Name: "light.nopruning",
|
Name: "light.nopruning",
|
||||||
Usage: "Disable ancient light chain data pruning",
|
Usage: "Disable ancient light chain data pruning",
|
||||||
}
|
}
|
||||||
|
LightNoSyncServeFlag = cli.BoolFlag{
|
||||||
|
Name: "light.nosyncserve",
|
||||||
|
Usage: "Enables serving light clients before syncing",
|
||||||
|
}
|
||||||
// Ethash settings
|
// Ethash settings
|
||||||
EthashCacheDirFlag = DirectoryFlag{
|
EthashCacheDirFlag = DirectoryFlag{
|
||||||
Name: "ethash.cachedir",
|
Name: "ethash.cachedir",
|
||||||
|
@ -1042,6 +1046,9 @@ func setLes(ctx *cli.Context, cfg *ethconfig.Config) {
|
||||||
if ctx.GlobalIsSet(LightNoPruneFlag.Name) {
|
if ctx.GlobalIsSet(LightNoPruneFlag.Name) {
|
||||||
cfg.LightNoPrune = ctx.GlobalBool(LightNoPruneFlag.Name)
|
cfg.LightNoPrune = ctx.GlobalBool(LightNoPruneFlag.Name)
|
||||||
}
|
}
|
||||||
|
if ctx.GlobalIsSet(LightNoSyncServeFlag.Name) {
|
||||||
|
cfg.LightNoSyncServe = ctx.GlobalBool(LightNoSyncServeFlag.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeDatabaseHandles raises out the number of allowed file handles per process
|
// MakeDatabaseHandles raises out the number of allowed file handles per process
|
||||||
|
|
|
@ -140,6 +140,7 @@ type Config struct {
|
||||||
LightEgress int `toml:",omitempty"` // Outgoing bandwidth limit for light servers
|
LightEgress int `toml:",omitempty"` // Outgoing bandwidth limit for light servers
|
||||||
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
|
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
|
||||||
LightNoPrune bool `toml:",omitempty"` // Whether to disable light chain pruning
|
LightNoPrune bool `toml:",omitempty"` // Whether to disable light chain pruning
|
||||||
|
LightNoSyncServe bool `toml:",omitempty"` // Whether to serve light clients before syncing
|
||||||
SyncFromCheckpoint bool `toml:",omitempty"` // Whether to sync the header chain from the configured checkpoint
|
SyncFromCheckpoint bool `toml:",omitempty"` // Whether to sync the header chain from the configured checkpoint
|
||||||
|
|
||||||
// Ultra Light client options
|
// Ultra Light client options
|
||||||
|
|
|
@ -31,6 +31,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
LightEgress int `toml:",omitempty"`
|
LightEgress int `toml:",omitempty"`
|
||||||
LightPeers int `toml:",omitempty"`
|
LightPeers int `toml:",omitempty"`
|
||||||
LightNoPrune bool `toml:",omitempty"`
|
LightNoPrune bool `toml:",omitempty"`
|
||||||
|
LightNoSyncServe bool `toml:",omitempty"`
|
||||||
SyncFromCheckpoint bool `toml:",omitempty"`
|
SyncFromCheckpoint bool `toml:",omitempty"`
|
||||||
UltraLightServers []string `toml:",omitempty"`
|
UltraLightServers []string `toml:",omitempty"`
|
||||||
UltraLightFraction int `toml:",omitempty"`
|
UltraLightFraction int `toml:",omitempty"`
|
||||||
|
@ -74,6 +75,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
enc.LightEgress = c.LightEgress
|
enc.LightEgress = c.LightEgress
|
||||||
enc.LightPeers = c.LightPeers
|
enc.LightPeers = c.LightPeers
|
||||||
enc.LightNoPrune = c.LightNoPrune
|
enc.LightNoPrune = c.LightNoPrune
|
||||||
|
enc.LightNoSyncServe = c.LightNoSyncServe
|
||||||
enc.SyncFromCheckpoint = c.SyncFromCheckpoint
|
enc.SyncFromCheckpoint = c.SyncFromCheckpoint
|
||||||
enc.UltraLightServers = c.UltraLightServers
|
enc.UltraLightServers = c.UltraLightServers
|
||||||
enc.UltraLightFraction = c.UltraLightFraction
|
enc.UltraLightFraction = c.UltraLightFraction
|
||||||
|
@ -121,6 +123,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
LightEgress *int `toml:",omitempty"`
|
LightEgress *int `toml:",omitempty"`
|
||||||
LightPeers *int `toml:",omitempty"`
|
LightPeers *int `toml:",omitempty"`
|
||||||
LightNoPrune *bool `toml:",omitempty"`
|
LightNoPrune *bool `toml:",omitempty"`
|
||||||
|
LightNoSyncServe *bool `toml:",omitempty"`
|
||||||
SyncFromCheckpoint *bool `toml:",omitempty"`
|
SyncFromCheckpoint *bool `toml:",omitempty"`
|
||||||
UltraLightServers []string `toml:",omitempty"`
|
UltraLightServers []string `toml:",omitempty"`
|
||||||
UltraLightFraction *int `toml:",omitempty"`
|
UltraLightFraction *int `toml:",omitempty"`
|
||||||
|
@ -195,6 +198,9 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
if dec.LightNoPrune != nil {
|
if dec.LightNoPrune != nil {
|
||||||
c.LightNoPrune = *dec.LightNoPrune
|
c.LightNoPrune = *dec.LightNoPrune
|
||||||
}
|
}
|
||||||
|
if dec.LightNoSyncServe != nil {
|
||||||
|
c.LightNoSyncServe = *dec.LightNoSyncServe
|
||||||
|
}
|
||||||
if dec.SyncFromCheckpoint != nil {
|
if dec.SyncFromCheckpoint != nil {
|
||||||
c.SyncFromCheckpoint = *dec.SyncFromCheckpoint
|
c.SyncFromCheckpoint = *dec.SyncFromCheckpoint
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,11 @@ func NewLesServer(node *node.Node, e ethBackend, config *ethconfig.Config) (*Les
|
||||||
threadsIdle: threads,
|
threadsIdle: threads,
|
||||||
p2pSrv: node.Server(),
|
p2pSrv: node.Server(),
|
||||||
}
|
}
|
||||||
srv.handler = newServerHandler(srv, e.BlockChain(), e.ChainDb(), e.TxPool(), e.Synced)
|
issync := e.Synced
|
||||||
|
if config.LightNoSyncServe {
|
||||||
|
issync = func() bool { return true }
|
||||||
|
}
|
||||||
|
srv.handler = newServerHandler(srv, e.BlockChain(), e.ChainDb(), e.TxPool(), issync)
|
||||||
srv.costTracker, srv.minCapacity = newCostTracker(e.ChainDb(), config)
|
srv.costTracker, srv.minCapacity = newCostTracker(e.ChainDb(), config)
|
||||||
srv.oracle = srv.setupOracle(node, e.BlockChain().Genesis().Hash(), config)
|
srv.oracle = srv.setupOracle(node, e.BlockChain().Genesis().Hash(), config)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue