diff --git a/CHANGELOG.md b/CHANGELOG.md index 032a3b5a85a5..2880158a22f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (client/keys) [\#9407](https://github.com/cosmos/cosmos-sdk/pull/9601) Added `keys rename` CLI command and `Keyring.Rename` interface method to rename a key in the keyring. * (x/slashing) [\#9458](https://github.com/cosmos/cosmos-sdk/pull/9458) Coins burned from slashing is now returned from Slash function and included in Slash event. * [\#9246](https://github.com/cosmos/cosmos-sdk/pull/9246) The `New` method for the network package now returns an error. -* [\#9519](https://github.com/cosmos/cosmos-sdk/pull/9519) `DeleteDeposits` renamed to `DeleteAndBurnDeposits`, `RefundDeposits` renamed to `RefundAndDeleteDeposits` +* [\#9519](https://github.com/cosmos/cosmos-sdk/pull/9519) `DeleteDeposits` renamed to `DeleteAndBurnDeposits`, `RefundDeposits` renamed to `RefundAndDeleteDeposits` * (codec) [\#9521](https://github.com/cosmos/cosmos-sdk/pull/9521) Removed deprecated `clientCtx.JSONCodec` from `client.Context`. * (codec) [\#9521](https://github.com/cosmos/cosmos-sdk/pull/9521) Rename `EncodingConfig.Marshaler` to `Codec`. * [\#9418](https://github.com/cosmos/cosmos-sdk/pull/9418) `sdk.Msg`'s `GetSigners()` method updated to return `[]string`. @@ -63,7 +63,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#9432](https://github.com/cosmos/cosmos-sdk/pull/9432) `ConsensusParamsKeyTable` moved from `params/keeper` to `params/types` * [\#9576](https://github.com/cosmos/cosmos-sdk/pull/9576) Add debug error message to `sdkerrors.QueryResult` when enabled * [\#9650](https://github.com/cosmos/cosmos-sdk/pull/9650) Removed deprecated message handler implementation from the SDK modules. -* (x/capability) [\#9836](https://github.com/cosmos/cosmos-sdk/pull/9836) Removed `InitializeAndSeal(ctx sdk.Context)` and replaced with `Seal()`. +* (x/capability) [\#9836](https://github.com/cosmos/cosmos-sdk/pull/9836) Removed `InitializeAndSeal(ctx sdk.Context)` and replaced with `Seal()`. App must add x/capability to begin blockers which will assure that the x/capability keeper is properly initialized. The x/capability begin blocker must be run before any other module which uses x/capability. ### Client Breaking Changes diff --git a/x/capability/abci.go b/x/capability/abci.go deleted file mode 100644 index 9d1c94b5b901..000000000000 --- a/x/capability/abci.go +++ /dev/null @@ -1,21 +0,0 @@ -package capability - -import ( - "time" - - "github.com/cosmos/cosmos-sdk/telemetry" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/capability/keeper" - "github.com/cosmos/cosmos-sdk/x/capability/types" -) - -// BeginBlocker will call InitMemStore to initialize the memory stores in the case -// that this is the first time the node is executing a block since restarting (wiping memory). -// In this case, the BeginBlocker method will reinitialize the memory stores locally, so that subsequent -// capability transactions will pass. -// Otherwise BeginBlocker performs a no-op. -func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) - - k.InitMemStore(ctx) -} diff --git a/x/capability/keeper/keeper.go b/x/capability/keeper/keeper.go index 48e0bdfe3184..61df229af9f2 100644 --- a/x/capability/keeper/keeper.go +++ b/x/capability/keeper/keeper.go @@ -99,10 +99,11 @@ func (k *Keeper) Seal() { k.sealed = true } -// InitMemStore will initialize the memory store if the initialized flag is not set. -// InitMemStore logic should be run in first `BeginBlock` or `InitChain` (whichever is run on app start) -// so that the memory store is properly initialized before any transactions are run. -// InitMemStore also asserts the memory store type is correct, and will panic if it does not have store type of `StoreTypeMemory`. +// InitMemStore will assure that the module store is a memory store (it will panic if it's not) +// and willl initialize it. The function is safe to be called multiple times. +// InitMemStore must be called every time the app starts before the keeper is used (so +// `BeginBlock` or `InitChain` - whichever is first). We need access to the store so we +// can't initialize it in a constructor. func (k *Keeper) InitMemStore(ctx sdk.Context) { memStore := ctx.KVStore(k.memKey) memStoreType := memStore.GetStoreType() @@ -137,7 +138,7 @@ func (k *Keeper) InitMemStore(ctx sdk.Context) { } } -// IsInitialized returns true if the initialized flag is set, and false otherwise +// IsInitialized returns true if the keeper is properly initialized, and false otherwise. func (k *Keeper) IsInitialized(ctx sdk.Context) bool { memStore := ctx.KVStore(k.memKey) return memStore.Get(types.KeyMemInitialized) != nil diff --git a/x/capability/module.go b/x/capability/module.go index 5d6e8ffcbb03..f8295948d9b7 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "math/rand" + "time" "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -14,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -143,8 +145,12 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw func (AppModule) ConsensusVersion() uint64 { return 1 } // BeginBlock executes all ABCI BeginBlock logic respective to the capability module. +// BeginBlocker calls InitMemStore to assert that the memory store is initialized. +// It's safe to run multiple times. func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { - BeginBlocker(ctx, am.keeper) + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + + am.keeper.InitMemStore(ctx) } // EndBlock executes all ABCI EndBlock logic respective to the capability module. It