Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: simplify node start #91

Merged
merged 16 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ func defaultNodeConfig() node.Config {
return cfg
}

func defaultOpBNBNodeConfig() node.Config {
git, _ := version.VCS()
cfg := node.DefaultOpBNBConfig
cfg.Name = clientIdentifier
cfg.Version = params.VersionWithCommit(git.Commit, git.Date)
cfg.HTTPModules = append(cfg.HTTPModules, "eth")
cfg.WSModules = append(cfg.WSModules, "eth")
cfg.IPCPath = "geth.ipc"
return cfg
}

// loadBaseConfig loads the gethConfig based on the given command line
// parameters and config file.
func loadBaseConfig(ctx *cli.Context) gethConfig {
Expand All @@ -134,6 +145,15 @@ func loadBaseConfig(ctx *cli.Context) gethConfig {
Metrics: metrics.DefaultConfig,
}

if ctx.Bool(utils.OpBNBMainnetFlag.Name) || ctx.Bool(utils.OpBNBTestnetFlag.Name) {
cfg.Eth = ethconfig.OpBNBDefaults
cfg.Node = defaultOpBNBNodeConfig()
if ctx.Bool(utils.OpBNBTestnetFlag.Name) {
cfg.Eth.NetworkId = 5611
cfg.Eth.TrieCommitInterval = 240
}
}

// Load config file.
if file := ctx.String(configFileFlag.Name); file != "" {
if err := loadConfig(file, &cfg); err != nil {
Expand Down
9 changes: 5 additions & 4 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,11 @@ func prepare(ctx *cli.Context) {
log.Info("Bumping default cache on mainnet", "provided", ctx.Int(utils.CacheFlag.Name), "updated", 4096, "network", ctx.String(utils.OPNetworkFlag.Name))
ctx.Set(utils.CacheFlag.Name, strconv.Itoa(4096))
}
} else if ctx.String(utils.SyncModeFlag.Name) != "light" && !ctx.IsSet(utils.CacheFlag.Name) && ctx.IsSet(utils.OpBNBMainnetFlag.Name) {
// we're really on opBNB mainnet. Bump that cache up
log.Info("Bumping default cache on mainnet", "provided", ctx.Int(utils.CacheFlag.Name), "updated", 4096, "network", ctx.String(utils.OpBNBMainnetFlag.Name))
ctx.Set(utils.CacheFlag.Name, strconv.Itoa(4096))
} else if ctx.String(utils.SyncModeFlag.Name) != "light" && !ctx.IsSet(utils.CacheFlag.Name) &&
(ctx.IsSet(utils.OpBNBMainnetFlag.Name) || ctx.IsSet(utils.OpBNBTestnetFlag.Name)) {
// we're really on opBNB network. Bump that cache up
log.Info("Bumping default cache on opBNB", "provided", ctx.Int(utils.CacheFlag.Name), "updated", 22000)
ctx.Set(utils.CacheFlag.Name, strconv.Itoa(22000))
}
// If we're running a light client on any network, drop the cache to some meaningfully low amount
if ctx.String(utils.SyncModeFlag.Name) == "light" && !ctx.IsSet(utils.CacheFlag.Name) {
Expand Down
6 changes: 6 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,8 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls = params.SepoliaBootnodes
case ctx.Bool(GoerliFlag.Name):
urls = params.GoerliBootnodes
case ctx.Bool(OpBNBTestnetFlag.Name):
urls = params.OpBNBTestnetBootnodes
case ctx.Bool(NetworkIdFlag.Name):
if ctx.Uint64(NetworkIdFlag.Name) == params.OpBNBTestnet {
urls = params.OpBNBTestnetBootnodes
Expand Down Expand Up @@ -1623,6 +1625,10 @@ func SetDataDir(ctx *cli.Context, cfg *node.Config) {
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "holesky")
case ctx.IsSet(OPNetworkFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), ctx.String(OPNetworkFlag.Name))
case ctx.IsSet(OpBNBMainnetFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "opBNBMainnet")
case ctx.IsSet(OpBNBTestnetFlag.Name) && cfg.DataDir == node.DefaultDataDir():
cfg.DataDir = filepath.Join(node.DefaultDataDir(), "opBNBTestnet")
}
}

Expand Down
31 changes: 28 additions & 3 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,32 @@ var LightClientGPO = gasprice.Config{

// Defaults contains default settings for use on the Ethereum main net.
var Defaults = Config{
SyncMode: downloader.SnapSync,
NetworkId: 1,
SyncMode: downloader.SnapSync,
NetworkId: 1,
TxLookupLimit: 2350000,
TransactionHistory: 2350000,
StateHistory: params.FullImmutabilityThreshold,
LightPeers: 100,
DatabaseCache: 512,
TrieCleanCache: 154,
TrieDirtyCache: 256,
TrieTimeout: 60 * time.Minute,
TrieCommitInterval: 0,
SnapshotCache: 102,
FilterLogCacheSize: 32,
Miner: miner.DefaultConfig,
TxPool: legacypool.DefaultConfig,
BlobPool: blobpool.DefaultConfig,
RPCGasCap: 50000000,
RPCEVMTimeout: 5 * time.Second,
GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether
}

// OpBNBDefaults contains default settings for use on the opBNB main net.
var OpBNBDefaults = Config{
SyncMode: downloader.FullSync,
NetworkId: 204,
TxLookupLimit: 2350000,
TransactionHistory: 2350000,
StateHistory: params.FullImmutabilityThreshold,
Expand All @@ -70,7 +94,7 @@ var Defaults = Config{
TrieCleanCache: 154,
TrieDirtyCache: 256,
TrieTimeout: 60 * time.Minute,
TrieCommitInterval: 0,
TrieCommitInterval: 3600,
SnapshotCache: 102,
FilterLogCacheSize: 32,
Miner: miner.DefaultConfig,
Expand All @@ -80,6 +104,7 @@ var Defaults = Config{
RPCEVMTimeout: 5 * time.Second,
GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether
Preimages: true,
EnableOpcodeOptimizing: false,
}

Expand Down
26 changes: 26 additions & 0 deletions node/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ var DefaultConfig = Config{
DBEngine: "", // Use whatever exists, will default to Pebble if non-existent and supported
}

// DefaultOpBNBConfig contains reasonable default opBNB settings.
var DefaultOpBNBConfig = Config{
DataDir: DefaultDataDir(),
HTTPHost: DefaultHTTPHost,
HTTPPort: DefaultHTTPPort,
AuthAddr: DefaultAuthHost,
AuthPort: DefaultAuthPort,
AuthVirtualHosts: DefaultAuthVhosts,
HTTPModules: []string{"net", "web3", "engine"},
HTTPVirtualHosts: []string{"localhost"},
HTTPTimeouts: rpc.DefaultHTTPTimeouts,
WSHost: DefaultWSHost,
WSPort: DefaultWSPort,
WSModules: []string{"net", "web3", "engine"},
BatchRequestLimit: 1000,
BatchResponseMaxSize: 25 * 1000 * 1000,
GraphQLVirtualHosts: []string{"localhost"},
P2P: p2p.Config{
ListenAddr: ":30303",
MaxPeers: 10,
NAT: nat.Any(),
},
DBEngine: "", // Use whatever exists, will default to Pebble if non-existent and supported
InsecureUnlockAllowed: true,
}

// DefaultDataDir is the default data directory to use for the databases and other
// persistence requirements.
func DefaultDataDir() string {
Expand Down
Loading