cmd/utils: change default value of some flags to simplify sync

This commit is contained in:
Daniel Liu 2025-02-14 11:53:49 +08:00
parent ede4c10961
commit bea5c95a7c
2 changed files with 30 additions and 38 deletions

View file

@ -101,7 +101,7 @@ func TestHTTPAttachWelcome(t *testing.T) {
XDC := runXDC(t, XDC := runXDC(t,
"--datadir", datadir, "--XDCx-datadir", datadir+"/XDCx", "--datadir", datadir, "--XDCx-datadir", datadir+"/XDCx",
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--miner-etherbase", coinbase, "--http", "--http-port", port) "--miner-etherbase", coinbase, "--http", "--http-port", port, "--http-api", "eth,net,rpc,web3")
time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
testAttachWelcome(t, XDC, "http://localhost:"+port, httpAPIs) testAttachWelcome(t, XDC, "http://localhost:"+port, httpAPIs)
@ -117,7 +117,7 @@ func TestWSAttachWelcome(t *testing.T) {
XDC := runXDC(t, XDC := runXDC(t,
"--datadir", datadir, "--XDCx-datadir", datadir+"/XDCx", "--datadir", datadir, "--XDCx-datadir", datadir+"/XDCx",
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--miner-etherbase", coinbase, "--ws", "--ws-port", port) "--miner-etherbase", coinbase, "--ws", "--ws-port", port, "--ws-api", "eth,net,rpc,web3")
time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
testAttachWelcome(t, XDC, "ws://localhost:"+port, httpAPIs) testAttachWelcome(t, XDC, "ws://localhost:"+port, httpAPIs)

View file

@ -345,21 +345,21 @@ var (
Name: "miner-gaslimit", Name: "miner-gaslimit",
Aliases: []string{"targetgaslimit"}, Aliases: []string{"targetgaslimit"},
Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine", Usage: "Target gas limit sets the artificial target gas floor for the blocks to mine",
Value: params.XDCGenesisGasLimit, Value: 50000000,
Category: flags.MinerCategory, Category: flags.MinerCategory,
} }
MinerGasPriceFlag = &flags.BigFlag{ MinerGasPriceFlag = &flags.BigFlag{
Name: "miner-gasprice", Name: "miner-gasprice",
Aliases: []string{"gasprice"}, Aliases: []string{"gasprice"},
Usage: "Minimal gas price to accept for mining a transactions", Usage: "Minimal gas price to accept for mining a transactions",
Value: ethconfig.Defaults.GasPrice, Value: big.NewInt(1),
Category: flags.MinerCategory, Category: flags.MinerCategory,
} }
MinerEtherbaseFlag = &cli.StringFlag{ MinerEtherbaseFlag = &cli.StringFlag{
Name: "miner-etherbase", Name: "miner-etherbase",
Aliases: []string{"etherbase"}, Aliases: []string{"etherbase"},
Usage: "Public address for block mining rewards (default = first account created)", Usage: "Public address for block mining rewards (default = first account created)",
Value: "0", Value: "0x000000000000000000000000000000000000abcd",
Category: flags.MinerCategory, Category: flags.MinerCategory,
} }
MinerExtraDataFlag = &cli.StringFlag{ MinerExtraDataFlag = &cli.StringFlag{
@ -437,13 +437,14 @@ var (
Name: "http", Name: "http",
Aliases: []string{"rpc"}, Aliases: []string{"rpc"},
Usage: "Enable the HTTP-RPC server", Usage: "Enable the HTTP-RPC server",
Value: true,
Category: flags.APICategory, Category: flags.APICategory,
} }
HTTPListenAddrFlag = &cli.StringFlag{ HTTPListenAddrFlag = &cli.StringFlag{
Name: "http-addr", Name: "http-addr",
Aliases: []string{"rpcaddr"}, Aliases: []string{"rpcaddr"},
Usage: "HTTP-RPC server listening interface", Usage: "HTTP-RPC server listening interface",
Value: node.DefaultHTTPHost, Value: "0.0.0.0",
Category: flags.APICategory, Category: flags.APICategory,
} }
HTTPPortFlag = &cli.IntFlag{ HTTPPortFlag = &cli.IntFlag{
@ -457,21 +458,21 @@ var (
Name: "http-corsdomain", Name: "http-corsdomain",
Aliases: []string{"rpccorsdomain"}, Aliases: []string{"rpccorsdomain"},
Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)", Usage: "Comma separated list of domains from which to accept cross origin requests (browser enforced)",
Value: "", Value: "*",
Category: flags.APICategory, Category: flags.APICategory,
} }
HTTPVirtualHostsFlag = &cli.StringFlag{ HTTPVirtualHostsFlag = &cli.StringFlag{
Name: "http-vhosts", Name: "http-vhosts",
Aliases: []string{"rpcvhosts"}, Aliases: []string{"rpcvhosts"},
Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.", Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
Value: strings.Join(node.DefaultConfig.HTTPVirtualHosts, ","), Value: "*",
Category: flags.APICategory, Category: flags.APICategory,
} }
HTTPApiFlag = &cli.StringFlag{ HTTPApiFlag = &cli.StringFlag{
Name: "http-api", Name: "http-api",
Aliases: []string{"rpcapi"}, Aliases: []string{"rpcapi"},
Usage: "API's offered over the HTTP-RPC interface", Usage: "API's offered over the HTTP-RPC interface",
Value: "", Value: "debug,eth,net,personal,txpool,web3,XDPoS",
Category: flags.APICategory, Category: flags.APICategory,
} }
HTTPReadTimeoutFlag = &cli.DurationFlag{ HTTPReadTimeoutFlag = &cli.DurationFlag{
@ -498,13 +499,14 @@ var (
WSEnabledFlag = &cli.BoolFlag{ WSEnabledFlag = &cli.BoolFlag{
Name: "ws", Name: "ws",
Usage: "Enable the WS-RPC server", Usage: "Enable the WS-RPC server",
Value: true,
Category: flags.APICategory, Category: flags.APICategory,
} }
WSListenAddrFlag = &cli.StringFlag{ WSListenAddrFlag = &cli.StringFlag{
Name: "ws-addr", Name: "ws-addr",
Aliases: []string{"wsaddr"}, Aliases: []string{"wsaddr"},
Usage: "WS-RPC server listening interface", Usage: "WS-RPC server listening interface",
Value: node.DefaultWSHost, Value: "0.0.0.0",
Category: flags.APICategory, Category: flags.APICategory,
} }
WSPortFlag = &cli.IntFlag{ WSPortFlag = &cli.IntFlag{
@ -518,14 +520,14 @@ var (
Name: "ws-api", Name: "ws-api",
Aliases: []string{"wsapi"}, Aliases: []string{"wsapi"},
Usage: "API's offered over the WS-RPC interface", Usage: "API's offered over the WS-RPC interface",
Value: "", Value: "debug,eth,net,personal,txpool,web3,XDPoS",
Category: flags.APICategory, Category: flags.APICategory,
} }
WSAllowedOriginsFlag = &cli.StringFlag{ WSAllowedOriginsFlag = &cli.StringFlag{
Name: "ws-origins", Name: "ws-origins",
Aliases: []string{"wsorigins"}, Aliases: []string{"wsorigins"},
Usage: "Origins from which to accept websockets requests", Usage: "Origins from which to accept websockets requests",
Value: "", Value: "*",
Category: flags.APICategory, Category: flags.APICategory,
} }
ExecFlag = &cli.StringFlag{ ExecFlag = &cli.StringFlag{
@ -970,11 +972,11 @@ func splitAndTrim(input string) (ret []string) {
// setHTTP creates the HTTP RPC listener interface string from the set // setHTTP creates the HTTP RPC listener interface string from the set
// command line flags, returning empty if the HTTP endpoint is disabled. // command line flags, returning empty if the HTTP endpoint is disabled.
func setHTTP(ctx *cli.Context, cfg *node.Config) { func setHTTP(ctx *cli.Context, cfg *node.Config) {
if ctx.Bool(HTTPEnabledFlag.Name) && cfg.HTTPHost == "" { if ctx.Bool(HTTPEnabledFlag.Name) {
cfg.HTTPHost = "127.0.0.1" if cfg.HTTPHost == "" {
if ctx.IsSet(HTTPListenAddrFlag.Name) { cfg.HTTPHost = "127.0.0.1"
cfg.HTTPHost = ctx.String(HTTPListenAddrFlag.Name)
} }
cfg.HTTPHost = ctx.String(HTTPListenAddrFlag.Name)
} }
if ctx.IsSet(HTTPPortFlag.Name) { if ctx.IsSet(HTTPPortFlag.Name) {
@ -989,36 +991,26 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
if ctx.IsSet(HTTPIdleTimeoutFlag.Name) { if ctx.IsSet(HTTPIdleTimeoutFlag.Name) {
cfg.HTTPTimeouts.IdleTimeout = ctx.Duration(HTTPIdleTimeoutFlag.Name) cfg.HTTPTimeouts.IdleTimeout = ctx.Duration(HTTPIdleTimeoutFlag.Name)
} }
if ctx.IsSet(HTTPCORSDomainFlag.Name) { cfg.HTTPCors = splitAndTrim(ctx.String(HTTPCORSDomainFlag.Name))
cfg.HTTPCors = splitAndTrim(ctx.String(HTTPCORSDomainFlag.Name)) cfg.HTTPModules = splitAndTrim(ctx.String(HTTPApiFlag.Name))
} cfg.HTTPVirtualHosts = splitAndTrim(ctx.String(HTTPVirtualHostsFlag.Name))
if ctx.IsSet(HTTPApiFlag.Name) {
cfg.HTTPModules = splitAndTrim(ctx.String(HTTPApiFlag.Name))
}
if ctx.IsSet(HTTPVirtualHostsFlag.Name) {
cfg.HTTPVirtualHosts = splitAndTrim(ctx.String(HTTPVirtualHostsFlag.Name))
}
} }
// setWS creates the WebSocket RPC listener interface string from the set // setWS creates the WebSocket RPC listener interface string from the set
// command line flags, returning empty if the HTTP endpoint is disabled. // command line flags, returning empty if the HTTP endpoint is disabled.
func setWS(ctx *cli.Context, cfg *node.Config) { func setWS(ctx *cli.Context, cfg *node.Config) {
if ctx.Bool(WSEnabledFlag.Name) && cfg.WSHost == "" { if ctx.Bool(WSEnabledFlag.Name) {
cfg.WSHost = "127.0.0.1" if cfg.WSHost == "" {
if ctx.IsSet(WSListenAddrFlag.Name) { cfg.WSHost = "127.0.0.1"
cfg.WSHost = ctx.String(WSListenAddrFlag.Name)
} }
cfg.WSHost = ctx.String(WSListenAddrFlag.Name)
} }
if ctx.IsSet(WSPortFlag.Name) { if ctx.IsSet(WSPortFlag.Name) {
cfg.WSPort = ctx.Int(WSPortFlag.Name) cfg.WSPort = ctx.Int(WSPortFlag.Name)
} }
if ctx.IsSet(WSAllowedOriginsFlag.Name) { cfg.WSOrigins = splitAndTrim(ctx.String(WSAllowedOriginsFlag.Name))
cfg.WSOrigins = splitAndTrim(ctx.String(WSAllowedOriginsFlag.Name)) cfg.WSModules = splitAndTrim(ctx.String(WSApiFlag.Name))
}
if ctx.IsSet(WSApiFlag.Name) {
cfg.WSModules = splitAndTrim(ctx.String(WSApiFlag.Name))
}
} }
// setIPC creates an IPC path configuration from the set command line flags, // setIPC creates an IPC path configuration from the set command line flags,
@ -1098,6 +1090,8 @@ func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *ethconfig.Config
Fatalf("Option %q: %v", MinerEtherbaseFlag.Name, err) Fatalf("Option %q: %v", MinerEtherbaseFlag.Name, err)
} }
cfg.Etherbase = account.Address cfg.Etherbase = account.Address
} else {
cfg.Etherbase = common.HexToAddress(ctx.String(MinerEtherbaseFlag.Name))
} }
} }
@ -1482,9 +1476,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.IsSet(MinerExtraDataFlag.Name) { if ctx.IsSet(MinerExtraDataFlag.Name) {
cfg.ExtraData = []byte(ctx.String(MinerExtraDataFlag.Name)) cfg.ExtraData = []byte(ctx.String(MinerExtraDataFlag.Name))
} }
if ctx.IsSet(MinerGasPriceFlag.Name) { cfg.GasPrice = flags.GlobalBig(ctx, MinerGasPriceFlag.Name)
cfg.GasPrice = flags.GlobalBig(ctx, MinerGasPriceFlag.Name)
}
if ctx.IsSet(CacheLogSizeFlag.Name) { if ctx.IsSet(CacheLogSizeFlag.Name) {
cfg.FilterLogCacheSize = ctx.Int(CacheLogSizeFlag.Name) cfg.FilterLogCacheSize = ctx.Int(CacheLogSizeFlag.Name)
} }