Skip to content

Commit

Permalink
fix issues with liveness test (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
fragwuerdig authored Mar 19, 2023
1 parent ff2e40b commit b54f04d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
go.sum
- name: start localnet
run: |
make clean localnet-start
TESTNET_NVAL=6 make clean localnet-start
if: env.GIT_DIFF
- name: test liveness
run: |
Expand Down
106 changes: 60 additions & 46 deletions cmd/terrad/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ func InitTestnet(
chainID = "chain-" + tmrand.NewRand().Str(6)
}

nodeIDs := make([]string, numValidators)
valPubKeys := make([]cryptotypes.PubKey, numValidators)
nodeIDs := make([]string, 6)
valPubKeys := make([]cryptotypes.PubKey, 6)

_, appConfig := initAppConfig()
terraappConfig := appConfig.(TerraAppConfig)
Expand All @@ -138,33 +138,41 @@ func InitTestnet(

inBuf := bufio.NewReader(cmd.InOrStdin())
// generate private keys, node IDs, and initial transactions
for i := 0; i < numValidators; i++ {

// can have 6 validators at most
// but need to go through all nodes to initialize config and such
for i := 0; i < 6; i++ {
nodeDirName := fmt.Sprintf("%s%d", nodeDirPrefix, i)
nodeDir := filepath.Join(outputDir, nodeDirName, nodeDaemonHome)
gentxsDir := filepath.Join(outputDir, "gentxs")

nodeConfig.SetRoot(nodeDir)
nodeConfig.RPC.ListenAddress = "tcp://0.0.0.0:26657"


// 1.) create testnet config dirs
if err := os.MkdirAll(filepath.Join(nodeDir, "config"), nodeDirPerm); err != nil {
_ = os.RemoveAll(outputDir)
return err
}

// 2.) set node moniker
nodeConfig.Moniker = nodeDirName

// 3.) get IP for node
ip, err := getIP(i, startingIPAddress)
if err != nil {
_ = os.RemoveAll(outputDir)
return err
}

// 4.) create validator files
nodeIDs[i], valPubKeys[i], err = genutil.InitializeNodeValidatorFiles(nodeConfig)
if err != nil {
_ = os.RemoveAll(outputDir)
return err
}


memo := fmt.Sprintf("%s@%s:26656", nodeIDs[i], ip)
genFiles = append(genFiles, nodeConfig.GenesisFile())

Expand Down Expand Up @@ -196,57 +204,63 @@ func InitTestnet(
if err := writeFile(fmt.Sprintf("%v.json", "key_seed"), nodeDir, cliPrint); err != nil {
return err
}


// create account Tokens for node
accTokens := sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)

// create staking tokens for node
accStakingTokens := sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction)


coins := sdk.Coins{
sdk.NewCoin(fmt.Sprintf("%stoken", nodeDirName), accTokens),
sdk.NewCoin(core.MicroLunaDenom, accStakingTokens),
}

genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()})
genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0))

valTokens := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)
createValMsg, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
sdk.NewCoin(core.MicroLunaDenom, valTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
)
if err != nil {
return err
}

txBuilder := clientCtx.TxConfig.NewTxBuilder()
if err := txBuilder.SetMsgs(createValMsg); err != nil {
return err
}

txBuilder.SetMemo(memo)

txFactory := tx.Factory{}
txFactory = txFactory.
WithChainID(chainID).
WithMemo(memo).
WithKeybase(kb).
WithTxConfig(clientCtx.TxConfig)

if err := tx.Sign(txFactory, nodeDirName, txBuilder, true); err != nil {
return err
}

txBz, err := clientCtx.TxConfig.TxJSONEncoder()(txBuilder.GetTx())
if err != nil {
return err
}

if err := writeFile(fmt.Sprintf("%v.json", nodeDirName), gentxsDir, txBz); err != nil {
return err

// create gentxs only for numValidators
if i < numValidators {
// create the validator for node i
createValMsg, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(addr),
valPubKeys[i],
sdk.NewCoin(core.MicroLunaDenom, valTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
)
if err != nil {
return err
}

// create gentx (create validator) and write to file
txBuilder := clientCtx.TxConfig.NewTxBuilder()
if err := txBuilder.SetMsgs(createValMsg); err != nil {
return err
}
txBuilder.SetMemo(memo)
txFactory := tx.Factory{}
txFactory = txFactory.
WithChainID(chainID).
WithMemo(memo).
WithKeybase(kb).
WithTxConfig(clientCtx.TxConfig)
if err := tx.Sign(txFactory, nodeDirName, txBuilder, true); err != nil {
return err
}
txBz, err := clientCtx.TxConfig.TxJSONEncoder()(txBuilder.GetTx())
if err != nil {
return err
}
if err := writeFile(fmt.Sprintf("%v.json", nodeDirName), gentxsDir, txBz); err != nil {
return err
}
}


// write config file app.toml
srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config/app.toml"), terraappConfig)
}

Expand Down Expand Up @@ -304,7 +318,7 @@ func initGenFiles(
}

// generate empty genesis files for each validator and save
for i := 0; i < numValidators; i++ {
for i := 0; i < 6; i++ {
if err := genDoc.SaveAs(genFiles[i]); err != nil {
return err
}
Expand All @@ -320,7 +334,7 @@ func collectGenFiles(
var appState json.RawMessage
genTime := tmtime.Now()

for i := 0; i < numValidators; i++ {
for i := 0; i < 6; i++ {
nodeDirName := fmt.Sprintf("%s%d", nodeDirPrefix, i)
nodeDir := filepath.Join(outputDir, nodeDirName, nodeDaemonHome)
gentxsDir := filepath.Join(outputDir, "gentxs")
Expand Down

0 comments on commit b54f04d

Please sign in to comment.