add custom ip list to cmd (#545)

* add custom ip list to cmd

* fix errs

* fix lint

* change to StringSlice
This commit is contained in:
Daniel Choi 2020-09-25 16:00:49 -07:00 committed by GitHub
parent 712a5bad61
commit 64b18b556f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,6 +50,7 @@ var (
flagStartingIPAddress = "starting-ip-address" flagStartingIPAddress = "starting-ip-address"
flagCoinDenom = "coin-denom" flagCoinDenom = "coin-denom"
flagKeyAlgo = "algo" flagKeyAlgo = "algo"
flagIPAddrs = "ip-addrs"
) )
const nodeDirPerm = 0755 const nodeDirPerm = 0755
@ -78,13 +79,14 @@ Note, strict routability for addresses is turned off in the config file.`,
nodeDaemonHome, _ := cmd.Flags().GetString(flagNodeDaemonHome) nodeDaemonHome, _ := cmd.Flags().GetString(flagNodeDaemonHome)
nodeCLIHome, _ := cmd.Flags().GetString(flagNodeCLIHome) nodeCLIHome, _ := cmd.Flags().GetString(flagNodeCLIHome)
startingIPAddress, _ := cmd.Flags().GetString(flagStartingIPAddress) startingIPAddress, _ := cmd.Flags().GetString(flagStartingIPAddress)
ipAddresses, _ := cmd.Flags().GetStringSlice(flagIPAddrs)
numValidators, _ := cmd.Flags().GetInt(flagNumValidators) numValidators, _ := cmd.Flags().GetInt(flagNumValidators)
coinDenom, _ := cmd.Flags().GetString(flagCoinDenom) coinDenom, _ := cmd.Flags().GetString(flagCoinDenom)
algo, _ := cmd.Flags().GetString(flagKeyAlgo) algo, _ := cmd.Flags().GetString(flagKeyAlgo)
return InitTestnet( return InitTestnet(
cmd, config, cdc, mbm, genAccIterator, outputDir, chainID, coinDenom, minGasPrices, cmd, config, cdc, mbm, genAccIterator, outputDir, chainID, coinDenom, minGasPrices,
nodeDirPrefix, nodeDaemonHome, nodeCLIHome, startingIPAddress, keyringBackend, algo, numValidators, nodeDirPrefix, nodeDaemonHome, nodeCLIHome, startingIPAddress, ipAddresses, keyringBackend, algo, numValidators,
) )
}, },
} }
@ -95,6 +97,7 @@ Note, strict routability for addresses is turned off in the config file.`,
cmd.Flags().String(flagNodeDaemonHome, "ethermintd", "Home directory of the node's daemon configuration") cmd.Flags().String(flagNodeDaemonHome, "ethermintd", "Home directory of the node's daemon configuration")
cmd.Flags().String(flagNodeCLIHome, "ethermintcli", "Home directory of the node's cli configuration") cmd.Flags().String(flagNodeCLIHome, "ethermintcli", "Home directory of the node's cli configuration")
cmd.Flags().String(flagStartingIPAddress, "192.168.0.1", "Starting IP address (192.168.0.1 results in persistent peers list ID0@192.168.0.1:46656, ID1@192.168.0.2:46656, ...)") cmd.Flags().String(flagStartingIPAddress, "192.168.0.1", "Starting IP address (192.168.0.1 results in persistent peers list ID0@192.168.0.1:46656, ID1@192.168.0.2:46656, ...)")
cmd.Flags().StringSlice(flagIPAddrs, []string{}, "List of IP addresses to use (i.e. `192.168.0.1,172.168.0.1` results in persistent peers list ID0@192.168.0.1:46656, ID1@172.168.0.1)")
cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created")
cmd.Flags().String(flagCoinDenom, ethermint.AttoPhoton, "Coin denomination used for staking, governance, mint, crisis and evm parameters") cmd.Flags().String(flagCoinDenom, ethermint.AttoPhoton, "Coin denomination used for staking, governance, mint, crisis and evm parameters")
cmd.Flags().String(server.FlagMinGasPrices, fmt.Sprintf("0.000006%s", ethermint.AttoPhoton), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01aphoton,0.001stake)") cmd.Flags().String(server.FlagMinGasPrices, fmt.Sprintf("0.000006%s", ethermint.AttoPhoton), "Minimum gas prices to accept for transactions; All fees in a tx must meet this minimum (e.g. 0.01aphoton,0.001stake)")
@ -117,7 +120,8 @@ func InitTestnet(
nodeDirPrefix, nodeDirPrefix,
nodeDaemonHome, nodeDaemonHome,
nodeCLIHome, nodeCLIHome,
startingIPAddress, startingIPAddress string,
ipAddresses []string,
keyringBackend, keyringBackend,
algo string, algo string,
numValidators int, numValidators int,
@ -135,6 +139,10 @@ func InitTestnet(
return err return err
} }
if len(ipAddresses) != 0 {
numValidators = len(ipAddresses)
}
nodeIDs := make([]string, numValidators) nodeIDs := make([]string, numValidators)
valPubKeys := make([]tmcrypto.PubKey, numValidators) valPubKeys := make([]tmcrypto.PubKey, numValidators)
@ -169,10 +177,16 @@ func InitTestnet(
config.Moniker = nodeDirName config.Moniker = nodeDirName
ip, err := getIP(i, startingIPAddress) var ip string
if err != nil { var err error
_ = os.RemoveAll(outputDir) if len(ipAddresses) == 0 {
return err ip, err = getIP(i, startingIPAddress)
if err != nil {
_ = os.RemoveAll(outputDir)
return err
}
} else {
ip = ipAddresses[i]
} }
nodeIDs[i], valPubKeys[i], err = genutil.InitializeNodeValidatorFiles(config) nodeIDs[i], valPubKeys[i], err = genutil.InitializeNodeValidatorFiles(config)