diff --git a/internal/cli/server/config.go b/internal/cli/server/config.go index 29cb8ffa21..a5e255ad48 100644 --- a/internal/cli/server/config.go +++ b/internal/cli/server/config.go @@ -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 } diff --git a/internal/cli/server/config_test.go b/internal/cli/server/config_test.go index 62296d82a4..6f5f9ff97d 100644 --- a/internal/cli/server/config_test.go +++ b/internal/cli/server/config_test.go @@ -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) diff --git a/internal/cli/server/flags.go b/internal/cli/server/flags.go index b8f6003420..edc7276a8b 100644 --- a/internal/cli/server/flags.go +++ b/internal/cli/server/flags.go @@ -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