diff --git a/CHANGELOG.md b/CHANGELOG.md index 46d0d14970f6..210c68b144dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [\#9750](https://github.com/cosmos/cosmos-sdk/pull/9750) Emit events for tx signature and sequence, so clients can now query txs by signature (`tx.signature=''`) or by address and sequence combo (`tx.acc_seq='/'`). +### API Breaking Changes + +* (x/capability) [\#9836](https://github.com/cosmos/cosmos-sdk/pull/9836) Removed `InitializeAndSeal(ctx sdk.Context)` and replaced with `Seal()`. + ### Improvements * (cli) [\#9717](https://github.com/cosmos/cosmos-sdk/pull/9717) Added CLI flag `--output json/text` to `tx` cli commands. @@ -56,7 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Client-Breaking Changes -* [\#9785](https://github.com/cosmos/cosmos-sdk/issues/9785) Missing coin denomination in logs +* [\#9785](https://github.com/cosmos/cosmos-sdk/issues/9785) Missing coin denomination in logs ### CLI Breaking Changes diff --git a/x/capability/keeper/keeper.go b/x/capability/keeper/keeper.go index f0b85ca1b6e2..61e65aba1bc4 100644 --- a/x/capability/keeper/keeper.go +++ b/x/capability/keeper/keeper.go @@ -13,14 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/capability/types" ) -// initialized is a global variable used by GetCapability to ensure that the memory store -// and capability map are correctly populated. A state-synced node may copy over all the persistent -// state and start running the application without having the in-memory state required for x/capability. -// Thus, we must initialized the memory stores on-the-fly during tx execution once the first GetCapability -// is called. -// This is a temporary fix and should be replaced by a more robust solution in the next breaking release. -var initialized = false - type ( // Keeper defines the capability module's keeper. It is responsible for provisioning, // tracking, and authenticating capabilities at runtime. During application @@ -107,11 +99,10 @@ func (k *Keeper) Seal() { k.sealed = true } -// 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. +// 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`. func (k *Keeper) InitMemStore(ctx sdk.Context) { memStore := ctx.KVStore(k.memKey) memStoreType := memStore.GetStoreType() @@ -145,7 +136,7 @@ func (k *Keeper) InitMemStore(ctx sdk.Context) { } } -// IsInitialized returns true if the keeper is properly initialized, and false otherwise. +// IsInitialized returns true if the initialized flag is set, and false otherwise func (k *Keeper) IsInitialized(ctx sdk.Context) bool { memStore := ctx.KVStore(k.memKey) return memStore.Get(types.KeyMemInitialized) != nil @@ -370,22 +361,6 @@ func (sk ScopedKeeper) ReleaseCapability(ctx sdk.Context, cap *types.Capability) // by name. The module is not allowed to retrieve capabilities which it does not // own. func (sk ScopedKeeper) GetCapability(ctx sdk.Context, name string) (*types.Capability, bool) { - // Create a keeper that will set all in-memory mappings correctly into memstore and capmap if scoped keeper is not initialized yet. - // This ensures that the in-memory mappings are correctly filled in, in case this is a state-synced node. - // This is a temporary non-breaking fix, a future PR should store the reverse mapping in the persistent store and reconstruct forward mapping and capmap on the fly. - if !initialized { - // create context with infinite gas meter to avoid app state mismatch. - initCtx := ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) - k := Keeper{ - cdc: sk.cdc, - storeKey: sk.storeKey, - memKey: sk.memKey, - capMap: sk.capMap, - } - k.InitializeAndSeal(initCtx) - initialized = true - } - if strings.TrimSpace(name) == "" { return nil, false } diff --git a/x/capability/module.go b/x/capability/module.go index 65d7a92f7c65..5930a00e5ff7 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -141,12 +141,9 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return 1 } -// BeginBlocker calls InitMemStore to assert that the memory store is initialized. -// It's safe to run multiple times. +// BeginBlock executes all ABCI BeginBlock logic respective to the capability module. func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { - defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) - - am.keeper.InitMemStore(ctx) + BeginBlocker(ctx, am.keeper) } // EndBlock executes all ABCI EndBlock logic respective to the capability module. It