Skip to content

Commit

Permalink
feat: Add multi node (validator) testnet (backport #4377) (#4401)
Browse files Browse the repository at this point in the history
* resolve conflicts

* revert v28
  • Loading branch information
likesToEatFish authored Nov 12, 2024
1 parent e3b9131 commit 212005b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 92 deletions.
14 changes: 2 additions & 12 deletions ignite/cmd/bubblemodel/chain_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,13 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/stretchr/testify/require"

<<<<<<< HEAD:ignite/cmd/model/chain_debug_test.go
cmdmodel "github.com/ignite/cli/v28/ignite/cmd/model"
"github.com/ignite/cli/v28/ignite/cmd/model/testdata"
cmdmodel "github.com/ignite/cli/v28/ignite/cmd/bubblemodel"
"github.com/ignite/cli/v28/ignite/cmd/bubblemodel/testdata"
"github.com/ignite/cli/v28/ignite/pkg/cliui/colors"
"github.com/ignite/cli/v28/ignite/pkg/cliui/icons"
cliuimodel "github.com/ignite/cli/v28/ignite/pkg/cliui/model"
"github.com/ignite/cli/v28/ignite/pkg/errors"
"github.com/ignite/cli/v28/ignite/pkg/events"
=======
cmdmodel "github.com/ignite/cli/v29/ignite/cmd/bubblemodel"
"github.com/ignite/cli/v29/ignite/cmd/bubblemodel/testdata"
"github.com/ignite/cli/v29/ignite/pkg/cliui/colors"
"github.com/ignite/cli/v29/ignite/pkg/cliui/icons"
cliuimodel "github.com/ignite/cli/v29/ignite/pkg/cliui/model"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/events"
>>>>>>> b7e3ab3c (feat: Add multi node (validator) testnet (#4377)):ignite/cmd/bubblemodel/chain_debug_test.go
)

func TestChainDebugErrorView(t *testing.T) {
Expand Down
14 changes: 2 additions & 12 deletions ignite/cmd/bubblemodel/chain_serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,13 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/stretchr/testify/require"

<<<<<<< HEAD:ignite/cmd/model/chain_serve_test.go
cmdmodel "github.com/ignite/cli/v28/ignite/cmd/model"
"github.com/ignite/cli/v28/ignite/cmd/model/testdata"
cmdmodel "github.com/ignite/cli/v28/ignite/cmd/bubblemodel"
"github.com/ignite/cli/v28/ignite/cmd/bubblemodel/testdata"
"github.com/ignite/cli/v28/ignite/pkg/cliui/colors"
"github.com/ignite/cli/v28/ignite/pkg/cliui/icons"
cliuimodel "github.com/ignite/cli/v28/ignite/pkg/cliui/model"
"github.com/ignite/cli/v28/ignite/pkg/errors"
"github.com/ignite/cli/v28/ignite/pkg/events"
=======
cmdmodel "github.com/ignite/cli/v29/ignite/cmd/bubblemodel"
"github.com/ignite/cli/v29/ignite/cmd/bubblemodel/testdata"
"github.com/ignite/cli/v29/ignite/pkg/cliui/colors"
"github.com/ignite/cli/v29/ignite/pkg/cliui/icons"
cliuimodel "github.com/ignite/cli/v29/ignite/pkg/cliui/model"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/events"
>>>>>>> b7e3ab3c (feat: Add multi node (validator) testnet (#4377)):ignite/cmd/bubblemodel/chain_serve_test.go
)

var chainServeActions = colors.Faint("Press the 'q' key to stop serve")
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/bubblemodel/testnet_multi_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/charmbracelet/lipgloss"
"golang.org/x/sync/errgroup"

"github.com/ignite/cli/v29/ignite/services/chain"
"github.com/ignite/cli/v28/ignite/services/chain"
)

// NodeStatus is an integer data type that represents the status of a node.
Expand Down
16 changes: 1 addition & 15 deletions ignite/cmd/chain_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"

<<<<<<< HEAD
cmdmodel "github.com/ignite/cli/v28/ignite/cmd/model"
cmdmodel "github.com/ignite/cli/v28/ignite/cmd/bubblemodel"
chainconfig "github.com/ignite/cli/v28/ignite/config/chain"
"github.com/ignite/cli/v28/ignite/pkg/chaincmd"
"github.com/ignite/cli/v28/ignite/pkg/cliui"
Expand All @@ -19,19 +18,6 @@ import (
"github.com/ignite/cli/v28/ignite/pkg/events"
"github.com/ignite/cli/v28/ignite/pkg/xurl"
"github.com/ignite/cli/v28/ignite/services/chain"
=======
cmdmodel "github.com/ignite/cli/v29/ignite/cmd/bubblemodel"
chainconfig "github.com/ignite/cli/v29/ignite/config/chain"
"github.com/ignite/cli/v29/ignite/pkg/chaincmd"
"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/pkg/cliui/icons"
cliuimodel "github.com/ignite/cli/v29/ignite/pkg/cliui/model"
"github.com/ignite/cli/v29/ignite/pkg/debugger"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/events"
"github.com/ignite/cli/v29/ignite/pkg/xurl"
"github.com/ignite/cli/v29/ignite/services/chain"
>>>>>>> b7e3ab3c (feat: Add multi node (validator) testnet (#4377))
)

const (
Expand Down
12 changes: 1 addition & 11 deletions ignite/cmd/chain_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,13 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/spf13/cobra"

<<<<<<< HEAD
cmdmodel "github.com/ignite/cli/v28/ignite/cmd/model"
cmdmodel "github.com/ignite/cli/v28/ignite/cmd/bubblemodel"
"github.com/ignite/cli/v28/ignite/pkg/cliui"
uilog "github.com/ignite/cli/v28/ignite/pkg/cliui/log"
cliuimodel "github.com/ignite/cli/v28/ignite/pkg/cliui/model"
"github.com/ignite/cli/v28/ignite/pkg/errors"
"github.com/ignite/cli/v28/ignite/pkg/events"
"github.com/ignite/cli/v28/ignite/services/chain"
=======
cmdmodel "github.com/ignite/cli/v29/ignite/cmd/bubblemodel"
"github.com/ignite/cli/v29/ignite/pkg/cliui"
uilog "github.com/ignite/cli/v29/ignite/pkg/cliui/log"
cliuimodel "github.com/ignite/cli/v29/ignite/pkg/cliui/model"
"github.com/ignite/cli/v29/ignite/pkg/errors"
"github.com/ignite/cli/v29/ignite/pkg/events"
"github.com/ignite/cli/v29/ignite/services/chain"
>>>>>>> b7e3ab3c (feat: Add multi node (validator) testnet (#4377))
)

const (
Expand Down
14 changes: 7 additions & 7 deletions ignite/cmd/testnet_multi_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"

cmdmodel "github.com/ignite/cli/v29/ignite/cmd/bubblemodel"
igcfg "github.com/ignite/cli/v29/ignite/config"
v1 "github.com/ignite/cli/v29/ignite/config/chain/v1"
"github.com/ignite/cli/v29/ignite/pkg/availableport"
"github.com/ignite/cli/v29/ignite/pkg/cliui"
"github.com/ignite/cli/v29/ignite/pkg/xfilepath"
"github.com/ignite/cli/v29/ignite/services/chain"
cmdmodel "github.com/ignite/cli/v28/ignite/cmd/bubblemodel"
igcfg "github.com/ignite/cli/v28/ignite/config"
v1 "github.com/ignite/cli/v28/ignite/config/chain/v1"
"github.com/ignite/cli/v28/ignite/pkg/availableport"
"github.com/ignite/cli/v28/ignite/pkg/cliui"
"github.com/ignite/cli/v28/ignite/pkg/xfilepath"
"github.com/ignite/cli/v28/ignite/services/chain"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/types/module"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
"github.com/spf13/cobra"
Expand All @@ -34,14 +35,9 @@ func initRootCmd(
basicManager module.BasicManager,
) {
rootCmd.AddCommand(
<<<<<<< HEAD
genutilcli.InitCmd(basicManager, app.DefaultNodeHome),
NewInPlaceTestnetCmd(addModuleInitFlags),
=======
genutilcli.InitCmd(moduleManager),
NewInPlaceTestnetCmd(),
NewTestnetMultiNodeCmd(moduleManager),
>>>>>>> b7e3ab3c (feat: Add multi node (validator) testnet (#4377))
NewTestnetMultiNodeCmd(basicManager, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
confixcmd.ConfigCommand(),
pruning.Cmd(newApp, app.DefaultNodeHome),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,24 @@ import (
"github.com/spf13/pflag"

"cosmossdk.io/math"
banktypes "cosmossdk.io/x/bank/types"
stakingtypes "cosmossdk.io/x/staking/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/server"
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

runtime "github.com/cosmos/cosmos-sdk/runtime"
)

var (
Expand Down Expand Up @@ -63,7 +64,7 @@ type initArgs struct {
}

// NewTestnetMultiNodeCmd returns a cmd to initialize all files for tendermint testnet and application
func NewTestnetMultiNodeCmd(mbm *module.Manager) *cobra.Command {
func NewTestnetMultiNodeCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command {
cmd := &cobra.Command{
Use: "multi-node",
Short: "Initialize config directories & files for a multi-validator testnet running locally via separate processes (e.g. Docker Compose or similar)",
Expand Down Expand Up @@ -127,7 +128,7 @@ Example:
}
}

return initTestnetFiles(clientCtx, cmd, config, mbm, args)
return initTestnetFiles(clientCtx, cmd, config, mbm, genBalIterator, args)
},
}

Expand Down Expand Up @@ -163,7 +164,8 @@ func initTestnetFiles(
clientCtx client.Context,
cmd *cobra.Command,
nodeConfig *cmtconfig.Config,
mbm *module.Manager,
mbm module.BasicManager,
genBalIterator banktypes.GenesisBalancesIterator,
args initArgs,
) error {
if args.chainID == "" {
Expand Down Expand Up @@ -196,15 +198,15 @@ func initTestnetFiles(

nodeConfig.SetRoot(nodeDir)
nodeConfig.Moniker = nodeDirName
nodeConfig.RPC.ListenAddress = "tcp://0.0.0.0:" + args.ports[i]
nodeConfig.RPC.ListenAddress = "tcp://0.0.0.0:" + args.ports[i]

var err error
if err := os.MkdirAll(filepath.Join(nodeDir, "config"), nodeDirPerm); err != nil {
_ = os.RemoveAll(args.outputDir)
return err
}

nodeIDs[i], valPubKeys[i], err = genutil.InitializeNodeValidatorFiles(nodeConfig, ed25519.KeyType)
nodeIDs[i], valPubKeys[i], err = genutil.InitializeNodeValidatorFiles(nodeConfig)
if err != nil {
_ = os.RemoveAll(args.outputDir)
return err
Expand All @@ -231,7 +233,7 @@ func initTestnetFiles(
return err
}

addr, secret, err := testutil.GenerateSaveCoinKey(kb, nodeDirName, "", true, algo, sdk.GetFullBIP44Path())
addr, secret, err := testutil.GenerateSaveCoinKey(kb, nodeDirName, "", true, algo)
if err != nil {
_ = os.RemoveAll(args.outputDir)
return err
Expand Down Expand Up @@ -291,7 +293,7 @@ func initTestnetFiles(
WithKeybase(kb).
WithTxConfig(clientCtx.TxConfig)

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

Expand All @@ -307,10 +309,7 @@ func initTestnetFiles(

appConfig.GRPC.Address = args.startingIPAddress + ":" + strconv.Itoa(9090-2*i)
appConfig.API.Address = "tcp://localhost:" + strconv.Itoa(1317-i)
err = srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config", "app.toml"), appConfig)
if err != nil {
return err
}
srvconfig.WriteConfigFile(filepath.Join(nodeDir, "config", "app.toml"), appConfig)
}

if err := initGenFiles(clientCtx, mbm, args.chainID, genAccounts, genBalances, genFiles, args.numValidators); err != nil {
Expand All @@ -327,15 +326,13 @@ func initTestnetFiles(
if err != nil || yes {
continue
}
_, err = copyFile(file, gentxsDir)
if err != nil {
return err
}

copyFile(file, gentxsDir)
}
}
err := collectGenFiles(
clientCtx, nodeConfig, nodeIDs, valPubKeys,
genBalIterator,
clientCtx.TxConfig.SigningContext().ValidatorAddressCodec(),
persistentPeers, args,
)
if err != nil {
Expand All @@ -359,11 +356,11 @@ func writeFile(file, dir string, contents []byte) error {
}

func initGenFiles(
clientCtx client.Context, mbm *module.Manager, chainID string,
clientCtx client.Context, mbm module.BasicManager, chainID string,
genAccounts []authtypes.GenesisAccount, genBalances []banktypes.Balance,
genFiles []string, numValidators int,
) error {
appGenState := mbm.DefaultGenesis()
appGenState := mbm.DefaultGenesis(clientCtx.Codec)

// set the accounts in the genesis state
var authGenState authtypes.GenesisState
Expand All @@ -381,10 +378,7 @@ func initGenFiles(
var bankGenState banktypes.GenesisState
clientCtx.Codec.MustUnmarshalJSON(appGenState[banktypes.ModuleName], &bankGenState)

bankGenState.Balances, err = banktypes.SanitizeGenesisBalances(genBalances, clientCtx.AddressCodec)
if err != nil {
return err
}
bankGenState.Balances = banktypes.SanitizeGenesisBalances(genBalances)
for _, bal := range bankGenState.Balances {
bankGenState.Supply = bankGenState.Supply.Add(bal.Coins...)
}
Expand Down Expand Up @@ -413,7 +407,8 @@ func initGenFiles(
func collectGenFiles(
clientCtx client.Context, nodeConfig *cmtconfig.Config,
nodeIDs []string, valPubKeys []cryptotypes.PubKey,
persistentPeers string,
genBalIterator banktypes.GenesisBalancesIterator,
valAddrCodec runtime.ValidatorAddressCodec, persistentPeers string,
args initArgs,
) error {
chainID := args.chainID
Expand All @@ -440,8 +435,8 @@ func collectGenFiles(
return err
}

nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.Codec, clientCtx.TxConfig, nodeConfig, initCfg, appGenesis, genutiltypes.DefaultMessageValidator,
clientCtx.ValidatorAddressCodec, clientCtx.AddressCodec)
nodeAppState, err := genutil.GenAppStateFromConfig(clientCtx.Codec, clientCtx.TxConfig, nodeConfig, initCfg, appGenesis, genBalIterator, genutiltypes.DefaultMessageValidator,
valAddrCodec)
if err != nil {
return err
}
Expand Down

0 comments on commit 212005b

Please sign in to comment.