Skip to content

Commit

Permalink
provider: enable AutoCLI; add missing Tx proto annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Oct 11, 2023
1 parent a12d3dc commit 0ff6c9a
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 81 deletions.
143 changes: 88 additions & 55 deletions app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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,
},
),
})
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion cmd/interchain-security-pd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func NewRootCmd() *cobra.Command {
}

initRootCmd(rootCmd, encodingConfig)

if err := tempApp.AutoCliOpts().EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}
return rootCmd
}

Expand Down
3 changes: 3 additions & 0 deletions proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
52 changes: 27 additions & 25 deletions x/ccv/provider/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0ff6c9a

Please sign in to comment.