Update default cli config (#323)

* update the default cli config

* fix: handle maxpeers flag override, added tests

* add: no-snapshot flag, handle snapshot disable

* fix: update default flags

* add: update the sealer.GasPrice default to 30 gewi

* fix: remove snapshot flag, rely on no-snapshot only
This commit is contained in:
Manav Darji 2022-04-26 13:50:53 +05:30 committed by Victor Castell
parent 388b68cd05
commit 597037df30
3 changed files with 51 additions and 20 deletions

View file

@ -58,8 +58,8 @@ type Config struct {
// GcMode selects the garbage collection mode for the trie
GcMode string `hcl:"gc-mode,optional"`
// XXX
Snapshot bool `hcl:"snapshot,optional"`
// NoSnapshot disbales the snapshot database mode
NoSnapshot bool `hcl:"no-snapshot,optional"`
// Ethstats is the address of the ethstats server to send telemetry
Ethstats string `hcl:"ethstats,optional"`
@ -406,27 +406,27 @@ func DefaultConfig() *Config {
URL: "http://localhost:1317",
Without: false,
},
SyncMode: "full",
GcMode: "full",
Snapshot: true,
SyncMode: "full",
GcMode: "full",
NoSnapshot: false,
TxPool: &TxPoolConfig{
Locals: []string{},
NoLocals: false,
Journal: "",
Rejournal: time.Duration(1 * time.Hour),
PriceLimit: 1,
PriceLimit: 30000000000,
PriceBump: 10,
AccountSlots: 16,
GlobalSlots: 4096,
AccountQueue: 64,
GlobalQueue: 1024,
GlobalSlots: 32768,
AccountQueue: 16,
GlobalQueue: 32768,
LifeTime: time.Duration(3 * time.Hour),
},
Sealer: &SealerConfig{
Enabled: false,
Etherbase: "",
GasCeil: 8000000,
GasPrice: big.NewInt(params.GWei),
GasPrice: big.NewInt(30 * params.GWei),
ExtraData: "",
},
Gpo: &GpoConfig{
@ -443,11 +443,11 @@ func DefaultConfig() *Config {
GasCap: ethconfig.Defaults.RPCGasCap,
TxFeeCap: ethconfig.Defaults.RPCTxFeeCap,
Http: &APIConfig{
Enabled: true,
Enabled: false,
Port: 8545,
Prefix: "",
Host: "localhost",
Modules: []string{"eth", "web3", "net"},
Modules: []string{"eth", "net", "web3", "txpool", "bor"},
},
Ws: &APIConfig{
Enabled: false,
@ -805,7 +805,7 @@ func (c *Config) buildEth(stack *node.Node) (*ethconfig.Config, error) {
}
// snapshot disable check
if c.Snapshot {
if c.NoSnapshot {
if n.SyncMode == downloader.SnapSync {
log.Info("Snap sync requested, enabling --snapshot")
} else {
@ -867,6 +867,10 @@ func (c *Config) buildNode() (*node.Config, error) {
cfg.P2P.ListenAddr = ""
cfg.P2P.NoDial = true
cfg.P2P.DiscoveryV5 = false
// enable JsonRPC HTTP API
c.JsonRPC.Http.Enabled = true
cfg.HTTPModules = []string{"admin", "debug", "eth", "miner", "net", "personal", "txpool", "web3", "bor"}
}
// enable jsonrpc endpoints
@ -922,6 +926,11 @@ func (c *Config) Merge(cc ...*Config) error {
if err := mergo.Merge(c, elem, mergo.WithOverride, mergo.WithAppendSlice); err != nil {
return fmt.Errorf("failed to merge configurations: %v", err)
}
// override max peers
if elem.P2P.MaxPeers == 0 {
c.P2P.MaxPeers = 0
}
}
return nil
}

View file

@ -22,8 +22,8 @@ func TestConfigDefault(t *testing.T) {
func TestConfigMerge(t *testing.T) {
c0 := &Config{
Chain: "0",
Snapshot: true,
Chain: "0",
NoSnapshot: true,
Whitelist: map[string]string{
"a": "b",
},
@ -53,8 +53,8 @@ func TestConfigMerge(t *testing.T) {
},
}
expected := &Config{
Chain: "1",
Snapshot: true,
Chain: "1",
NoSnapshot: true,
Whitelist: map[string]string{
"a": "b",
"b": "c",
@ -76,6 +76,28 @@ func TestConfigMerge(t *testing.T) {
assert.Equal(t, c0, expected)
}
func TestDefaultDatatypeOverride(t *testing.T) {
// This test is specific to `maxpeers` flag (for now) to check
// if default datatype value (0 in case of uint64) is overridden.
c0 := &Config{
P2P: &P2PConfig{
MaxPeers: 30,
},
}
c1 := &Config{
P2P: &P2PConfig{
MaxPeers: 0,
},
}
expected := &Config{
P2P: &P2PConfig{
MaxPeers: 0,
},
}
assert.NoError(t, c0.Merge(c1))
assert.Equal(t, c0, expected)
}
func TestConfigLoadFile(t *testing.T) {
readFile := func(path string) {
config, err := readConfigFile(path)

View file

@ -50,9 +50,9 @@ func (c *Command) Flags() *flagset.Flagset {
Value: &c.cliConfig.Whitelist,
})
f.BoolFlag(&flagset.BoolFlag{
Name: "snapshot",
Usage: `Enables snapshot-database mode (default = enable)`,
Value: &c.cliConfig.Snapshot,
Name: "no-snapshot",
Usage: `Disables the snapshot-database mode (default = false)`,
Value: &c.cliConfig.NoSnapshot,
})
// heimdall