From 6677814457975534bbb5253c58b9a84304cb76d1 Mon Sep 17 00:00:00 2001 From: MSalopek Date: Sat, 11 Nov 2023 21:58:35 +0100 Subject: [PATCH] [wip] unjail works; proposal stopped working --- Dockerfile | 2 +- app/provider/app.go | 53 +++++-- cmd/interchain-security-pd/cmd/root.go | 206 +++++++++++++++---------- cmd/interchain-security-sd/cmd/root.go | 7 + tests/e2e/actions.go | 9 +- tests/e2e/steps.go | 2 +- 6 files changed, 181 insertions(+), 98 deletions(-) diff --git a/Dockerfile b/Dockerfile index de183457d0..aeaf114783 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ RUN make install FROM --platform=linux/amd64 ghcr.io/informalsystems/hermes:v1.7.0 AS hermes-builder # Get CometMock -FROM ghcr.io/informalsystems/cometmock:v0.37.x as cometmock-builder +FROM ghcr.io/informalsystems/cometmock:v0.38.0 as cometmock-builder # Get GoRelayer FROM ghcr.io/informalsystems/relayer-no-gas-sim:v2.3.0-rc4-no-gas-sim AS gorelayer-builder diff --git a/app/provider/app.go b/app/provider/app.go index 00c775043e..656e800abc 100644 --- a/app/provider/app.go +++ b/app/provider/app.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - stdlog "log" "os" "path/filepath" @@ -32,6 +31,7 @@ import ( "cosmossdk.io/x/evidence" evidencekeeper "cosmossdk.io/x/evidence/keeper" evidencetypes "cosmossdk.io/x/evidence/types" + "cosmossdk.io/x/tx/signing" "cosmossdk.io/x/upgrade" upgradekeeper "cosmossdk.io/x/upgrade/keeper" upgradetypes "cosmossdk.io/x/upgrade/types" @@ -41,6 +41,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services" @@ -59,6 +60,8 @@ import ( authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" + + txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" @@ -104,6 +107,8 @@ import ( tmos "github.com/cometbft/cometbft/libs/os" dbm "github.com/cosmos/cosmos-db" + sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" + appparams "github.com/cosmos/interchain-security/v3/app/params" testutil "github.com/cosmos/interchain-security/v3/testutil/integration" icsprovider "github.com/cosmos/interchain-security/v3/x/ccv/provider" @@ -113,9 +118,8 @@ import ( ) const ( - AppName = "interchain-security-p" - upgradeName = "ics-v1-to-v2" - AccountAddressPrefix = "cosmos" + AppName = "interchain-security-p" + upgradeName = "ics-v1-to-v2" ) // this line is used by starport scaffolding # stargate/wasm/app/enabledProposals @@ -230,7 +234,7 @@ type App struct { // nolint: golint func init() { userHomeDir, err := os.UserHomeDir() if err != nil { - stdlog.Println("Failed to get home dir %2", err) + panic(fmt.Sprintf("Failed to get home dir %v", err)) } DefaultNodeHome = filepath.Join(userHomeDir, "."+AppName) @@ -245,15 +249,23 @@ func New( appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *App { - encodingConfig := makeEncodingConfig() + interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ + ProtoFiles: proto.HybridResolver, + SigningOptions: signing.Options{ + AddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + }, + ValidatorAddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), + }, + }, + }) + appCodec := codec.NewProtoCodec(interfaceRegistry) + legacyAmino := codec.NewLegacyAmino() + txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes) - interfaceRegistry := encodingConfig.InterfaceRegistry - appCodec := encodingConfig.Codec - legacyAmino := encodingConfig.Amino - txConfig := encodingConfig.TxConfig std.RegisterLegacyAminoCodec(legacyAmino) std.RegisterInterfaces(interfaceRegistry) - // ABCI++, v50 voteExtOp := func(bApp *baseapp.BaseApp) { voteExtHandler := NewVoteExtensionHandler() @@ -560,6 +572,21 @@ func New( ModuleBasics.RegisterLegacyAminoCodec(app.legacyAmino) ModuleBasics.RegisterInterfaces(app.interfaceRegistry) + enabledSignModes := append(authtx.DefaultSignModes, + sigtypes.SignMode_SIGN_MODE_TEXTUAL) + txConfigOpts := authtx.ConfigOptions{ + EnabledSignModes: enabledSignModes, + TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), + } + txConfig, err := authtx.NewTxConfigWithOptions( + appCodec, + txConfigOpts, + ) + if err != nil { + panic(err) + } + app.txConfig = txConfig + app.MM.SetOrderPreBlockers( upgradetypes.ModuleName, ) @@ -638,7 +665,7 @@ func New( app.MM.RegisterInvariants(&app.CrisisKeeper) app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) - err := app.MM.RegisterServices(app.configurator) + err = app.MM.RegisterServices(app.configurator) if err != nil { panic(err) } @@ -699,7 +726,7 @@ func New( HandlerOptions: ante.HandlerOptions{ AccountKeeper: app.AccountKeeper, BankKeeper: app.BankKeeper, - SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), + SignModeHandler: txConfig.SignModeHandler(), SigGasConsumer: ante.DefaultSigVerificationGasConsumer, }, IBCKeeper: app.IBCKeeper, diff --git a/cmd/interchain-security-pd/cmd/root.go b/cmd/interchain-security-pd/cmd/root.go index 780aba17f8..f053e2ea04 100644 --- a/cmd/interchain-security-pd/cmd/root.go +++ b/cmd/interchain-security-pd/cmd/root.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + "cosmossdk.io/client/v2/autocli" confixcmd "cosmossdk.io/tools/confix/cmd" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" @@ -16,19 +17,24 @@ import ( "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/pruning" "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/codec" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" + "github.com/cosmos/cosmos-sdk/x/auth/tx" + txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" "cosmossdk.io/log" - tmcfg "github.com/cometbft/cometbft/config" + cmtcfg "github.com/cometbft/cometbft/config" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/interchain-security/v3/app/params" @@ -39,7 +45,7 @@ import ( // main function. func NewRootCmd() *cobra.Command { // we "pre"-instantiate the application for getting the injected/configured encoding configuration - tempApp := providerApp.New(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(providerApp.DefaultNodeHome)) + tempApp := providerApp.New(log.NewNopLogger(), dbm.NewMemDB(), nil, true, simtestutil.NewAppOptionsWithFlagHome(tempDir())) encodingConfig := params.EncodingConfig{ InterfaceRegistry: tempApp.InterfaceRegistry(), Codec: tempApp.AppCodec(), @@ -50,7 +56,6 @@ func NewRootCmd() *cobra.Command { initClientCtx := client.Context{}. WithCodec(encodingConfig.Codec). WithInterfaceRegistry(encodingConfig.InterfaceRegistry). - WithTxConfig(encodingConfig.TxConfig). WithLegacyAmino(encodingConfig.Amino). WithInput(os.Stdin). WithAccountRetriever(types.AccountRetriever{}). @@ -58,8 +63,9 @@ func NewRootCmd() *cobra.Command { WithViper("") // In simapp, we don't use any prefix for env variables. rootCmd := &cobra.Command{ - Use: "simd", - Short: "simulation app", + Use: "simd", + Short: "simulation app", + SilenceErrors: false, PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { // set the default command outputs cmd.SetOut(cmd.OutOrStdout()) @@ -76,66 +82,78 @@ func NewRootCmd() *cobra.Command { return err } + // This needs to go after ReadFromClientConfig, as that function + // sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode + // is only available if the client is online. + if !initClientCtx.Offline { + txConfigOpts := tx.ConfigOptions{ + EnabledSignModes: append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL), + TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx), + } + txConfigWithTextual, err := tx.NewTxConfigWithOptions( + codec.NewProtoCodec(encodingConfig.InterfaceRegistry), + txConfigOpts, + ) + if err != nil { + return err + } + initClientCtx = initClientCtx.WithTxConfig(txConfigWithTextual) + } + if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { return err } customAppTemplate, customAppConfig := initAppConfig() - customTMConfig := initTendermintConfig() + customCMTConfig := initCometBFTConfig() - return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customTMConfig) + return server.InterceptConfigsPreRunHandler(cmd, customAppTemplate, customAppConfig, customCMTConfig) }, } initRootCmd(rootCmd, encodingConfig) - // autocli opts - autoCliOpts := tempApp.AutoCliOpts() - initClientCtx, _ = config.ReadFromClientConfig(initClientCtx) - autoCliOpts.Keyring, _ = keyring.NewAutoCLIKeyring(initClientCtx.Keyring) - autoCliOpts.ClientCtx = initClientCtx + autoCliOpts, err := enrichAutoCliOpts(tempApp.AutoCliOpts(), initClientCtx) + if err != nil { + panic(err) + } if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil { panic(err) } + return rootCmd } -// initTendermintConfig helps to override default Tendermint Config values. -// return tmcfg.DefaultConfig if no custom configuration is required for the application. -func initTendermintConfig() *tmcfg.Config { - cfg := tmcfg.DefaultConfig() - - // these values put a higher strain on node memory - // cfg.P2P.MaxNumInboundPeers = 100 - // cfg.P2P.MaxNumOutboundPeers = 40 +func enrichAutoCliOpts(autoCliOpts autocli.AppOptions, clientCtx client.Context) (autocli.AppOptions, error) { + autoCliOpts.AddressCodec = addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()) + autoCliOpts.ValidatorAddressCodec = addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()) + autoCliOpts.ConsensusAddressCodec = addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()) - return cfg -} + var err error + clientCtx, err = config.ReadFromClientConfig(clientCtx) + if err != nil { + return autocli.AppOptions{}, err + } -func txCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "tx", - Short: "Transactions subcommands", - DisableFlagParsing: false, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, + autoCliOpts.ClientCtx = clientCtx + autoCliOpts.Keyring, err = keyring.NewAutoCLIKeyring(clientCtx.Keyring) + if err != nil { + return autocli.AppOptions{}, err } - cmd.AddCommand( - authcmd.GetSignCommand(), - authcmd.GetSignBatchCommand(), - authcmd.GetMultiSignCommand(), - authcmd.GetMultiSignBatchCmd(), - authcmd.GetValidateSignaturesCommand(), - authcmd.GetBroadcastCommand(), - authcmd.GetEncodeCommand(), - authcmd.GetDecodeCommand(), - authcmd.GetSimulateCmd(), - ) + return autoCliOpts, nil +} - providerApp.ModuleBasics.AddTxCommands(cmd) +// initCometBFTConfig helps to override default CometBFT Config values. +// return cmtcfg.DefaultConfig if no custom configuration is required for the application. +func initCometBFTConfig() *cmtcfg.Config { + cfg := cmtcfg.DefaultConfig() - return cmd + // these values put a higher strain on node memory + // cfg.P2P.MaxNumInboundPeers = 100 + // cfg.P2P.MaxNumOutboundPeers = 40 + + return cfg } // initAppConfig helps to override default appConfig template and configs. @@ -204,6 +222,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { debug.Cmd(), pruning.Cmd(newApp, providerApp.DefaultNodeHome), confixcmd.ConfigCommand(), + server.QueryBlockResultsCmd(), ) server.AddCommands(rootCmd, providerApp.DefaultNodeHome, newApp, appExport, addModuleInitFlags) @@ -212,12 +231,71 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) { rootCmd.AddCommand( server.StatusCommand(), genesisCommand(encodingConfig), - queryCommand(), txCommand(), + queryCommand(), keys.Commands(), ) } +func addModuleInitFlags(startCmd *cobra.Command) { + crisis.AddModuleInitFlags(startCmd) +} + +func queryCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "query", + Aliases: []string{"q"}, + Short: "Querying subcommands", + DisableFlagParsing: false, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + rpc.ValidatorCommand(), + server.QueryBlockCmd(), + authcmd.QueryTxsByEventsCmd(), + server.QueryBlocksCmd(), + authcmd.QueryTxCmd(), + authcmd.GetSimulateCmd(), + ) + + return cmd +} + +func txCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "tx", + Short: "Transactions subcommands", + DisableFlagParsing: false, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand( + authcmd.GetSignCommand(), + authcmd.GetSignBatchCommand(), + authcmd.GetMultiSignCommand(), + authcmd.GetMultiSignBatchCmd(), + authcmd.GetValidateSignaturesCommand(), + authcmd.GetBroadcastCommand(), + authcmd.GetEncodeCommand(), + authcmd.GetDecodeCommand(), + authcmd.GetSimulateCmd(), + ) + + return cmd +} + +// genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter +func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command) *cobra.Command { + cmd := genutilcli.GenesisCoreCommand(encodingConfig.TxConfig, providerApp.ModuleBasics, providerApp.DefaultNodeHome) + for _, sub_cmd := range cmds { + cmd.AddCommand(sub_cmd) + } + return cmd +} + // newApp is an appCreator // newApp creates the application func newApp( @@ -277,42 +355,12 @@ func appExport( return simApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) } -func addModuleInitFlags(startCmd *cobra.Command) { - crisis.AddModuleInitFlags(startCmd) -} - -// genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter -func genesisCommand(encodingConfig params.EncodingConfig, cmds ...*cobra.Command) *cobra.Command { - cmd := genutilcli.GenesisCoreCommand(encodingConfig.TxConfig, providerApp.ModuleBasics, providerApp.DefaultNodeHome) - for _, sub_cmd := range cmds { - cmd.AddCommand(sub_cmd) +var tempDir = func() string { + dir, err := os.MkdirTemp("", "."+providerApp.AppName) + if err != nil { + dir = providerApp.DefaultNodeHome } - return cmd -} + defer os.RemoveAll(dir) -func queryCommand() *cobra.Command { - cmd := &cobra.Command{ - Use: "query", - Aliases: []string{"q"}, - Short: "Querying subcommands", - DisableFlagParsing: false, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - - cmd.AddCommand( - rpc.ValidatorCommand(), - server.QueryBlockCmd(), - server.QueryBlocksCmd(), - server.QueryBlockResultsCmd(), - authcmd.QueryTxsByEventsCmd(), - authcmd.QueryTxCmd(), - authcmd.GetEncodeCommand(), - authcmd.GetDecodeCommand(), - authcmd.GetSimulateCmd(), - ) - - providerApp.ModuleBasics.AddQueryCommands(cmd) - - return cmd + return dir } diff --git a/cmd/interchain-security-sd/cmd/root.go b/cmd/interchain-security-sd/cmd/root.go index 5d5810eeb1..e052fb625e 100644 --- a/cmd/interchain-security-sd/cmd/root.go +++ b/cmd/interchain-security-sd/cmd/root.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/pruning" "github.com/cosmos/cosmos-sdk/client/rpc" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" serverconfig "github.com/cosmos/cosmos-sdk/server/config" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -86,6 +87,12 @@ func NewRootCmd() *cobra.Command { } initRootCmd(rootCmd, encodingConfig) + // autocli opts + autoCliOpts := tempApp.AutoCliOpts() + initClientCtx, _ = config.ReadFromClientConfig(initClientCtx) + autoCliOpts.Keyring, _ = keyring.NewAutoCLIKeyring(initClientCtx.Keyring) + autoCliOpts.ClientCtx = initClientCtx + if err := tempApp.AutoCliOpts().EnhanceRootCommand(rootCmd); err != nil { panic(err) } diff --git a/tests/e2e/actions.go b/tests/e2e/actions.go index 4f4b74a435..19850fc210 100644 --- a/tests/e2e/actions.go +++ b/tests/e2e/actions.go @@ -1408,7 +1408,8 @@ func (tr TestRun) cancelUnbondTokens( if err != nil { log.Fatal(err, "\n", string(bz)) } - creationHeight := gjson.Get(string(bz), "entries.0.creation_height").Int() + + creationHeight := gjson.Get(string(bz), "unbond.entries.0.creation_height").Int() if creationHeight == 0 { log.Fatal("invalid creation height") } @@ -1600,18 +1601,18 @@ func (tr TestRun) unjailValidator(action unjailValidatorAction, verbose bool) { "tx", "slashing", "unjail", // Validator is sender here `--from`, `validator`+fmt.Sprint(action.validator), + `--keyring-backend`, `test`, + `--keyring-dir`, tr.getValidatorHome(action.provider, action.validator), `--chain-id`, string(tr.chainConfigs[action.provider].chainId), - `--home`, tr.getValidatorHome(action.provider, action.validator), `--node`, tr.getValidatorNode(action.provider, action.validator), `--gas`, "900000", - `--keyring-backend`, `test`, `-y`, ) if verbose { fmt.Println("unjail cmd:", cmd.String()) } - + fmt.Println("unjail cmd:", cmd.String()) bz, err := cmd.CombinedOutput() if err != nil { log.Fatal(err, "\n", string(bz)) diff --git a/tests/e2e/steps.go b/tests/e2e/steps.go index 19f52f800a..9372e88b57 100644 --- a/tests/e2e/steps.go +++ b/tests/e2e/steps.go @@ -16,7 +16,7 @@ func concatSteps(steps ...[]Step) []Step { var happyPathSteps = concatSteps( stepsStartChains([]string{"consu"}, false), stepsDelegate("consu"), - stepsAssignConsumerKeyOnStartedChain("consu", "bob"), + // stepsAssignConsumerKeyOnStartedChain("consu", "bob"), stepsUnbond("consu"), stepsCancelUnbond("consu"), stepsRedelegateForOptOut("consu"),