Skip to content

Commit

Permalink
Merge pull request ethereum#185 from maticnetwork/krishna/network-flags
Browse files Browse the repository at this point in the history
Network flags
  • Loading branch information
ssandeep authored Oct 6, 2021
2 parents 3283fb9 + cf809b4 commit 7368ca6
Show file tree
Hide file tree
Showing 21 changed files with 384 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2.1.3
with:
go-version: 1.15.5
go-version: 1.16.7
- name: "Build binaries"
run: make all
- name: "Run tests"
Expand Down
4 changes: 4 additions & 0 deletions cmd/devp2p/nodesetcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func ethFilter(args []string) (nodeFilter, error) {
filter = forkid.NewStaticFilter(params.GoerliChainConfig, params.GoerliGenesisHash)
case "ropsten":
filter = forkid.NewStaticFilter(params.RopstenChainConfig, params.RopstenGenesisHash)
case "bor-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
7 changes: 5 additions & 2 deletions cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var (

goerliFlag = flag.Bool("goerli", false, "Initializes the faucet with Görli network config")
rinkebyFlag = flag.Bool("rinkeby", false, "Initializes the faucet with Rinkeby network config")
mumbaiFlag = flag.Bool("bor-mumbai", false, "Initializes the faucet with Bor-Mumbai network config")
)

var (
Expand Down Expand Up @@ -147,7 +148,7 @@ func main() {
log.Crit("Failed to render the faucet template", "err", err)
}
// Load and parse the genesis block requested by the user
genesis, err := getGenesis(genesisFlag, *goerliFlag, *rinkebyFlag)
genesis, err := getGenesis(genesisFlag, *goerliFlag, *rinkebyFlag, *mumbaiFlag)
if err != nil {
log.Crit("Failed to parse genesis config", "err", err)
}
Expand Down Expand Up @@ -886,7 +887,7 @@ func authNoAuth(url string) (string, string, common.Address, error) {
}

// getGenesis returns a genesis based on input args
func getGenesis(genesisFlag *string, goerliFlag bool, rinkebyFlag bool) (*core.Genesis, error) {
func getGenesis(genesisFlag *string, goerliFlag bool, rinkebyFlag bool, mumbaiFlag bool) (*core.Genesis, error) {
switch {
case genesisFlag != nil:
var genesis core.Genesis
Expand All @@ -896,6 +897,8 @@ func getGenesis(genesisFlag *string, goerliFlag bool, rinkebyFlag bool) (*core.G
return core.DefaultGoerliGenesisBlock(), nil
case rinkebyFlag:
return core.DefaultRinkebyGenesisBlock(), nil
case mumbaiFlag:
return core.DefaultMumbaiGenesisBlock(), nil
default:
return nil, fmt.Errorf("no genesis flag provided")
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ It expects the genesis file as argument.`,
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
Expand Down
56 changes: 56 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"math/big"
"os"
"reflect"
"time"
"unicode"

"gopkg.in/urfave/cli.v1"
Expand All @@ -33,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/usbwallet"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/eth/catalyst"
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -133,6 +135,14 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
}
}

if ctx.GlobalIsSet(utils.MumbaiFlag.Name) {
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 @@ -328,3 +338,49 @@ func setAccountManagerBackends(stack *node.Node) error {

return nil
}

func setDefaultMumbaiGethConfig(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.SnapSync
config.Eth.NetworkId = 80001
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'
}

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.SnapSync
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'
}
3 changes: 3 additions & 0 deletions cmd/geth/consolecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ 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) || ctx.GlobalBool(utils.BorMainnetFlag.Name) {
homeDir, _ := os.UserHomeDir()
path = filepath.Join(homeDir, "/.bor/data")
}
}
endpoint = fmt.Sprintf("%s/geth.ipc", path)
Expand Down
16 changes: 16 additions & 0 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Remove blockchain and state databases`,
utils.RopstenFlag,
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 @@ -90,6 +92,8 @@ Remove blockchain and state databases`,
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
}
dbCompactCmd = cli.Command{
Expand All @@ -103,6 +107,8 @@ Remove blockchain and state databases`,
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
utils.CacheFlag,
utils.CacheDatabaseFlag,
},
Expand All @@ -122,6 +128,8 @@ corruption if it is aborted during execution'!`,
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: "This command looks up the specified database key from the database.",
}
Expand All @@ -137,6 +145,8 @@ corruption if it is aborted during execution'!`,
utils.RopstenFlag,
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 @@ -153,6 +163,8 @@ WARNING: This is a low-level operation which may cause database corruption!`,
utils.RopstenFlag,
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 @@ -169,6 +181,8 @@ WARNING: This is a low-level operation which may cause database corruption!`,
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: "This command looks up the specified database key from the database.",
}
Expand All @@ -184,6 +198,8 @@ WARNING: This is a low-level operation which may cause database corruption!`,
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: "This command displays information about the freezer index.",
}
Expand Down
10 changes: 9 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ var (
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
utils.VMEnableDebugFlag,
utils.NetworkIdFlag,
utils.EthStatsURLFlag,
Expand Down Expand Up @@ -282,6 +284,12 @@ func prepare(ctx *cli.Context) {
case ctx.GlobalIsSet(utils.GoerliFlag.Name):
log.Info("Starting Geth on Görli testnet...")

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...")

Expand All @@ -291,7 +299,7 @@ func prepare(ctx *cli.Context) {
// 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) {
// 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.DeveloperFlag.Name) {
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!
log.Info("Bumping default cache on mainnet", "provided", ctx.GlobalInt(utils.CacheFlag.Name), "updated", 4096)
ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(4096))
Expand Down
10 changes: 10 additions & 0 deletions cmd/geth/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ var (
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
utils.CacheTrieJournalFlag,
utils.BloomFilterSizeFlag,
},
Expand Down Expand Up @@ -93,6 +95,8 @@ the trie clean cache with default directory will be deleted.
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: `
geth snapshot verify-state <state-root>
Expand All @@ -113,6 +117,8 @@ In other words, this command does the snapshot to trie conversion.
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: `
geth snapshot traverse-state <state-root>
Expand All @@ -135,6 +141,8 @@ It's also usable without snapshot enabled.
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
},
Description: `
geth snapshot traverse-rawstate <state-root>
Expand All @@ -158,6 +166,8 @@ It's also usable without snapshot enabled.
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
utils.ExcludeCodeFlag,
utils.ExcludeStorageFlag,
utils.StartKeyFlag,
Expand Down
2 changes: 2 additions & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.NetworkIdFlag,
utils.MainnetFlag,
utils.GoerliFlag,
utils.MumbaiFlag,
utils.BorMainnetFlag,
utils.RinkebyFlag,
utils.RopstenFlag,
utils.SyncModeFlag,
Expand Down
Loading

0 comments on commit 7368ca6

Please sign in to comment.