Skip to content

Commit

Permalink
Check if mainnet in a function
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sammy committed Jul 16, 2020
1 parent d74ff3d commit 44a445f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,9 @@ func main() {
}
}

// prepare manipulates memory cache allowance and setups metric system.
// This function should be called before launching devp2p stack.
func prepare(ctx *cli.Context) {
// If we're running a known preset, log it for convenience.
func checkMainnet(ctx *cli.Context) bool {
isMainnet := false

switch {
case ctx.GlobalIsSet(utils.LegacyTestnetFlag.Name):
log.Info("Starting Geth on Ropsten testnet...")
Expand Down Expand Up @@ -333,11 +332,23 @@ func prepare(ctx *cli.Context) {

case !ctx.GlobalIsSet(utils.NetworkIdFlag.Name):
log.Info("Starting Geth on Ethereum mainnet...")
isMainnet = true
}

return isMainnet
}

// prepare manipulates memory cache allowance and setups metric system.
// This function should be called before launching devp2p stack.
func prepare(ctx *cli.Context) {
// If we're running a known preset, log it for convenience.

isMainnet := checkMainnet(ctx)

// 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.LegacyTestnetFlag.Name) && !ctx.GlobalIsSet(utils.RopstenFlag.Name) && !ctx.GlobalIsSet(utils.RinkebyFlag.Name) && !ctx.GlobalIsSet(utils.GoerliFlag.Name) && !ctx.GlobalIsSet(utils.DeveloperFlag.Name) {
if isMainnet {
// 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

0 comments on commit 44a445f

Please sign in to comment.