mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-15 17:30:44 +00:00
cmd/XDC, cmd/utils: set network flag early (#938)
* cmd/XDC: remove unused function applyValues * cmd/XDC, cmd/utils: remove function SetupNetwork * cmd/XDC, cmd/utils: set network flag early
This commit is contained in:
parent
9656e2d1c4
commit
fb300a43fb
3 changed files with 19 additions and 39 deletions
|
|
@ -182,6 +182,8 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, XDCConfig) {
|
||||||
}
|
}
|
||||||
cfg.Account.Passwords = passwords
|
cfg.Account.Passwords = passwords
|
||||||
|
|
||||||
|
utils.SetNetworkFlagById(ctx, &cfg.Eth)
|
||||||
|
|
||||||
// Apply flags.
|
// Apply flags.
|
||||||
utils.SetNodeConfig(ctx, &cfg.Node)
|
utils.SetNodeConfig(ctx, &cfg.Node)
|
||||||
stack, err := node.New(&cfg.Node)
|
stack, err := node.New(&cfg.Node)
|
||||||
|
|
@ -205,19 +207,6 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, XDCConfig) {
|
||||||
return stack, cfg
|
return stack, cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyValues(values []string, params *[]string) {
|
|
||||||
data := []string{}
|
|
||||||
for _, value := range values {
|
|
||||||
if trimmed := strings.TrimSpace(value); trimmed != "" {
|
|
||||||
data = append(data, trimmed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(data) > 0 {
|
|
||||||
*params = data
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend, XDCConfig) {
|
func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend, XDCConfig) {
|
||||||
stack, cfg := makeConfigNode(ctx)
|
stack, cfg := makeConfigNode(ctx)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/log"
|
"github.com/XinFinOrg/XDPoSChain/log"
|
||||||
"github.com/XinFinOrg/XDPoSChain/metrics"
|
"github.com/XinFinOrg/XDPoSChain/metrics"
|
||||||
"github.com/XinFinOrg/XDPoSChain/node"
|
"github.com/XinFinOrg/XDPoSChain/node"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
// Force-load the native, to trigger registration
|
// Force-load the native, to trigger registration
|
||||||
|
|
@ -231,7 +232,7 @@ func init() {
|
||||||
// Start system runtime metrics collection
|
// Start system runtime metrics collection
|
||||||
go metrics.CollectProcessMetrics(3 * time.Second)
|
go metrics.CollectProcessMetrics(3 * time.Second)
|
||||||
|
|
||||||
utils.SetupNetwork(ctx)
|
params.TargetGasLimit = ctx.Uint64(utils.MinerGasLimitFlag.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -893,11 +893,10 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
|
||||||
if cfg.BootstrapNodes != nil {
|
if cfg.BootstrapNodes != nil {
|
||||||
return // Already set by config file, don't apply defaults.
|
return // Already set by config file, don't apply defaults.
|
||||||
}
|
}
|
||||||
networkID := ctx.Uint64(NetworkIdFlag.Name)
|
|
||||||
switch {
|
switch {
|
||||||
case ctx.Bool(TestnetFlag.Name) || networkID == 51:
|
case ctx.Bool(TestnetFlag.Name):
|
||||||
urls = params.TestnetBootnodes
|
urls = params.TestnetBootnodes
|
||||||
case ctx.Bool(DevnetFlag.Name) || networkID == 551:
|
case ctx.Bool(DevnetFlag.Name):
|
||||||
urls = params.DevnetBootnodes
|
urls = params.DevnetBootnodes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1419,24 +1418,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
Fatalf("invalid --syncmode flag: %v", err)
|
Fatalf("invalid --syncmode flag: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ctx.IsSet(NetworkIdFlag.Name) {
|
|
||||||
cfg.NetworkId = ctx.Uint64(NetworkIdFlag.Name)
|
|
||||||
switch cfg.NetworkId {
|
|
||||||
case 50:
|
|
||||||
if !ctx.IsSet(MainnetFlag.Name) {
|
|
||||||
ctx.Set(MainnetFlag.Name, "true")
|
|
||||||
}
|
|
||||||
case 51:
|
|
||||||
common.IsTestnet = true
|
|
||||||
if !ctx.IsSet(TestnetFlag.Name) {
|
|
||||||
ctx.Set(TestnetFlag.Name, "true")
|
|
||||||
}
|
|
||||||
case 551:
|
|
||||||
if !ctx.IsSet(DevnetFlag.Name) {
|
|
||||||
ctx.Set(DevnetFlag.Name, "true")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheDatabaseFlag.Name) {
|
if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheDatabaseFlag.Name) {
|
||||||
cfg.DatabaseCache = ctx.Int(CacheFlag.Name) * ctx.Int(CacheDatabaseFlag.Name) / 100
|
cfg.DatabaseCache = ctx.Int(CacheFlag.Name) * ctx.Int(CacheDatabaseFlag.Name) / 100
|
||||||
|
|
@ -1569,10 +1550,19 @@ func RegisterXDCXService(stack *node.Node, cfg *XDCx.Config) (*XDCx.XDCX, *XDCxl
|
||||||
return XDCX, lendingServ
|
return XDCX, lendingServ
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupNetwork configures the system for either the main net or some test network.
|
func SetNetworkFlagById(ctx *cli.Context, cfg *ethconfig.Config) {
|
||||||
func SetupNetwork(ctx *cli.Context) {
|
if ctx.IsSet(NetworkIdFlag.Name) {
|
||||||
// TODO(fjl): move target gas limit into config
|
cfg.NetworkId = ctx.Uint64(NetworkIdFlag.Name)
|
||||||
params.TargetGasLimit = ctx.Uint64(MinerGasLimitFlag.Name)
|
switch cfg.NetworkId {
|
||||||
|
case 50:
|
||||||
|
ctx.Set(MainnetFlag.Name, "true")
|
||||||
|
case 51:
|
||||||
|
common.IsTestnet = true
|
||||||
|
ctx.Set(TestnetFlag.Name, "true")
|
||||||
|
case 551:
|
||||||
|
ctx.Set(DevnetFlag.Name, "true")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupMetrics configures the metrics system.
|
// SetupMetrics configures the metrics system.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue