From 2b8fc1bab969dce2dbf58f02f3eabe5a58a32914 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 26 Sep 2023 14:57:23 +0200 Subject: [PATCH 1/5] remove sdk.Context from init and export genesis --- types/module/core_module.go | 7 ++++--- types/module/module.go | 8 ++++---- x/auth/keeper/genesis.go | 6 ++++-- x/auth/module.go | 4 ++-- x/authz/keeper/genesis.go | 8 +++++--- x/authz/module/module.go | 5 ++--- x/bank/module.go | 4 ++-- x/circuit/module.go | 5 ++--- x/crisis/keeper/genesis.go | 7 ++++--- x/crisis/keeper/keeper.go | 7 ++++--- x/crisis/module.go | 5 ++--- x/distribution/keeper/genesis.go | 5 +++-- x/distribution/module.go | 4 ++-- x/evidence/genesis.go | 6 +++--- x/evidence/module.go | 5 ++--- x/feegrant/module/module.go | 4 ++-- x/gov/genesis.go | 5 +++-- x/gov/module.go | 4 ++-- x/mint/keeper/genesis.go | 7 ++++--- x/mint/module.go | 5 ++--- x/nft/keeper/genesis.go | 7 +++---- x/nft/module/module.go | 5 ++--- x/slashing/keeper/genesis.go | 6 ++++-- x/slashing/module.go | 5 ++--- x/staking/keeper/genesis.go | 2 +- x/staking/module.go | 4 ++-- x/upgrade/module.go | 5 ++--- 27 files changed, 74 insertions(+), 71 deletions(-) diff --git a/types/module/core_module.go b/types/module/core_module.go index 1060edde4357..3289846d204e 100644 --- a/types/module/core_module.go +++ b/types/module/core_module.go @@ -1,6 +1,7 @@ package module import ( + "context" "encoding/json" abci "github.com/cometbft/cometbft/abci/types" @@ -82,9 +83,9 @@ func (c coreAppModuleBasicAdaptor) ValidateGenesis(cdc codec.JSONCodec, txConfig } // ExportGenesis implements HasGenesis -func (c coreAppModuleBasicAdaptor) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (c coreAppModuleBasicAdaptor) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { if module, ok := c.module.(appmodule.HasGenesis); ok { - ctx := ctx.WithGasMeter(storetypes.NewInfiniteGasMeter()) // avoid race conditions + ctx := sdk.UnwrapSDKContext(ctx).WithGasMeter(storetypes.NewInfiniteGasMeter()) // avoid race conditions target := genesis.RawJSONTarget{} err := module.ExportGenesis(ctx, target.Target()) if err != nil { @@ -107,7 +108,7 @@ func (c coreAppModuleBasicAdaptor) ExportGenesis(ctx sdk.Context, cdc codec.JSON } // InitGenesis implements HasGenesis -func (c coreAppModuleBasicAdaptor) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate { +func (c coreAppModuleBasicAdaptor) InitGenesis(ctx context.Context, cdc codec.JSONCodec, bz json.RawMessage) []abci.ValidatorUpdate { if module, ok := c.module.(appmodule.HasGenesis); ok { // core API genesis source, err := genesis.SourceFromRawJSON(bz) diff --git a/types/module/module.go b/types/module/module.go index 615efc001773..3d869a9157fe 100644 --- a/types/module/module.go +++ b/types/module/module.go @@ -184,15 +184,15 @@ func (bm BasicManager) AddQueryCommands(rootQueryCmd *cobra.Command) { // HasGenesis is the extension interface for stateful genesis methods. type HasGenesis interface { HasGenesisBasics - InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) - ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage + InitGenesis(context.Context, codec.JSONCodec, json.RawMessage) + ExportGenesis(context.Context, codec.JSONCodec) json.RawMessage } // HasABCIGenesis is the extension interface for stateful genesis methods which returns validator updates. type HasABCIGenesis interface { HasGenesisBasics - InitGenesis(sdk.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate - ExportGenesis(sdk.Context, codec.JSONCodec) json.RawMessage + InitGenesis(context.Context, codec.JSONCodec, json.RawMessage) []abci.ValidatorUpdate + ExportGenesis(context.Context, codec.JSONCodec) json.RawMessage } // AppModule is the form for an application module. Most of diff --git a/x/auth/keeper/genesis.go b/x/auth/keeper/genesis.go index 555e9f3566de..25047cf8e5d0 100644 --- a/x/auth/keeper/genesis.go +++ b/x/auth/keeper/genesis.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -9,7 +11,7 @@ import ( // // CONTRACT: old coins from the FeeCollectionKeeper need to be transferred through // a genesis port script to the new fee collector account -func (ak AccountKeeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { +func (ak AccountKeeper) InitGenesis(ctx context.Context, data types.GenesisState) { if err := ak.Params.Set(ctx, data.Params); err != nil { panic(err) } @@ -35,7 +37,7 @@ func (ak AccountKeeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { } // ExportGenesis returns a GenesisState for a given context and keeper -func (ak AccountKeeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { +func (ak AccountKeeper) ExportGenesis(ctx context.Context) *types.GenesisState { params := ak.GetParams(ctx) var genAccounts types.GenesisAccounts diff --git a/x/auth/module.go b/x/auth/module.go index e4a183eab5b3..b19deb714797 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -130,7 +130,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the auth module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.accountKeeper.InitGenesis(ctx, genesisState) @@ -138,7 +138,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the auth // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs := am.accountKeeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } diff --git a/x/authz/keeper/genesis.go b/x/authz/keeper/genesis.go index a1e5a9acd90d..d364399312ad 100644 --- a/x/authz/keeper/genesis.go +++ b/x/authz/keeper/genesis.go @@ -1,13 +1,15 @@ package keeper import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/authz" ) // InitGenesis initializes new authz genesis -func (k Keeper) InitGenesis(ctx sdk.Context, data *authz.GenesisState) { - now := ctx.HeaderInfo().Time +func (k Keeper) InitGenesis(ctx context.Context, data *authz.GenesisState) { + now := sdk.UnwrapSDKContext(ctx).HeaderInfo().Time for _, entry := range data.Authorization { // ignore expired authorizations if entry.Expiration != nil && entry.Expiration.Before(now) { @@ -36,7 +38,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *authz.GenesisState) { } // ExportGenesis returns a GenesisState for a given context. -func (k Keeper) ExportGenesis(ctx sdk.Context) *authz.GenesisState { +func (k Keeper) ExportGenesis(ctx context.Context) *authz.GenesisState { var entries []authz.GrantAuthorization k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant authz.Grant) bool { entries = append(entries, authz.GrantAuthorization{ diff --git a/x/authz/module/module.go b/x/authz/module/module.go index bba3d561d8ac..f6379853bf78 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -19,7 +19,6 @@ import ( sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/authz" @@ -128,7 +127,7 @@ func (am AppModule) IsAppModule() {} // InitGenesis performs genesis initialization for the authz module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { var genesisState authz.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.keeper.InitGenesis(ctx, &genesisState) @@ -136,7 +135,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the authz // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } diff --git a/x/bank/module.go b/x/bank/module.go index ce9823559914..071897763279 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -143,7 +143,7 @@ func (AppModule) QuerierRoute() string { return types.RouterKey } // InitGenesis performs genesis initialization for the bank module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { start := time.Now() var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) @@ -154,7 +154,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the bank // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } diff --git a/x/circuit/module.go b/x/circuit/module.go index ddfc6449c3c3..39ff742190e6 100644 --- a/x/circuit/module.go +++ b/x/circuit/module.go @@ -24,7 +24,6 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/telemetry" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -117,7 +116,7 @@ func (AppModule) ConsensusVersion() uint64 { return ConsensusVersion } // InitGenesis performs genesis initialization for the circuit module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { start := time.Now() var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) @@ -128,7 +127,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the circuit // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } diff --git a/x/crisis/keeper/genesis.go b/x/crisis/keeper/genesis.go index e68dc05d5872..b2bd54af50df 100644 --- a/x/crisis/keeper/genesis.go +++ b/x/crisis/keeper/genesis.go @@ -1,19 +1,20 @@ package keeper import ( - sdk "github.com/cosmos/cosmos-sdk/types" + "context" + "github.com/cosmos/cosmos-sdk/x/crisis/types" ) // new crisis genesis -func (k *Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) { +func (k *Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) { if err := k.ConstantFee.Set(ctx, data.ConstantFee); err != nil { panic(err) } } // ExportGenesis returns a GenesisState for a given context and keeper. -func (k *Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { +func (k *Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { constantFee, err := k.ConstantFee.Get(ctx) if err != nil { panic(err) diff --git a/x/crisis/keeper/keeper.go b/x/crisis/keeper/keeper.go index edf66124301b..64cfc3b8d013 100644 --- a/x/crisis/keeper/keeper.go +++ b/x/crisis/keeper/keeper.go @@ -95,16 +95,17 @@ func (k *Keeper) Invariants() []sdk.Invariant { // AssertInvariants asserts all registered invariants. If any invariant fails, // the method panics. -func (k *Keeper) AssertInvariants(ctx sdk.Context) { +func (k *Keeper) AssertInvariants(ctx context.Context) { logger := k.Logger(ctx) start := time.Now() invarRoutes := k.Routes() n := len(invarRoutes) + sdkCtx := sdk.UnwrapSDKContext(ctx) for i, ir := range invarRoutes { logger.Info("asserting crisis invariants", "inv", fmt.Sprint(i+1, "/", n), "name", ir.FullRoute()) - invCtx, _ := ctx.CacheContext() + invCtx, _ := sdkCtx.CacheContext() if res, stop := ir.Invar(invCtx); stop { // TODO: Include app name as part of context to allow for this to be // variable. @@ -115,7 +116,7 @@ func (k *Keeper) AssertInvariants(ctx sdk.Context) { } diff := time.Since(start) - logger.Info("asserted all invariants", "duration", diff, "height", ctx.BlockHeight()) + logger.Info("asserted all invariants", "duration", diff, "height", sdkCtx.BlockHeight()) } // InvCheckPeriod returns the invariant checks period. diff --git a/x/crisis/module.go b/x/crisis/module.go index d6308f1018d8..30665fdc5c49 100644 --- a/x/crisis/module.go +++ b/x/crisis/module.go @@ -22,7 +22,6 @@ import ( "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/telemetry" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/crisis/client/cli" @@ -139,7 +138,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the crisis module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { start := time.Now() var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) @@ -153,7 +152,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the crisis // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } diff --git a/x/distribution/keeper/genesis.go b/x/distribution/keeper/genesis.go index da6b4a89b51f..dccb9d15bd3c 100644 --- a/x/distribution/keeper/genesis.go +++ b/x/distribution/keeper/genesis.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "fmt" "cosmossdk.io/collections" @@ -10,7 +11,7 @@ import ( ) // InitGenesis sets distribution information for genesis -func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { +func (k Keeper) InitGenesis(ctx context.Context, data types.GenesisState) { var moduleHoldings sdk.DecCoins err := k.FeePool.Set(ctx, data.FeePool) @@ -146,7 +147,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { } // ExportGenesis returns a GenesisState for a given context and keeper. -func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { +func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { feePool, err := k.FeePool.Get(ctx) if err != nil { panic(err) diff --git a/x/distribution/module.go b/x/distribution/module.go index 6552c1fe4468..8f1891a5bcc6 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -147,7 +147,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the distribution module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.keeper.InitGenesis(ctx, genesisState) @@ -155,7 +155,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the distribution // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } diff --git a/x/evidence/genesis.go b/x/evidence/genesis.go index 1c7569415547..3c632607ea4e 100644 --- a/x/evidence/genesis.go +++ b/x/evidence/genesis.go @@ -1,6 +1,7 @@ package evidence import ( + "context" "fmt" "cosmossdk.io/x/evidence/exported" @@ -8,12 +9,11 @@ import ( "cosmossdk.io/x/evidence/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) // InitGenesis initializes the evidence module's state from a provided genesis // state. -func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs *types.GenesisState) { +func InitGenesis(ctx context.Context, k keeper.Keeper, gs *types.GenesisState) { if err := gs.Validate(); err != nil { panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err)) } @@ -34,7 +34,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs *types.GenesisState) { } // ExportGenesis returns the evidence module's exported genesis. -func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { +func ExportGenesis(ctx context.Context, k keeper.Keeper) *types.GenesisState { gs := new(types.GenesisState) err := k.Evidences.Walk(ctx, nil, func(_ []byte, value exported.Evidence) (stop bool, err error) { anyEvi, err := codectypes.NewAnyWithValue(value) diff --git a/x/evidence/module.go b/x/evidence/module.go index 43f65545bc9f..e72a562cee09 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -23,7 +23,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) @@ -136,7 +135,7 @@ func (am AppModule) RegisterServices(registrar grpc.ServiceRegistrar) error { // InitGenesis performs the evidence module's genesis initialization It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, bz json.RawMessage) { var gs types.GenesisState err := cdc.UnmarshalJSON(bz, &gs) if err != nil { @@ -147,7 +146,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.Ra } // ExportGenesis returns the evidence module's exported genesis state as raw JSON bytes. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { return cdc.MustMarshalJSON(ExportGenesis(ctx, am.keeper)) } diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 82103c7a81cd..320812aac29a 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -135,7 +135,7 @@ func (am AppModule) IsAppModule() {} // InitGenesis performs genesis initialization for the feegrant module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, bz json.RawMessage) { var gs feegrant.GenesisState cdc.MustUnmarshalJSON(bz, &gs) @@ -147,7 +147,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, bz json.Ra // ExportGenesis returns the exported genesis state as raw bytes for the feegrant // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs, err := am.keeper.ExportGenesis(ctx) if err != nil { panic(err) diff --git a/x/gov/genesis.go b/x/gov/genesis.go index 0eeebcd72e21..31924f9c2e40 100644 --- a/x/gov/genesis.go +++ b/x/gov/genesis.go @@ -1,6 +1,7 @@ package gov import ( + "context" "fmt" "cosmossdk.io/collections" @@ -12,7 +13,7 @@ import ( ) // InitGenesis - store genesis parameters -func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, data *v1.GenesisState) { +func InitGenesis(ctx context.Context, ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, data *v1.GenesisState) { err := k.ProposalID.Set(ctx, data.StartingProposalId) if err != nil { panic(err) @@ -86,7 +87,7 @@ func InitGenesis(ctx sdk.Context, ak types.AccountKeeper, bk types.BankKeeper, k } // ExportGenesis - output genesis parameters -func ExportGenesis(ctx sdk.Context, k *keeper.Keeper) (*v1.GenesisState, error) { +func ExportGenesis(ctx context.Context, k *keeper.Keeper) (*v1.GenesisState, error) { startingProposalID, err := k.ProposalID.Peek(ctx) if err != nil { return nil, err diff --git a/x/gov/module.go b/x/gov/module.go index f70139e041b7..edf726351492 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -290,7 +290,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the gov module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { var genesisState v1.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.accountKeeper, am.bankKeeper, am.keeper, &genesisState) @@ -298,7 +298,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the gov // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs, err := ExportGenesis(ctx, am.keeper) if err != nil { panic(err) diff --git a/x/mint/keeper/genesis.go b/x/mint/keeper/genesis.go index 4ed6ae1fcdea..abdd91c02df7 100644 --- a/x/mint/keeper/genesis.go +++ b/x/mint/keeper/genesis.go @@ -1,12 +1,13 @@ package keeper import ( - sdk "github.com/cosmos/cosmos-sdk/types" + "context" + "github.com/cosmos/cosmos-sdk/x/mint/types" ) // InitGenesis new mint genesis -func (keeper Keeper) InitGenesis(ctx sdk.Context, ak types.AccountKeeper, data *types.GenesisState) { +func (keeper Keeper) InitGenesis(ctx context.Context, ak types.AccountKeeper, data *types.GenesisState) { if err := keeper.Minter.Set(ctx, data.Minter); err != nil { panic(err) } @@ -19,7 +20,7 @@ func (keeper Keeper) InitGenesis(ctx sdk.Context, ak types.AccountKeeper, data * } // ExportGenesis returns a GenesisState for a given context and keeper. -func (keeper Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { +func (keeper Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { minter, err := keeper.Minter.Get(ctx) if err != nil { panic(err) diff --git a/x/mint/module.go b/x/mint/module.go index 8191d639ffa8..585b7564cc3f 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -15,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -133,7 +132,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the mint module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) @@ -142,7 +141,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the mint // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } diff --git a/x/nft/keeper/genesis.go b/x/nft/keeper/genesis.go index 20631dbbf65b..b0a435dafb44 100644 --- a/x/nft/keeper/genesis.go +++ b/x/nft/keeper/genesis.go @@ -1,16 +1,15 @@ package keeper import ( + "context" "sort" "cosmossdk.io/x/nft" - - sdk "github.com/cosmos/cosmos-sdk/types" ) // InitGenesis initializes the nft module's genesis state from a given // genesis state. -func (k Keeper) InitGenesis(ctx sdk.Context, data *nft.GenesisState) { +func (k Keeper) InitGenesis(ctx context.Context, data *nft.GenesisState) { for _, class := range data.Classes { if err := k.SaveClass(ctx, *class); err != nil { panic(err) @@ -31,7 +30,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data *nft.GenesisState) { } // ExportGenesis returns a GenesisState for a given context. -func (k Keeper) ExportGenesis(ctx sdk.Context) *nft.GenesisState { +func (k Keeper) ExportGenesis(ctx context.Context) *nft.GenesisState { classes := k.GetClasses(ctx) nftMap := make(map[string][]*nft.NFT) for _, class := range classes { diff --git a/x/nft/module/module.go b/x/nft/module/module.go index c1254756f7f6..4595c771863d 100644 --- a/x/nft/module/module.go +++ b/x/nft/module/module.go @@ -22,7 +22,6 @@ import ( sdkclient "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) @@ -120,7 +119,7 @@ func (am AppModule) IsAppModule() {} // InitGenesis performs genesis initialization for the nft module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { var genesisState nft.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.keeper.InitGenesis(ctx, &genesisState) @@ -128,7 +127,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the nft // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } diff --git a/x/slashing/keeper/genesis.go b/x/slashing/keeper/genesis.go index e85e636ca754..47e518ffaffb 100644 --- a/x/slashing/keeper/genesis.go +++ b/x/slashing/keeper/genesis.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -8,7 +10,7 @@ import ( // InitGenesis initializes default parameters and the keeper's address to // pubkey map. -func (keeper Keeper) InitGenesis(ctx sdk.Context, stakingKeeper types.StakingKeeper, data *types.GenesisState) { +func (keeper Keeper) InitGenesis(ctx context.Context, stakingKeeper types.StakingKeeper, data *types.GenesisState) { err := stakingKeeper.IterateValidators(ctx, func(index int64, validator stakingtypes.ValidatorI) bool { consPk, err := validator.ConsPubKey() @@ -59,7 +61,7 @@ func (keeper Keeper) InitGenesis(ctx sdk.Context, stakingKeeper types.StakingKee // ExportGenesis writes the current store values // to a genesis file, which can be imported again // with InitGenesis -func (keeper Keeper) ExportGenesis(ctx sdk.Context) (data *types.GenesisState) { +func (keeper Keeper) ExportGenesis(ctx context.Context) (data *types.GenesisState) { params, err := keeper.Params.Get(ctx) if err != nil { panic(err) diff --git a/x/slashing/module.go b/x/slashing/module.go index ffed8a8c22a6..5e71ec0d33b6 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -16,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -145,7 +144,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { // InitGenesis performs genesis initialization for the slashing module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.keeper.InitGenesis(ctx, am.stakingKeeper, &genesisState) @@ -153,7 +152,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the slashing // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } diff --git a/x/staking/keeper/genesis.go b/x/staking/keeper/genesis.go index 149d606ea232..567d3b0c1aa9 100644 --- a/x/staking/keeper/genesis.go +++ b/x/staking/keeper/genesis.go @@ -212,7 +212,7 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) (res // ExportGenesis returns a GenesisState for a given context and keeper. The // GenesisState will contain the pool, params, validators, and bonds found in // the keeper. -func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { +func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState { var unbondingDelegations []types.UnbondingDelegation err := k.UnbondingDelegations.Walk( diff --git a/x/staking/module.go b/x/staking/module.go index 15d573506ef5..8c1cea7f69d2 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -152,7 +152,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } // InitGenesis performs genesis initialization for the staking module. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) @@ -162,7 +162,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the staking // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { return cdc.MustMarshalJSON(am.keeper.ExportGenesis(ctx)) } diff --git a/x/upgrade/module.go b/x/upgrade/module.go index 8bb8b0230f82..80775a8a0aa8 100644 --- a/x/upgrade/module.go +++ b/x/upgrade/module.go @@ -25,7 +25,6 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -116,7 +115,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } // InitGenesis is ignored, no sense in serializing future upgrades -func (am AppModule) InitGenesis(ctx sdk.Context, _ codec.JSONCodec, _ json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, _ codec.JSONCodec, _ json.RawMessage) { // set version map automatically if available if versionMap := am.keeper.GetInitVersionMap(); versionMap != nil { // chains can still use a custom init chainer for setting the version map @@ -150,7 +149,7 @@ func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConf } // ExportGenesis is always empty, as InitGenesis does nothing either -func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(_ context.Context, cdc codec.JSONCodec) json.RawMessage { return am.DefaultGenesis(cdc) } From ec13789b9b5dd44cec3b7463edec4e6c7ede3749 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 26 Sep 2023 14:59:26 +0200 Subject: [PATCH 2/5] fully remove it --- x/genutil/genesis.go | 5 +++-- x/genutil/gentx.go | 3 ++- x/genutil/module.go | 6 +++--- x/group/keeper/genesis.go | 35 ++++++++++++++++++++--------------- x/group/module/module.go | 4 ++-- 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/x/genutil/genesis.go b/x/genutil/genesis.go index 0f8f7d4867f2..64d55293485b 100644 --- a/x/genutil/genesis.go +++ b/x/genutil/genesis.go @@ -1,18 +1,19 @@ package genutil import ( + "context" + abci "github.com/cometbft/cometbft/abci/types" "cosmossdk.io/core/genesis" "github.com/cosmos/cosmos-sdk/client" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/genutil/types" ) // InitGenesis - initialize accounts and deliver genesis transactions func InitGenesis( - ctx sdk.Context, stakingKeeper types.StakingKeeper, + ctx context.Context, stakingKeeper types.StakingKeeper, deliverTx genesis.TxHandler, genesisState types.GenesisState, txEncodingConfig client.TxEncodingConfig, ) (validators []abci.ValidatorUpdate, err error) { diff --git a/x/genutil/gentx.go b/x/genutil/gentx.go index 6b969145fbc8..b0e162c977d8 100644 --- a/x/genutil/gentx.go +++ b/x/genutil/gentx.go @@ -1,6 +1,7 @@ package genutil import ( + "context" "encoding/json" "fmt" "strings" @@ -90,7 +91,7 @@ func ValidateAccountInGenesis( // invokes the provided deliverTxfn with the decoded Tx. It returns the result // of the staking module's ApplyAndReturnValidatorSetUpdates. func DeliverGenTxs( - ctx sdk.Context, genTxs []json.RawMessage, + ctx context.Context, genTxs []json.RawMessage, stakingKeeper types.StakingKeeper, deliverTx genesis.TxHandler, txEncodingConfig client.TxEncodingConfig, ) ([]abci.ValidatorUpdate, error) { diff --git a/x/genutil/module.go b/x/genutil/module.go index 5d3337ba24ab..4959c8692f62 100644 --- a/x/genutil/module.go +++ b/x/genutil/module.go @@ -1,6 +1,7 @@ package genutil import ( + "context" "encoding/json" "fmt" @@ -15,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/genutil/types" ) @@ -100,7 +100,7 @@ func (AppModule) IsOnePerModuleType() {} func (AppModule) IsAppModule() {} // InitGenesis performs genesis initialization for the genutil module. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) validators, err := InitGenesis(ctx, am.stakingKeeper, am.deliverTx, genesisState, am.txEncodingConfig) @@ -112,7 +112,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json. // ExportGenesis returns the exported genesis state as raw bytes for the genutil // module. -func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(_ context.Context, cdc codec.JSONCodec) json.RawMessage { return am.DefaultGenesis(cdc) } diff --git a/x/group/keeper/genesis.go b/x/group/keeper/genesis.go index 457fd461f7da..61e983df2034 100644 --- a/x/group/keeper/genesis.go +++ b/x/group/keeper/genesis.go @@ -1,6 +1,7 @@ package keeper import ( + "context" "encoding/json" abci "github.com/cometbft/cometbft/abci/types" @@ -8,36 +9,38 @@ import ( "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/group" ) // InitGenesis initializes the group module's genesis state. -func (k Keeper) InitGenesis(ctx types.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { +func (k Keeper) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { var genesisState group.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) - if err := k.groupTable.Import(ctx.KVStore(k.key), genesisState.Groups, genesisState.GroupSeq); err != nil { + sdkCtx := sdk.UnwrapSDKContext(ctx) + + if err := k.groupTable.Import(sdkCtx.KVStore(k.key), genesisState.Groups, genesisState.GroupSeq); err != nil { panic(errors.Wrap(err, "groups")) } - if err := k.groupMemberTable.Import(ctx.KVStore(k.key), genesisState.GroupMembers, 0); err != nil { + if err := k.groupMemberTable.Import(sdkCtx.KVStore(k.key), genesisState.GroupMembers, 0); err != nil { panic(errors.Wrap(err, "group members")) } - if err := k.groupPolicyTable.Import(ctx.KVStore(k.key), genesisState.GroupPolicies, 0); err != nil { + if err := k.groupPolicyTable.Import(sdkCtx.KVStore(k.key), genesisState.GroupPolicies, 0); err != nil { panic(errors.Wrap(err, "group policies")) } - if err := k.groupPolicySeq.InitVal(ctx.KVStore(k.key), genesisState.GroupPolicySeq); err != nil { + if err := k.groupPolicySeq.InitVal(sdkCtx.KVStore(k.key), genesisState.GroupPolicySeq); err != nil { panic(errors.Wrap(err, "group policy account seq")) } - if err := k.proposalTable.Import(ctx.KVStore(k.key), genesisState.Proposals, genesisState.ProposalSeq); err != nil { + if err := k.proposalTable.Import(sdkCtx.KVStore(k.key), genesisState.Proposals, genesisState.ProposalSeq); err != nil { panic(errors.Wrap(err, "proposals")) } - if err := k.voteTable.Import(ctx.KVStore(k.key), genesisState.Votes, 0); err != nil { + if err := k.voteTable.Import(sdkCtx.KVStore(k.key), genesisState.Votes, 0); err != nil { panic(errors.Wrap(err, "votes")) } @@ -45,12 +48,14 @@ func (k Keeper) InitGenesis(ctx types.Context, cdc codec.JSONCodec, data json.Ra } // ExportGenesis returns the group module's exported genesis. -func (k Keeper) ExportGenesis(ctx types.Context, _ codec.JSONCodec) *group.GenesisState { +func (k Keeper) ExportGenesis(ctx context.Context, _ codec.JSONCodec) *group.GenesisState { genesisState := group.NewGenesisState() var groups []*group.GroupInfo - groupSeq, err := k.groupTable.Export(ctx.KVStore(k.key), &groups) + sdkCtx := sdk.UnwrapSDKContext(ctx) + + groupSeq, err := k.groupTable.Export(sdkCtx.KVStore(k.key), &groups) if err != nil { panic(errors.Wrap(err, "groups")) } @@ -58,22 +63,22 @@ func (k Keeper) ExportGenesis(ctx types.Context, _ codec.JSONCodec) *group.Genes genesisState.GroupSeq = groupSeq var groupMembers []*group.GroupMember - _, err = k.groupMemberTable.Export(ctx.KVStore(k.key), &groupMembers) + _, err = k.groupMemberTable.Export(sdkCtx.KVStore(k.key), &groupMembers) if err != nil { panic(errors.Wrap(err, "group members")) } genesisState.GroupMembers = groupMembers var groupPolicies []*group.GroupPolicyInfo - _, err = k.groupPolicyTable.Export(ctx.KVStore(k.key), &groupPolicies) + _, err = k.groupPolicyTable.Export(sdkCtx.KVStore(k.key), &groupPolicies) if err != nil { panic(errors.Wrap(err, "group policies")) } genesisState.GroupPolicies = groupPolicies - genesisState.GroupPolicySeq = k.groupPolicySeq.CurVal(ctx.KVStore(k.key)) + genesisState.GroupPolicySeq = k.groupPolicySeq.CurVal(sdkCtx.KVStore(k.key)) var proposals []*group.Proposal - proposalSeq, err := k.proposalTable.Export(ctx.KVStore(k.key), &proposals) + proposalSeq, err := k.proposalTable.Export(sdkCtx.KVStore(k.key), &proposals) if err != nil { panic(errors.Wrap(err, "proposals")) } @@ -81,7 +86,7 @@ func (k Keeper) ExportGenesis(ctx types.Context, _ codec.JSONCodec) *group.Genes genesisState.ProposalSeq = proposalSeq var votes []*group.Vote - _, err = k.voteTable.Export(ctx.KVStore(k.key), &votes) + _, err = k.voteTable.Export(sdkCtx.KVStore(k.key), &votes) if err != nil { panic(errors.Wrap(err, "votes")) } diff --git a/x/group/module/module.go b/x/group/module/module.go index 889d22ab1787..19b44c6050a7 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -120,13 +120,13 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { // InitGenesis performs genesis initialization for the group module. It returns // no validator updates. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) { +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { am.keeper.InitGenesis(ctx, cdc, data) } // ExportGenesis returns the exported genesis state as raw bytes for the group // module. -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { gs := am.keeper.ExportGenesis(ctx, cdc) return cdc.MustMarshalJSON(gs) } From fe01f8bdb35b1bd08398a4d3e007963188817086 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 26 Sep 2023 15:37:07 +0200 Subject: [PATCH 3/5] mocks --- baseapp/testutil/mock/mocks.go | 93 +++++++++++++++++++++++++++ testutil/mock/types_mock_appmodule.go | 8 +-- testutil/mock/types_module_module.go | 12 ++-- 3 files changed, 103 insertions(+), 10 deletions(-) diff --git a/baseapp/testutil/mock/mocks.go b/baseapp/testutil/mock/mocks.go index ec48c87b493e..bf6359cec639 100644 --- a/baseapp/testutil/mock/mocks.go +++ b/baseapp/testutil/mock/mocks.go @@ -140,3 +140,96 @@ func (mr *MockProposalTxVerifierMockRecorder) ProcessProposalVerifyTx(txBz inter mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcessProposalVerifyTx", reflect.TypeOf((*MockProposalTxVerifier)(nil).ProcessProposalVerifyTx), txBz) } + +// TxDecode mocks base method. +func (m *MockProposalTxVerifier) TxDecode(txBz []byte) (types.Tx, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TxDecode", txBz) + ret0, _ := ret[0].(types.Tx) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// TxDecode indicates an expected call of TxDecode. +func (mr *MockProposalTxVerifierMockRecorder) TxDecode(txBz interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TxDecode", reflect.TypeOf((*MockProposalTxVerifier)(nil).TxDecode), txBz) +} + +// TxEncode mocks base method. +func (m *MockProposalTxVerifier) TxEncode(tx types.Tx) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TxEncode", tx) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// TxEncode indicates an expected call of TxEncode. +func (mr *MockProposalTxVerifierMockRecorder) TxEncode(tx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TxEncode", reflect.TypeOf((*MockProposalTxVerifier)(nil).TxEncode), tx) +} + +// MockTxSelector is a mock of TxSelector interface. +type MockTxSelector struct { + ctrl *gomock.Controller + recorder *MockTxSelectorMockRecorder +} + +// MockTxSelectorMockRecorder is the mock recorder for MockTxSelector. +type MockTxSelectorMockRecorder struct { + mock *MockTxSelector +} + +// NewMockTxSelector creates a new mock instance. +func NewMockTxSelector(ctrl *gomock.Controller) *MockTxSelector { + mock := &MockTxSelector{ctrl: ctrl} + mock.recorder = &MockTxSelectorMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockTxSelector) EXPECT() *MockTxSelectorMockRecorder { + return m.recorder +} + +// Clear mocks base method. +func (m *MockTxSelector) Clear() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Clear") +} + +// Clear indicates an expected call of Clear. +func (mr *MockTxSelectorMockRecorder) Clear() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Clear", reflect.TypeOf((*MockTxSelector)(nil).Clear)) +} + +// SelectTxForProposal mocks base method. +func (m *MockTxSelector) SelectTxForProposal(maxTxBytes, maxBlockGas uint64, memTx types.Tx, txBz []byte) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SelectTxForProposal", maxTxBytes, maxBlockGas, memTx, txBz) + ret0, _ := ret[0].(bool) + return ret0 +} + +// SelectTxForProposal indicates an expected call of SelectTxForProposal. +func (mr *MockTxSelectorMockRecorder) SelectTxForProposal(maxTxBytes, maxBlockGas, memTx, txBz interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectTxForProposal", reflect.TypeOf((*MockTxSelector)(nil).SelectTxForProposal), maxTxBytes, maxBlockGas, memTx, txBz) +} + +// SelectedTxs mocks base method. +func (m *MockTxSelector) SelectedTxs() [][]byte { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SelectedTxs") + ret0, _ := ret[0].([][]byte) + return ret0 +} + +// SelectedTxs indicates an expected call of SelectedTxs. +func (mr *MockTxSelectorMockRecorder) SelectedTxs() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SelectedTxs", reflect.TypeOf((*MockTxSelector)(nil).SelectedTxs)) +} diff --git a/testutil/mock/types_mock_appmodule.go b/testutil/mock/types_mock_appmodule.go index 48cc6f49a35a..8d3af82f5c27 100644 --- a/testutil/mock/types_mock_appmodule.go +++ b/testutil/mock/types_mock_appmodule.go @@ -87,7 +87,7 @@ func (mr *MockAppModuleWithAllExtensionsMockRecorder) EndBlock(arg0 interface{}) } // ExportGenesis mocks base method. -func (m *MockAppModuleWithAllExtensions) ExportGenesis(arg0 types1.Context, arg1 codec.JSONCodec) json.RawMessage { +func (m *MockAppModuleWithAllExtensions) ExportGenesis(arg0 context.Context, arg1 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) ret0, _ := ret[0].(json.RawMessage) @@ -101,7 +101,7 @@ func (mr *MockAppModuleWithAllExtensionsMockRecorder) ExportGenesis(arg0, arg1 i } // InitGenesis mocks base method. -func (m *MockAppModuleWithAllExtensions) InitGenesis(arg0 types1.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) { +func (m *MockAppModuleWithAllExtensions) InitGenesis(arg0 context.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) { m.ctrl.T.Helper() m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) } @@ -267,7 +267,7 @@ func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) EndBlock(arg0 interfac } // ExportGenesis mocks base method. -func (m *MockAppModuleWithAllExtensionsABCI) ExportGenesis(arg0 types1.Context, arg1 codec.JSONCodec) json.RawMessage { +func (m *MockAppModuleWithAllExtensionsABCI) ExportGenesis(arg0 context.Context, arg1 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) ret0, _ := ret[0].(json.RawMessage) @@ -281,7 +281,7 @@ func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) ExportGenesis(arg0, ar } // InitGenesis mocks base method. -func (m *MockAppModuleWithAllExtensionsABCI) InitGenesis(arg0 types1.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types.ValidatorUpdate { +func (m *MockAppModuleWithAllExtensionsABCI) InitGenesis(arg0 context.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types.ValidatorUpdate { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) ret0, _ := ret[0].([]types.ValidatorUpdate) diff --git a/testutil/mock/types_module_module.go b/testutil/mock/types_module_module.go index 186cd4d7ca7f..b299af134d7d 100644 --- a/testutil/mock/types_module_module.go +++ b/testutil/mock/types_module_module.go @@ -218,7 +218,7 @@ func (mr *MockHasGenesisMockRecorder) DefaultGenesis(arg0 interface{}) *gomock.C } // ExportGenesis mocks base method. -func (m *MockHasGenesis) ExportGenesis(arg0 types1.Context, arg1 codec.JSONCodec) json.RawMessage { +func (m *MockHasGenesis) ExportGenesis(arg0 context.Context, arg1 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) ret0, _ := ret[0].(json.RawMessage) @@ -232,7 +232,7 @@ func (mr *MockHasGenesisMockRecorder) ExportGenesis(arg0, arg1 interface{}) *gom } // InitGenesis mocks base method. -func (m *MockHasGenesis) InitGenesis(arg0 types1.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) { +func (m *MockHasGenesis) InitGenesis(arg0 context.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) { m.ctrl.T.Helper() m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) } @@ -295,7 +295,7 @@ func (mr *MockHasABCIGenesisMockRecorder) DefaultGenesis(arg0 interface{}) *gomo } // ExportGenesis mocks base method. -func (m *MockHasABCIGenesis) ExportGenesis(arg0 types1.Context, arg1 codec.JSONCodec) json.RawMessage { +func (m *MockHasABCIGenesis) ExportGenesis(arg0 context.Context, arg1 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) ret0, _ := ret[0].(json.RawMessage) @@ -309,7 +309,7 @@ func (mr *MockHasABCIGenesisMockRecorder) ExportGenesis(arg0, arg1 interface{}) } // InitGenesis mocks base method. -func (m *MockHasABCIGenesis) InitGenesis(arg0 types1.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types.ValidatorUpdate { +func (m *MockHasABCIGenesis) InitGenesis(arg0 context.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types.ValidatorUpdate { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) ret0, _ := ret[0].([]types.ValidatorUpdate) @@ -642,7 +642,7 @@ func (mr *MockgenesisOnlyModuleMockRecorder) DefaultGenesis(arg0 interface{}) *g } // ExportGenesis mocks base method. -func (m *MockgenesisOnlyModule) ExportGenesis(arg0 types1.Context, arg1 codec.JSONCodec) json.RawMessage { +func (m *MockgenesisOnlyModule) ExportGenesis(arg0 context.Context, arg1 codec.JSONCodec) json.RawMessage { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ExportGenesis", arg0, arg1) ret0, _ := ret[0].(json.RawMessage) @@ -656,7 +656,7 @@ func (mr *MockgenesisOnlyModuleMockRecorder) ExportGenesis(arg0, arg1 interface{ } // InitGenesis mocks base method. -func (m *MockgenesisOnlyModule) InitGenesis(arg0 types1.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types.ValidatorUpdate { +func (m *MockgenesisOnlyModule) InitGenesis(arg0 context.Context, arg1 codec.JSONCodec, arg2 json.RawMessage) []types.ValidatorUpdate { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "InitGenesis", arg0, arg1, arg2) ret0, _ := ret[0].([]types.ValidatorUpdate) From 102228a701734722672a4e8738b29d8501fc25f0 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 26 Sep 2023 16:55:31 +0200 Subject: [PATCH 4/5] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aad09aac81b..ab7e313a6028 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -148,6 +148,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (client) [#17746](https://github.com/cosmos/cosmos-sdk/pull/17746) `txEncodeAmino` & `txDecodeAmino` txs via grpc and rest were removed * `RegisterLegacyAmino` was removed from `AppModuleBasic` * (x/staking) [#17655](https://github.com/cosmos/cosmos-sdk/pull/17655) `QueryHistoricalInfo` was adjusted to return `HistoricalRecord` and marked `Hist` as deprecated. +* (types) [#17885](https://github.com/cosmos/cosmos-sdk/pull/17885) `InitGenesis` & `ExportGenesis` now take `context.Context` instead of `sdk.Context` ### CLI Breaking Changes From 3bfac5602a5e81168f177a5f4e67826dc5f01236 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Tue, 26 Sep 2023 17:34:59 +0200 Subject: [PATCH 5/5] add upgrading.md info --- UPGRADING.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/UPGRADING.md b/UPGRADING.md index 792e7f826496..c8d193856187 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -36,6 +36,22 @@ Refer to SimApp `root_v2.go` and `root.go` for an example with an app v2 and a l #### `**all**` +##### Genesis Interface + +All genesis interfaces have been migrated to take context.Context instead of sdk.Context. + +```golang +// InitGenesis performs genesis initialization for the authz module. It returns +// no validator updates. +func (am AppModule) InitGenesis(ctx context.Context, cdc codec.JSONCodec, data json.RawMessage) { +} + +// ExportGenesis returns the exported genesis state as raw bytes for the authz +// module. +func (am AppModule) ExportGenesis(ctx context.Context, cdc codec.JSONCodec) json.RawMessage { +} +``` + ##### Migration to Collections Most of Cosmos SDK modules have migrated to [collections](https://docs.cosmos.network/main/packages/collections).