Skip to content

Commit

Permalink
feat: add opbnb network flags to get genesis and config from code (bn…
Browse files Browse the repository at this point in the history
…b-chain#60)

Co-authored-by: bnoieh <135800952+bnoieh@users.noreply.github.com>
  • Loading branch information
redhdx and bnoieh authored Feb 23, 2024
1 parent 30393bd commit 59977b6
Show file tree
Hide file tree
Showing 7 changed files with 45,102 additions and 10 deletions.
13 changes: 13 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ func prepare(ctx *cli.Context) {
case ctx.IsSet(utils.OPNetworkFlag.Name):
log.Info("Starting geth on an OP network...", "network", ctx.String(utils.OPNetworkFlag.Name))

case ctx.IsSet(utils.OpBNBMainnetFlag.Name):
log.Info("Starting geth on an opBNB Mainnet network...", "network", ctx.String(utils.OpBNBMainnetFlag.Name))

case ctx.IsSet(utils.OpBNBTestnetFlag.Name):
log.Info("Starting geth on an opBNB Testnet network...", "network", ctx.String(utils.OpBNBTestnetFlag.Name))

case ctx.IsSet(utils.OpBNBQANetFlag.Name):
log.Info("Starting geth on an opBNB QAnet network...", "network", ctx.String(utils.OpBNBQANetFlag.Name))

case !ctx.IsSet(utils.NetworkIdFlag.Name):
log.Info("Starting Geth on Ethereum mainnet...")
}
Expand All @@ -336,6 +345,10 @@ 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))
}
// 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
58 changes: 56 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ var (
Category: flags.EthCategory,
}

OpBNBMainnetFlag = &cli.BoolFlag{
Name: "opBNBMainnet",
Usage: "opBNB mainnet",
Category: flags.EthCategory,
}
OpBNBTestnetFlag = &cli.BoolFlag{
Name: "opBNBTestnet",
Usage: "opBNB Testnet",
Category: flags.EthCategory,
}
OpBNBQANetFlag = &cli.BoolFlag{
Name: "opBNBQAnet",
Usage: "opBNB QANet just for internal test",
Category: flags.EthCategory,
}

// Dev mode
DeveloperFlag = &cli.BoolFlag{
Name: "dev",
Expand Down Expand Up @@ -1036,9 +1052,11 @@ var (
GoerliFlag,
SepoliaFlag,
HoleskyFlag,
OpBNBTestnetFlag,
OpBNBQANetFlag,
}
// NetworkFlags is the flag group of all built-in supported networks.
NetworkFlags = append([]cli.Flag{MainnetFlag, OPNetworkFlag}, TestnetFlags...)
NetworkFlags = append([]cli.Flag{MainnetFlag, OPNetworkFlag, OpBNBMainnetFlag}, TestnetFlags...)

// DatabaseFlags is the flag group of all database flags.
DatabaseFlags = []cli.Flag{
Expand Down Expand Up @@ -1757,7 +1775,7 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
// SetEthConfig applies eth-related command line flags to the config.
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
// Avoid conflicting network flags
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, GoerliFlag, SepoliaFlag, HoleskyFlag, OPNetworkFlag)
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, GoerliFlag, SepoliaFlag, HoleskyFlag, OPNetworkFlag, OpBNBMainnetFlag, OpBNBTestnetFlag, OpBNBQANetFlag)
CheckExclusive(ctx, LightServeFlag, SyncModeFlag, "light")
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer

Expand Down Expand Up @@ -2004,6 +2022,21 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.NetworkId = genesis.Config.ChainID.Uint64()
}
cfg.Genesis = genesis
case ctx.Bool(OpBNBMainnetFlag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 204
}
cfg.Genesis = MakeGenesis(ctx)
case ctx.Bool(OpBNBTestnetFlag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 5611
}
cfg.Genesis = MakeGenesis(ctx)
case ctx.Bool(OpBNBQANetFlag.Name):
if !ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1322
}
cfg.Genesis = MakeGenesis(ctx)
default:
if cfg.NetworkId == 1 {
SetDNSDiscoveryDefaults(cfg, params.MainnetGenesisHash)
Expand Down Expand Up @@ -2270,6 +2303,27 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis {
return genesis
case ctx.Bool(DeveloperFlag.Name):
Fatalf("Developer chains are ephemeral")
case ctx.Bool(OpBNBMainnetFlag.Name):
genesis, err := core.LoadOpBNBGenesis(params.OPBNBMainnetChainID)
if err != nil {
Fatalf("failed to load genesis for opBNB mainnet: %v", err)
}
genesis.Config = params.OPBNBMainNetConfig
return genesis
case ctx.Bool(OpBNBTestnetFlag.Name):
genesis, err := core.LoadOpBNBGenesis(params.OPBNBTestNetChainID)
if err != nil {
Fatalf("failed to load genesis for opBNB testnet: %v", err)
}
genesis.Config = params.OPBNBTestNetConfig
return genesis
case ctx.Bool(OpBNBQANetFlag.Name):
genesis, err := core.LoadOpBNBGenesis(params.OPBNBQANetChainID)
if err != nil {
Fatalf("failed to load genesis for opBNB qanet: %v", err)
}
genesis.Config = params.OPBNBQANetConfig
return genesis
}
return genesis
}
Expand Down
14,474 changes: 14,474 additions & 0 deletions core/assets/mainnet/genesis.json

Large diffs are not rendered by default.

Loading

0 comments on commit 59977b6

Please sign in to comment.