mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
eth, cmd/utils: light vs max peer configuration logic
This commit is contained in:
parent
49a3d034d9
commit
f6451496b5
3 changed files with 27 additions and 7 deletions
|
|
@ -179,7 +179,7 @@ var (
|
||||||
LightPeersFlag = cli.IntFlag{
|
LightPeersFlag = cli.IntFlag{
|
||||||
Name: "lightpeers",
|
Name: "lightpeers",
|
||||||
Usage: "Maximum number of LES client peers",
|
Usage: "Maximum number of LES client peers",
|
||||||
Value: 20,
|
Value: eth.DefaultConfig.LightPeers,
|
||||||
}
|
}
|
||||||
LightKDFFlag = cli.BoolFlag{
|
LightKDFFlag = cli.BoolFlag{
|
||||||
Name: "lightkdf",
|
Name: "lightkdf",
|
||||||
|
|
@ -789,20 +789,40 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
|
||||||
setBootstrapNodes(ctx, cfg)
|
setBootstrapNodes(ctx, cfg)
|
||||||
setBootstrapNodesV5(ctx, cfg)
|
setBootstrapNodesV5(ctx, cfg)
|
||||||
|
|
||||||
|
lightClient := ctx.GlobalBool(LightModeFlag.Name) || ctx.GlobalString(SyncModeFlag.Name) == "light"
|
||||||
|
lightServer := ctx.GlobalInt(LightServFlag.Name) != 0
|
||||||
|
lightPeers := ctx.GlobalInt(LightPeersFlag.Name)
|
||||||
|
|
||||||
if ctx.GlobalIsSet(MaxPeersFlag.Name) {
|
if ctx.GlobalIsSet(MaxPeersFlag.Name) {
|
||||||
cfg.MaxPeers = ctx.GlobalInt(MaxPeersFlag.Name)
|
cfg.MaxPeers = ctx.GlobalInt(MaxPeersFlag.Name)
|
||||||
|
} else {
|
||||||
|
if lightServer {
|
||||||
|
cfg.MaxPeers += lightPeers
|
||||||
|
}
|
||||||
|
if lightClient && ctx.GlobalIsSet(LightPeersFlag.Name) && cfg.MaxPeers < lightPeers {
|
||||||
|
cfg.MaxPeers = lightPeers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if !(lightClient || lightServer) {
|
||||||
|
lightPeers = 0
|
||||||
|
}
|
||||||
|
ethPeers := cfg.MaxPeers - lightPeers
|
||||||
|
if lightClient {
|
||||||
|
ethPeers = 0
|
||||||
|
}
|
||||||
|
log.Info("Maximum peer count", "ETH", ethPeers, "LES", lightPeers, "total", cfg.MaxPeers)
|
||||||
|
|
||||||
if ctx.GlobalIsSet(MaxPendingPeersFlag.Name) {
|
if ctx.GlobalIsSet(MaxPendingPeersFlag.Name) {
|
||||||
cfg.MaxPendingPeers = ctx.GlobalInt(MaxPendingPeersFlag.Name)
|
cfg.MaxPendingPeers = ctx.GlobalInt(MaxPendingPeersFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(NoDiscoverFlag.Name) || ctx.GlobalBool(LightModeFlag.Name) {
|
if ctx.GlobalIsSet(NoDiscoverFlag.Name) || lightClient {
|
||||||
cfg.NoDiscovery = true
|
cfg.NoDiscovery = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we're running a light client or server, force enable the v5 peer discovery
|
// if we're running a light client or server, force enable the v5 peer discovery
|
||||||
// unless it is explicitly disabled with --nodiscover note that explicitly specifying
|
// unless it is explicitly disabled with --nodiscover note that explicitly specifying
|
||||||
// --v5disc overrides --nodiscover, in which case the later only disables v4 discovery
|
// --v5disc overrides --nodiscover, in which case the later only disables v4 discovery
|
||||||
forceV5Discovery := (ctx.GlobalBool(LightModeFlag.Name) || ctx.GlobalInt(LightServFlag.Name) > 0) && !ctx.GlobalBool(NoDiscoverFlag.Name)
|
forceV5Discovery := (lightClient || lightServer) && !ctx.GlobalBool(NoDiscoverFlag.Name)
|
||||||
if ctx.GlobalIsSet(DiscoveryV5Flag.Name) {
|
if ctx.GlobalIsSet(DiscoveryV5Flag.Name) {
|
||||||
cfg.DiscoveryV5 = ctx.GlobalBool(DiscoveryV5Flag.Name)
|
cfg.DiscoveryV5 = ctx.GlobalBool(DiscoveryV5Flag.Name)
|
||||||
} else if forceV5Discovery {
|
} else if forceV5Discovery {
|
||||||
|
|
|
||||||
|
|
@ -393,10 +393,10 @@ func (s *Ethereum) Start(srvr *p2p.Server) error {
|
||||||
// Figure out a max peers count based on the server limits
|
// Figure out a max peers count based on the server limits
|
||||||
maxPeers := srvr.MaxPeers
|
maxPeers := srvr.MaxPeers
|
||||||
if s.config.LightServ > 0 {
|
if s.config.LightServ > 0 {
|
||||||
maxPeers -= s.config.LightPeers
|
if s.config.LightPeers >= srvr.MaxPeers {
|
||||||
if maxPeers < srvr.MaxPeers/2 {
|
return fmt.Errorf("invalid peer config: light peer count (%d) >= total peer count (%d)", s.config.LightPeers, srvr.MaxPeers)
|
||||||
maxPeers = srvr.MaxPeers / 2
|
|
||||||
}
|
}
|
||||||
|
maxPeers -= s.config.LightPeers
|
||||||
}
|
}
|
||||||
// Start the networking layer and the light server if requested
|
// Start the networking layer and the light server if requested
|
||||||
s.protocolManager.Start(maxPeers)
|
s.protocolManager.Start(maxPeers)
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ var DefaultConfig = Config{
|
||||||
DatasetsOnDisk: 2,
|
DatasetsOnDisk: 2,
|
||||||
},
|
},
|
||||||
NetworkId: 1,
|
NetworkId: 1,
|
||||||
LightPeers: 20,
|
LightPeers: 100,
|
||||||
DatabaseCache: 128,
|
DatabaseCache: 128,
|
||||||
GasPrice: big.NewInt(18 * params.Shannon),
|
GasPrice: big.NewInt(18 * params.Shannon),
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue