Skip to content

Commit

Permalink
updates with v0.52
Browse files Browse the repository at this point in the history
  • Loading branch information
likesToEatFish committed Oct 20, 2024
1 parent e9e8dd2 commit 7e24538
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
"github.com/cosmos/cosmos-sdk/x/genutil"
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"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"

Expand All @@ -38,7 +36,7 @@ func initRootCmd(
rootCmd.AddCommand(
genutilcli.InitCmd(moduleManager),
NewInPlaceTestnetCmd(),
NewTestnetMultiNodeCmd(basicManager, banktypes.GenesisBalancesIterator{}),
NewTestnetMultiNodeCmd(moduleManager),
debug.Cmd(),
confixcmd.ConfigCommand(),
pruning.Cmd(newApp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@ 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 @@ -64,7 +63,7 @@ type initArgs struct {
}

// NewTestnetMultiNodeCmd returns a cmd to initialize all files for tendermint testnet and application
func NewTestnetMultiNodeCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalancesIterator) *cobra.Command {
func NewTestnetMultiNodeCmd(mbm *module.Manager) *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 @@ -128,7 +127,7 @@ Example:
}
}

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

Expand Down Expand Up @@ -164,8 +163,7 @@ func initTestnetFiles(
clientCtx client.Context,
cmd *cobra.Command,
nodeConfig *cmtconfig.Config,
mbm module.BasicManager,
genBalIterator banktypes.GenesisBalancesIterator,
mbm *module.Manager,
args initArgs,
) error {
if args.chainID == "" {
Expand Down Expand Up @@ -198,15 +196,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)
nodeIDs[i], valPubKeys[i], err = genutil.InitializeNodeValidatorFiles(nodeConfig, ed25519.KeyType)
if err != nil {
_ = os.RemoveAll(args.outputDir)
return err
Expand All @@ -233,7 +231,7 @@ func initTestnetFiles(
return err
}

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

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

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

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

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

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

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

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

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

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

0 comments on commit 7e24538

Please sign in to comment.