Skip to content

Commit

Permalink
Merge pull request ethereum#192 from maticnetwork/uttam/mainnet
Browse files Browse the repository at this point in the history
Add: Bor mainnet network flag
  • Loading branch information
0xKrishna authored Sep 20, 2021
2 parents 440ffaa + 6c7a9e1 commit 0c4366e
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 8 deletions.
2 changes: 2 additions & 0 deletions cmd/devp2p/nodesetcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ func ethFilter(args []string) (nodeFilter, error) {
filter = forkid.NewStaticFilter(params.RopstenChainConfig, params.RopstenGenesisHash)
case "mumbai":
filter = forkid.NewStaticFilter(params.MumbaiChainConfig, params.MumbaiGenesisHash)
case "bor-mainnet":
filter = forkid.NewStaticFilter(params.BorMainnetChainConfig, params.BorMainnetGenesisHash)
default:
return nil, fmt.Errorf("unknown network %q", args[0])
}
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ It expects the genesis file as argument.`,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
Expand Down
27 changes: 27 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
setDefaultMumbaiGethConfig(ctx, &cfg)
}

if ctx.GlobalIsSet(utils.BorMainnetFlag.Name) {
setDefaultBorMainnetGethConfig(ctx, &cfg)
}

// Apply flags.
utils.SetNodeConfig(ctx, &cfg.Node)
stack, err := node.New(&cfg.Node)
Expand Down Expand Up @@ -357,3 +361,26 @@ func setDefaultMumbaiGethConfig(ctx *cli.Context, config *gethConfig) {
config.Metrics.Enabled = true
// --pprof is enabled in 'internal/debug/flags.go'
}

func setDefaultBorMainnetGethConfig(ctx *cli.Context, config *gethConfig) {
config.Node.P2P.ListenAddr = fmt.Sprintf(":%d", 30303)
config.Node.HTTPHost = "0.0.0.0"
config.Node.HTTPVirtualHosts = []string{"*"}
config.Node.HTTPCors = []string{"*"}
config.Node.HTTPPort = 8545
config.Node.IPCPath = utils.MakeDataDir(ctx) + "/bor.ipc"
config.Node.HTTPModules = []string{"eth", "net", "web3", "txpool", "bor"}
config.Eth.SyncMode = downloader.FullSync
config.Eth.NetworkId = 137
config.Eth.Miner.GasCeil = 20000000
//--miner.gastarget is depreceated, No longed used
config.Eth.TxPool.NoLocals = true
config.Eth.TxPool.AccountSlots = 16
config.Eth.TxPool.GlobalSlots = 131072
config.Eth.TxPool.AccountQueue = 64
config.Eth.TxPool.GlobalQueue = 131072
config.Eth.TxPool.Lifetime = 90 * time.Minute
config.Node.P2P.MaxPeers = 200
config.Metrics.Enabled = true
// --pprof is enabled in 'internal/debug/flags.go'
}
2 changes: 1 addition & 1 deletion cmd/geth/consolecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func remoteConsole(ctx *cli.Context) error {
path = filepath.Join(path, "rinkeby")
} else if ctx.GlobalBool(utils.GoerliFlag.Name) {
path = filepath.Join(path, "goerli")
} else if ctx.GlobalBool(utils.MumbaiFlag.Name) {
} else if ctx.GlobalBool(utils.MumbaiFlag.Name) || ctx.GlobalBool(utils.BorMainnetFlag.Name) {
homeDir, _ := os.UserHomeDir()
path = filepath.Join(homeDir, "/.bor/data")
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Remove blockchain and state databases`,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Usage: "Inspect the storage size for each type of data in the database",
Description: `This commands iterates the entire database. If the optional 'prefix' and 'start' arguments are provided, then the iteration is limited to the given subset of data.`,
Expand All @@ -92,6 +93,7 @@ Remove blockchain and state databases`,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
}
dbCompactCmd = cli.Command{
Expand All @@ -106,6 +108,7 @@ Remove blockchain and state databases`,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
utils.CacheFlag,
utils.CacheDatabaseFlag,
},
Expand All @@ -126,6 +129,7 @@ corruption if it is aborted during execution'!`,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: "This command looks up the specified database key from the database.",
}
Expand All @@ -142,6 +146,7 @@ corruption if it is aborted during execution'!`,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: `This command deletes the specified database key from the database.
WARNING: This is a low-level operation which may cause database corruption!`,
Expand All @@ -159,6 +164,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: `This command sets a given database key to the given value.
WARNING: This is a low-level operation which may cause database corruption!`,
Expand All @@ -176,6 +182,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: "This command looks up the specified database key from the database.",
}
Expand All @@ -192,6 +199,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: "This command displays information about the freezer index.",
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ var (
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
utils.VMEnableDebugFlag,
utils.NetworkIdFlag,
utils.EthStatsURLFlag,
Expand Down Expand Up @@ -286,14 +287,17 @@ func prepare(ctx *cli.Context) {
case ctx.GlobalIsSet(utils.MumbaiFlag.Name):
log.Info("Starting Bor on Mumbai testnet...")

case ctx.GlobalIsSet(utils.BorMainnetFlag.Name):
log.Info("Starting Bor on Bor mainnet...")

case ctx.GlobalIsSet(utils.DeveloperFlag.Name):
log.Info("Starting Geth in ephemeral dev mode...")

case !ctx.GlobalIsSet(utils.NetworkIdFlag.Name):
log.Info("Starting Geth on Ethereum mainnet...")
}
// If we're a full node on mainnet without --cache specified, bump default cache allowance
if ctx.GlobalString(utils.SyncModeFlag.Name) != "light" && !ctx.GlobalIsSet(utils.CacheFlag.Name) && !ctx.GlobalIsSet(utils.NetworkIdFlag.Name) {
if ctx.GlobalString(utils.SyncModeFlag.Name) != "light" && !ctx.GlobalIsSet(utils.CacheFlag.Name) && !ctx.GlobalIsSet(utils.BorMainnetFlag.Name) && !ctx.GlobalIsSet(utils.NetworkIdFlag.Name) {
// Make sure we're not on any supported preconfigured testnet either
if !ctx.GlobalIsSet(utils.RopstenFlag.Name) && !ctx.GlobalIsSet(utils.RinkebyFlag.Name) && !ctx.GlobalIsSet(utils.GoerliFlag.Name) && !ctx.GlobalIsSet(utils.MumbaiFlag.Name) && !ctx.GlobalIsSet(utils.DeveloperFlag.Name) {
// Nope, we're really on mainnet. Bump that cache up!
Expand Down
5 changes: 5 additions & 0 deletions cmd/geth/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var (
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
utils.CacheTrieJournalFlag,
utils.BloomFilterSizeFlag,
},
Expand Down Expand Up @@ -95,6 +96,7 @@ the trie clean cache with default directory will be deleted.
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: `
geth snapshot verify-state <state-root>
Expand All @@ -116,6 +118,7 @@ In other words, this command does the snapshot to trie conversion.
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: `
geth snapshot traverse-state <state-root>
Expand All @@ -139,6 +142,7 @@ It's also usable without snapshot enabled.
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: `
geth snapshot traverse-rawstate <state-root>
Expand All @@ -163,6 +167,7 @@ It's also usable without snapshot enabled.
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
utils.ExcludeCodeFlag,
utils.ExcludeStorageFlag,
utils.StartKeyFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.MainnetFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
utils.RinkebyFlag,
utils.RopstenFlag,
utils.SyncModeFlag,
Expand Down
19 changes: 18 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ var (
Name: "mumbai",
Usage: "Mumbai network: pre-configured proof-of-stake test network",
}
BorMainnetFlag = cli.BoolFlag{
Name: "bor-mainnet",
Usage: "Bor mainnet",
}
DeveloperFlag = cli.BoolFlag{
Name: "dev",
Usage: "Ephemeral proof-of-authority network with a pre-funded developer account, mining enabled",
Expand Down Expand Up @@ -859,6 +863,8 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls = params.GoerliBootnodes
case ctx.GlobalBool(MumbaiFlag.Name):
urls = params.MumbaiBootnodes
case ctx.GlobalBool(BorMainnetFlag.Name):
urls = params.BorMainnetBootnodes
case cfg.BootstrapNodes != nil:
return // already set, don't apply defaults.
}
Expand Down Expand Up @@ -1305,6 +1311,9 @@ func setDataDir(ctx *cli.Context, cfg *node.Config) {
case ctx.GlobalBool(MumbaiFlag.Name) && cfg.DataDir == node.DefaultDataDir():
homeDir, _ := os.UserHomeDir()
cfg.DataDir = filepath.Join(homeDir, "/.bor/data")
case ctx.GlobalBool(BorMainnetFlag.Name) && cfg.DataDir == node.DefaultDataDir():
homeDir, _ := os.UserHomeDir()
cfg.DataDir = filepath.Join(homeDir, "/.bor/data")
}
}

Expand Down Expand Up @@ -1490,7 +1499,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, RopstenFlag, RinkebyFlag, GoerliFlag, MumbaiFlag)
CheckExclusive(ctx, MainnetFlag, DeveloperFlag, RopstenFlag, RinkebyFlag, GoerliFlag, MumbaiFlag, BorMainnetFlag)
CheckExclusive(ctx, LightServeFlag, SyncModeFlag, "light")
CheckExclusive(ctx, DeveloperFlag, ExternalSignerFlag) // Can't use both ephemeral unlocked and external signer
if ctx.GlobalString(GCModeFlag.Name) == "archive" && ctx.GlobalUint64(TxLookupLimitFlag.Name) != 0 {
Expand Down Expand Up @@ -1653,6 +1662,12 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}
cfg.Genesis = core.DefaultMumbaiGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.MumbaiGenesisHash)
case ctx.GlobalBool(BorMainnetFlag.Name):
if !ctx.GlobalIsSet(BorMainnetFlag.Name) {
cfg.NetworkId = 137
}
cfg.Genesis = core.DefaultBorMainnetGenesisBlock()
SetDNSDiscoveryDefaults(cfg, params.BorMainnetGenesisHash)
case ctx.GlobalBool(DeveloperFlag.Name):
if !ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = 1337
Expand Down Expand Up @@ -1875,6 +1890,8 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis {
genesis = core.DefaultGoerliGenesisBlock()
case ctx.GlobalBool(MumbaiFlag.Name):
genesis = core.DefaultMumbaiGenesisBlock()
case ctx.GlobalBool(BorMainnetFlag.Name):
genesis = core.DefaultBorMainnetGenesisBlock()
case ctx.GlobalBool(DeveloperFlag.Name):
Fatalf("Developer chains are ephemeral")
}
Expand Down
35 changes: 35 additions & 0 deletions core/allocs/bor_mainnet.json

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
return params.GoerliChainConfig
case ghash == params.MumbaiGenesisHash:
return params.MumbaiChainConfig
case ghash == params.BorMainnetGenesisHash:
return params.BorMainnetChainConfig
default:
return params.AllEthashProtocolChanges
}
Expand Down Expand Up @@ -417,6 +419,23 @@ func DefaultMumbaiGenesisBlock() *Genesis {
}
}

//DefaultBorMainnet returns the Bor Mainnet network gensis block.
func DefaultBorMainnetGenesisBlock() *Genesis {
return &Genesis{
Config: params.BorMainnetChainConfig,
Nonce: 0x0,
Timestamp: 0x5ED20F84,
GasLimit: 0x989680,
Difficulty: big.NewInt(1),
Mixhash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
Coinbase: common.HexToAddress("0x0000000000000000000000000000000000000000"),
Alloc: readPrealloc("allocs/bor_mainnet.json"),
Number: 0x0,
GasUsed: 0x0,
ParentHash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
}
}

// DeveloperGenesisBlock returns the 'geth --dev' genesis block.
func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis {
// Override the default period to the user requested one
Expand Down
3 changes: 3 additions & 0 deletions internal/debug/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ func Setup(ctx *cli.Context) error {
} else if ctx.GlobalIsSet("mumbai") {
address := fmt.Sprintf("%s:%d", "0.0.0.0", 7071)
StartPProf(address, !ctx.GlobalIsSet("metrics.addr"))
} else if ctx.GlobalIsSet("bor-mainnet") {
address := fmt.Sprintf("%s:%d", "0.0.0.0", 7071)
StartPProf(address, !ctx.GlobalIsSet("metrics.addr"))
}
return nil
}
Expand Down
7 changes: 7 additions & 0 deletions mobile/geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
config.EthereumNetworkID = 5
}
}
// If we have the Bor Mainnet, hard code the chain configs too
if config.EthereumGenesis == BorMainnetGenesis() {
genesis.Config = params.BorMainnetChainConfig
if config.EthereumNetworkID == 1 {
config.EthereumNetworkID = 137
}
}
// If we have the Mumbai testnet, hard code the chain configs too
if config.EthereumGenesis == MumbaiGenesis() {
genesis.Config = params.MumbaiChainConfig
Expand Down
9 changes: 9 additions & 0 deletions mobile/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ func MumbaiGenesis() string {
return string(enc)
}

// BorMainnetGenesis returns the JSON spec to use for the Mumbai test network
func BorMainnetGenesis() string {
enc, err := json.Marshal(core.DefaultBorMainnetGenesisBlock())
if err != nil {
panic(err)
}
return string(enc)
}

// FoundationBootnodes returns the enode URLs of the P2P bootstrap nodes operated
// by the foundation running the V5 discovery protocol.
func FoundationBootnodes() *Enodes {
Expand Down
9 changes: 9 additions & 0 deletions params/bootnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ var MumbaiBootnodes = []string{
"enode://f0f48a8781629f95ff02606081e6e43e4aebd503f3d07fc931fad7dd5ca1ba52bd849a6f6c3be0e375cf13c9ae04d859c4a9ae3546dc8ed4f10aa5dbb47d4998@34.226.134.117:30303",
}

// BorMainnetBootnodes are the enode URLs of the P2P bootstrap nodes running on the
// main Bor network.
var BorMainnetBootnodes = []string{
"enode://0cb82b395094ee4a2915e9714894627de9ed8498fb881cec6db7c65e8b9a5bd7f2f25cc84e71e89d0947e51c76e85d0847de848c7782b13c0255247a6758178c@44.232.55.71:30303",
"enode://88116f4295f5a31538ae409e4d44ad40d22e44ee9342869e7d68bdec55b0f83c1530355ce8b41fbec0928a7d75a5745d528450d30aec92066ab6ba1ee351d710@159.203.9.164:30303",
}

var V5Bootnodes = []string{
// Teku team's bootnode
"enr:-KG4QOtcP9X1FbIMOe17QNMKqDxCpm14jcX5tiOE4_TyMrFqbmhPZHK_ZPG2Gxb1GE2xdtodOfx9-cgvNtxnRyHEmC0ghGV0aDKQ9aX9QgAAAAD__________4JpZIJ2NIJpcIQDE8KdiXNlY3AyNTZrMaEDhpehBDbZjM_L9ek699Y7vhUJ-eAdMyQW_Fil522Y0fODdGNwgiMog3VkcIIjKA",
Expand Down Expand Up @@ -110,6 +117,8 @@ func KnownDNSNetwork(genesis common.Hash, protocol string) string {
net = "goerli"
case MumbaiGenesisHash:
net = "mumbai"
case BorMainnetGenesisHash:
net = "bor-mainnet"
default:
return ""
}
Expand Down
Loading

0 comments on commit 0c4366e

Please sign in to comment.