From 0ff6c9a31a5a73fb057e811101c0418e71bba8a7 Mon Sep 17 00:00:00 2001 From: MSalopek Date: Wed, 11 Oct 2023 20:32:59 +0200 Subject: [PATCH] provider: enable AutoCLI; add missing Tx proto annotations --- app/provider/app.go | 143 +++++++++++------- cmd/interchain-security-pd/cmd/root.go | 4 +- .../ccv/provider/v1/tx.proto | 3 + x/ccv/provider/types/tx.pb.go | 52 ++++--- 4 files changed, 121 insertions(+), 81 deletions(-) diff --git a/app/provider/app.go b/app/provider/app.go index b32a5f9848..28dcd97bf7 100644 --- a/app/provider/app.go +++ b/app/provider/app.go @@ -9,6 +9,7 @@ import ( "path/filepath" "github.com/cosmos/cosmos-sdk/testutil/testdata/testpb" + "github.com/cosmos/gogoproto/proto" "github.com/cosmos/ibc-go/v8/modules/apps/transfer" ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" @@ -26,6 +27,8 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" + "cosmossdk.io/client/v2/autocli" + "cosmossdk.io/core/appmodule" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/evidence" @@ -50,13 +53,13 @@ import ( "github.com/cosmos/cosmos-sdk/std" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/types/msgservice" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" - authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" @@ -276,8 +279,13 @@ func New( providertypes.StoreKey, consensusparamtypes.StoreKey, ) - tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey) + // register streaming services + if err := bApp.RegisterStreamingServices(appOpts, keys); err != nil { + panic(err) + } + + tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) app := &App{ @@ -518,7 +526,7 @@ func New( genutil.NewAppModule( app.AccountKeeper, app.StakingKeeper, - app, // app is the deliverTx handler? + app, txConfig, ), auth.NewAppModule(appCodec, app.AccountKeeper, nil, app.GetSubspace(authtypes.ModuleName)), @@ -548,6 +556,12 @@ func New( govtypes.ModuleName: gov.NewAppModuleBasic( []govclient.ProposalHandler{ paramsclient.ProposalHandler, + ibcclientclient.UpdateClientProposalHandler, + ibcclientclient.UpgradeProposalHandler, + icsproviderclient.ConsumerAdditionProposalHandler, + icsproviderclient.ConsumerRemovalProposalHandler, + icsproviderclient.EquivocationProposalHandler, + icsproviderclient.ChangeRewardDenomsProposalHandler, }, ), }) @@ -631,6 +645,41 @@ func New( panic(err) } + // Note this upgrade handler is just an example and may not be exactly what you need to implement. + // See https://docs.cosmos.network/v0.45/building-modules/upgrade.html + app.UpgradeKeeper.SetUpgradeHandler( + upgradeName, + func(ctx context.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) { + sdkCtx := sdk.UnwrapSDKContext(ctx) + app.IBCKeeper.ConnectionKeeper.SetParams(sdkCtx, ibcconnectiontypes.DefaultParams()) + + fromVM := make(map[string]uint64) + + for moduleName := range app.MM.Modules { + m := app.MM.Modules[moduleName] + if module, ok := m.(module.HasConsensusVersion); ok { + fromVM[moduleName] = module.ConsensusVersion() + } + } + + app.Logger().Info("start to run module migrations...") + + return app.MM.RunMigrations(ctx, app.configurator, fromVM) + }, + ) + + upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + if err != nil { + panic(fmt.Sprintf("failed to read upgrade info from disk %s", err)) + } + + if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + storeUpgrades := storetypes.StoreUpgrades{} + + // configure store loader that checks if version == upgradeHeight and applies store upgrades + app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + } + autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.MM.Modules)) reflectionSvc, err := runtimeservices.NewReflectionService() @@ -641,26 +690,6 @@ func New( // add test gRPC service for testing gRPC queries in isolation testpb.RegisterQueryServer(app.GRPCQueryRouter(), testpb.QueryImpl{}) - // create the simulation manager and define the order of the modules for deterministic simulations - // - // NOTE: this is not required apps that don't use the simulator for fuzz testing - // transactions - app.sm = module.NewSimulationManager( - auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)), - bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)), - capability.NewAppModule(appCodec, *app.CapabilityKeeper, false), - gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)), - mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)), - staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)), - distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName), interfaceRegistry), - params.NewAppModule(app.ParamsKeeper), - evidence.NewAppModule(app.EvidenceKeeper), - ibc.NewAppModule(app.IBCKeeper), - transferModule, - ) - - app.sm.RegisterStoreDecoders() // initialize stores app.MountKVStores(keys) @@ -689,39 +718,17 @@ func New( app.setPostHandler() - // Note this upgrade handler is just an example and may not be exactly what you need to implement. - // See https://docs.cosmos.network/v0.45/building-modules/upgrade.html - app.UpgradeKeeper.SetUpgradeHandler( - upgradeName, - func(ctx context.Context, _ upgradetypes.Plan, _ module.VersionMap) (module.VersionMap, error) { - sdkCtx := sdk.UnwrapSDKContext(ctx) - app.IBCKeeper.ConnectionKeeper.SetParams(sdkCtx, ibcconnectiontypes.DefaultParams()) - - fromVM := make(map[string]uint64) - - for moduleName := range app.MM.Modules { - m := app.MM.Modules[moduleName] - if module, ok := m.(module.HasConsensusVersion); ok { - fromVM[moduleName] = module.ConsensusVersion() - } - } - - app.Logger().Info("start to run module migrations...") - - return app.MM.RunMigrations(ctx, app.configurator, fromVM) - }, - ) - - upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + // At startup, after all modules have been registered, check that all prot + // annotations are correct. + protoFiles, err := proto.MergedRegistry() if err != nil { - panic(fmt.Sprintf("failed to read upgrade info from disk %s", err)) + panic(err) } - - if upgradeInfo.Name == upgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { - storeUpgrades := storetypes.StoreUpgrades{} - - // configure store loader that checks if version == upgradeHeight and applies store upgrades - app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + err = msgservice.ValidateProtoAnnotations(protoFiles) + if err != nil { + // Once we switch to using protoreflect-based antehandlers, we might + // want to panic here instead of logging a warning. + fmt.Fprintln(os.Stderr, err.Error()) } if loadLatest { @@ -750,6 +757,11 @@ func (app *App) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) { return app.MM.EndBlock(ctx) } +// Configurator returns the configurator for the app +func (app *App) Configurator() module.Configurator { + return app.configurator +} + // InitChainer application update at chain initialization func (app *App) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { var genesisState GenesisState @@ -907,6 +919,26 @@ func (app *App) TxConfig() client.TxConfig { return app.txConfig } +// AutoCliOpts returns the autocli options for the app. +func (app *App) AutoCliOpts() autocli.AppOptions { + modules := make(map[string]appmodule.AppModule, 0) + for _, m := range app.MM.Modules { + if moduleWithName, ok := m.(module.HasName); ok { + moduleName := moduleWithName.Name() + if appModule, ok := moduleWithName.(appmodule.AppModule); ok { + modules[moduleName] = appModule + } + } + } + + return autocli.AppOptions{ + Modules: modules, + AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), + ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), + ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), + } +} + // RegisterAPIRoutes registers all application module routes with the provided // API server. func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { @@ -939,7 +971,8 @@ func (app *App) RegisterNodeService(clientCtx client.Context, cfg config.Config) // RegisterTendermintService implements the Application.RegisterTendermintService method. func (app *App) RegisterTendermintService(clientCtx client.Context) { - cmtservice.RegisterTendermintService(clientCtx, app.BaseApp.GRPCQueryRouter(), app.interfaceRegistry, app.Query) + cmtApp := server.NewCometABCIWrapper(app) + cmtservice.RegisterTendermintService(clientCtx, app.BaseApp.GRPCQueryRouter(), app.interfaceRegistry, cmtApp.Query) } // GetMaccPerms returns a copy of the module account permissions diff --git a/cmd/interchain-security-pd/cmd/root.go b/cmd/interchain-security-pd/cmd/root.go index 813911b5cd..177756ae2f 100644 --- a/cmd/interchain-security-pd/cmd/root.go +++ b/cmd/interchain-security-pd/cmd/root.go @@ -86,7 +86,9 @@ func NewRootCmd() *cobra.Command { } initRootCmd(rootCmd, encodingConfig) - + if err := tempApp.AutoCliOpts().EnhanceRootCommand(rootCmd); err != nil { + panic(err) + } return rootCmd } diff --git a/proto/interchain_security/ccv/provider/v1/tx.proto b/proto/interchain_security/ccv/provider/v1/tx.proto index 7d4cce685e..222f75d754 100644 --- a/proto/interchain_security/ccv/provider/v1/tx.proto +++ b/proto/interchain_security/ccv/provider/v1/tx.proto @@ -6,10 +6,13 @@ option go_package = "github.com/cosmos/interchain-security/v3/x/ccv/provider/typ import "google/api/annotations.proto"; import "gogoproto/gogo.proto"; import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; import "google/protobuf/any.proto"; // Msg defines the Msg service. service Msg { + option (cosmos.msg.v1.service) = true; + rpc AssignConsumerKey(MsgAssignConsumerKey) returns (MsgAssignConsumerKeyResponse); } diff --git a/x/ccv/provider/types/tx.pb.go b/x/ccv/provider/types/tx.pb.go index c5bebf0cd5..a0d6397884 100644 --- a/x/ccv/provider/types/tx.pb.go +++ b/x/ccv/provider/types/tx.pb.go @@ -8,6 +8,7 @@ import ( fmt "fmt" _ "github.com/cosmos/cosmos-proto" _ "github.com/cosmos/cosmos-sdk/codec/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" @@ -121,31 +122,32 @@ func init() { } var fileDescriptor_43221a4391e9fbf4 = []byte{ - // 375 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x3d, 0x4f, 0xeb, 0x30, - 0x14, 0x8d, 0x5f, 0xa5, 0xf7, 0xfa, 0xfc, 0xfa, 0x9e, 0xf4, 0xa2, 0x0e, 0x6d, 0x55, 0xa5, 0x10, - 0x16, 0x06, 0x88, 0x55, 0x3a, 0x20, 0x2a, 0x31, 0xb4, 0x4c, 0x08, 0x75, 0xe9, 0x82, 0xc4, 0x12, - 0xa5, 0x8e, 0x71, 0x2d, 0x1a, 0x3b, 0xb2, 0x9d, 0xa8, 0xf9, 0x07, 0x8c, 0x30, 0x21, 0xb6, 0xfe, -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, 0x73, 0x1b, 0x56, 0x70, 0x6e, 0xe1, 0x5e, 0x91, 0xa4, - 0x56, 0x4a, 0x75, 0xff, 0xe0, 0xb5, 0x6d, 0xb7, 0x7c, 0x3d, 0x6b, 0x19, 0x2f, 0xb3, 0x96, 0x61, - 0x5b, 0xb0, 0xb9, 0x29, 0xd8, 0x90, 0xa8, 0x50, 0x70, 0x45, 0x0e, 0xee, 0x01, 0x2c, 0x0d, 0x14, - 0x35, 0x6f, 0x01, 0xfc, 0xff, 0x39, 0xfe, 0x91, 0xf3, 0x85, 0x7f, 0x76, 0x36, 0x19, 0x34, 0x7a, - 0xdf, 0x7e, 0x5a, 0x64, 0xeb, 0x9f, 0x3f, 0x2c, 0x2c, 0x30, 0x5f, 0x58, 0xe0, 0x79, 0x61, 0x81, - 0x9b, 0xa5, 0x65, 0xcc, 0x97, 0x96, 0xf1, 0xb8, 0xb4, 0x8c, 0x8b, 0x63, 0xca, 0xf4, 0x38, 0x1a, - 0x39, 0x58, 0x04, 0xf9, 0x8e, 0xd0, 0xda, 0x6d, 0xff, 0xfd, 0x7c, 0xe2, 0x0e, 0x9a, 0x7e, 0xbc, - 0x21, 0x9d, 0x84, 0x44, 0x8d, 0x7e, 0xa6, 0x5b, 0xeb, 0xbc, 0x05, 0x00, 0x00, 0xff, 0xff, 0x92, - 0xca, 0xcf, 0xe2, 0x74, 0x02, 0x00, 0x00, + // 394 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x52, 0x3d, 0xab, 0x13, 0x41, + 0x14, 0xdd, 0x31, 0xa8, 0x71, 0x8c, 0x82, 0x4b, 0xc0, 0x64, 0x09, 0x1b, 0x5d, 0x1b, 0x11, 0xdd, + 0x21, 0xa6, 0x10, 0x03, 0x16, 0x89, 0x95, 0x48, 0x9a, 0x34, 0x82, 0xcd, 0xb2, 0x99, 0x1d, 0x27, + 0x83, 0xd9, 0x99, 0x65, 0xee, 0xec, 0x92, 0xed, 0x2c, 0x2d, 0xb5, 0xb2, 0xcd, 0x4f, 0xf0, 0x67, + 0x58, 0xa6, 0xb4, 0x12, 0x49, 0x0a, 0xad, 0xfd, 0x05, 0xb2, 0x5f, 0x2f, 0x3c, 0x5e, 0x8a, 0xc7, + 0xeb, 0xe6, 0xdc, 0x73, 0xef, 0x3d, 0x67, 0x38, 0x17, 0x3f, 0x15, 0xd2, 0x30, 0x4d, 0x57, 0xa1, + 0x90, 0x01, 0x30, 0x9a, 0x6a, 0x61, 0x72, 0x42, 0x69, 0x46, 0x12, 0xad, 0x32, 0x11, 0x31, 0x4d, + 0xb2, 0x11, 0x31, 0x1b, 0x3f, 0xd1, 0xca, 0x28, 0xfb, 0xd1, 0x89, 0x6e, 0x9f, 0xd2, 0xcc, 0x6f, + 0xba, 0xfd, 0x6c, 0xe4, 0x0c, 0xb8, 0x52, 0x7c, 0xcd, 0x48, 0x98, 0x08, 0x12, 0x4a, 0xa9, 0x4c, + 0x68, 0x84, 0x92, 0x50, 0xad, 0x70, 0xba, 0x5c, 0x71, 0x55, 0x3e, 0x49, 0xf1, 0xaa, 0xab, 0x7d, + 0xaa, 0x20, 0x56, 0x10, 0x54, 0x44, 0x05, 0x6a, 0xea, 0x7e, 0x85, 0x48, 0x0c, 0xbc, 0xf0, 0x12, + 0x03, 0x6f, 0x66, 0x6a, 0x9d, 0x12, 0x2d, 0xd3, 0x0f, 0x24, 0x94, 0x79, 0x45, 0x79, 0xdf, 0x10, + 0xee, 0xce, 0x81, 0x4f, 0x01, 0x04, 0x97, 0xaf, 0x95, 0x84, 0x34, 0x66, 0xfa, 0x2d, 0xcb, 0xed, + 0x3e, 0x6e, 0x57, 0xee, 0x45, 0xd4, 0x43, 0x0f, 0xd0, 0xe3, 0x5b, 0x8b, 0x9b, 0x25, 0x7e, 0x13, + 0xd9, 0x2f, 0xf0, 0x9d, 0xe6, 0x17, 0x41, 0x18, 0x45, 0xba, 0x77, 0xad, 0xe0, 0x67, 0xf6, 0xbf, + 0x5f, 0xc3, 0xbb, 0x79, 0x18, 0xaf, 0x27, 0x5e, 0x51, 0x65, 0x00, 0xde, 0xa2, 0xd3, 0x34, 0x4e, + 0xa3, 0x48, 0xdb, 0x0f, 0x71, 0x87, 0xd6, 0x12, 0xc1, 0x47, 0x96, 0xf7, 0x5a, 0xe5, 0xde, 0xdb, + 0xf4, 0x28, 0x3b, 0x69, 0x7f, 0xde, 0x0e, 0xad, 0xbf, 0xdb, 0xa1, 0xe5, 0xb9, 0x78, 0x70, 0xca, + 0xd8, 0x82, 0x41, 0xa2, 0x24, 0xb0, 0xe7, 0x5b, 0x84, 0x5b, 0x73, 0xe0, 0xf6, 0x57, 0x84, 0xef, + 0x5d, 0xb4, 0xff, 0xd2, 0xbf, 0x44, 0x00, 0xfe, 0x29, 0x01, 0x67, 0x7a, 0xe5, 0xd1, 0xc6, 0x9b, + 0x73, 0xfd, 0xd3, 0x9f, 0xef, 0x4f, 0xd0, 0xec, 0xdd, 0x8f, 0xbd, 0x8b, 0x76, 0x7b, 0x17, 0xfd, + 0xde, 0xbb, 0xe8, 0xcb, 0xc1, 0xb5, 0x76, 0x07, 0xd7, 0xfa, 0x79, 0x70, 0xad, 0xf7, 0xaf, 0xb8, + 0x30, 0xab, 0x74, 0xe9, 0x53, 0x15, 0xd7, 0x19, 0x92, 0xa3, 0xe8, 0xb3, 0xb3, 0xf3, 0xca, 0xc6, + 0x64, 0x73, 0xfe, 0xc6, 0x4c, 0x9e, 0x30, 0x58, 0xde, 0x28, 0xc3, 0x1b, 0xff, 0x0f, 0x00, 0x00, + 0xff, 0xff, 0x87, 0x60, 0x20, 0xb1, 0x94, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used.