Skip to content

Commit bdf5aee

Browse files
style(capability)!: update go doc comments and remove BeginBlocker (cosmos#9845)
## Description + Backported go doc comment updates from cosmos#9835 + Removed BeginBlocker function which only wraps the `InitMemStore` -> https://github.com/cosmos/cosmos-sdk/pull/9835/files#r681987005 -- this is not a breaking change because RC3 was not yet released. + Updated changelog --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
1 parent f27c7ce commit bdf5aee

File tree

4 files changed

+15
-29
lines changed

4 files changed

+15
-29
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
5454
* (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.
5555
* (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.
5656
* [\#9246](https://github.com/cosmos/cosmos-sdk/pull/9246) The `New` method for the network package now returns an error.
57-
* [\#9519](https://github.com/cosmos/cosmos-sdk/pull/9519) `DeleteDeposits` renamed to `DeleteAndBurnDeposits`, `RefundDeposits` renamed to `RefundAndDeleteDeposits`
57+
* [\#9519](https://github.com/cosmos/cosmos-sdk/pull/9519) `DeleteDeposits` renamed to `DeleteAndBurnDeposits`, `RefundDeposits` renamed to `RefundAndDeleteDeposits`
5858
* (codec) [\#9521](https://github.com/cosmos/cosmos-sdk/pull/9521) Removed deprecated `clientCtx.JSONCodec` from `client.Context`.
5959
* (codec) [\#9521](https://github.com/cosmos/cosmos-sdk/pull/9521) Rename `EncodingConfig.Marshaler` to `Codec`.
6060
* [\#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/
6363
* [\#9432](https://github.com/cosmos/cosmos-sdk/pull/9432) `ConsensusParamsKeyTable` moved from `params/keeper` to `params/types`
6464
* [\#9576](https://github.com/cosmos/cosmos-sdk/pull/9576) Add debug error message to `sdkerrors.QueryResult` when enabled
6565
* [\#9650](https://github.com/cosmos/cosmos-sdk/pull/9650) Removed deprecated message handler implementation from the SDK modules.
66-
* (x/capability) [\#9836](https://github.com/cosmos/cosmos-sdk/pull/9836) Removed `InitializeAndSeal(ctx sdk.Context)` and replaced with `Seal()`.
66+
* (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.
6767

6868
### Client Breaking Changes
6969

x/capability/abci.go

-21
This file was deleted.

x/capability/keeper/keeper.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ func (k *Keeper) Seal() {
9999
k.sealed = true
100100
}
101101

102-
// InitMemStore will initialize the memory store if the initialized flag is not set.
103-
// InitMemStore logic should be run in first `BeginBlock` or `InitChain` (whichever is run on app start)
104-
// so that the memory store is properly initialized before any transactions are run.
105-
// InitMemStore also asserts the memory store type is correct, and will panic if it does not have store type of `StoreTypeMemory`.
102+
// InitMemStore will assure that the module store is a memory store (it will panic if it's not)
103+
// and willl initialize it. The function is safe to be called multiple times.
104+
// InitMemStore must be called every time the app starts before the keeper is used (so
105+
// `BeginBlock` or `InitChain` - whichever is first). We need access to the store so we
106+
// can't initialize it in a constructor.
106107
func (k *Keeper) InitMemStore(ctx sdk.Context) {
107108
memStore := ctx.KVStore(k.memKey)
108109
memStoreType := memStore.GetStoreType()
@@ -137,7 +138,7 @@ func (k *Keeper) InitMemStore(ctx sdk.Context) {
137138
}
138139
}
139140

140-
// IsInitialized returns true if the initialized flag is set, and false otherwise
141+
// IsInitialized returns true if the keeper is properly initialized, and false otherwise.
141142
func (k *Keeper) IsInitialized(ctx sdk.Context) bool {
142143
memStore := ctx.KVStore(k.memKey)
143144
return memStore.Get(types.KeyMemInitialized) != nil

x/capability/module.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"math/rand"
7+
"time"
78

89
"github.com/gorilla/mux"
910
"github.com/grpc-ecosystem/grpc-gateway/runtime"
@@ -14,6 +15,7 @@ import (
1415
"github.com/cosmos/cosmos-sdk/client"
1516
"github.com/cosmos/cosmos-sdk/codec"
1617
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
18+
"github.com/cosmos/cosmos-sdk/telemetry"
1719
sdk "github.com/cosmos/cosmos-sdk/types"
1820
"github.com/cosmos/cosmos-sdk/types/module"
1921
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
@@ -143,8 +145,12 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
143145
func (AppModule) ConsensusVersion() uint64 { return 1 }
144146

145147
// BeginBlock executes all ABCI BeginBlock logic respective to the capability module.
148+
// BeginBlocker calls InitMemStore to assert that the memory store is initialized.
149+
// It's safe to run multiple times.
146150
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
147-
BeginBlocker(ctx, am.keeper)
151+
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
152+
153+
am.keeper.InitMemStore(ctx)
148154
}
149155

150156
// EndBlock executes all ABCI EndBlock logic respective to the capability module. It

0 commit comments

Comments
 (0)