This PR is a forward-port of #9392 from `release/v0.42.x` to `master`. It was initially decided in https://github.com/cosmos/cosmos-sdk/pull/9392#issuecomment-865987655 that #9392 would be a temporary fix for 0.42, but as per @AdityaSripal's request we're actually foward-porting this to master too. ## Mergify description: This is an automatic backport of pull request #9392 done by [Mergify](https://mergify.io). Cherry-pick of3776793ce6
has failed: ``` On branch mergify/bp/master/pr-9392 Your branch is up to date with 'origin/master'. You are currently cherry-picking commit3776793ce
. (fix conflicts and run "git cherry-pick --continue") (use "git cherry-pick --skip" to skip this patch) (use "git cherry-pick --abort" to cancel the cherry-pick operation) Changes to be committed: modified: x/bank/simulation/params.go modified: x/capability/keeper/keeper.go Unmerged paths: (use "git add/rm <file>..." as appropriate to mark resolution) deleted by us: x/ibc/applications/transfer/simulation/params.go ``` To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/github/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally --- <details> <summary>Mergify commands and options</summary> <br /> More conditions and actions can be found in the [documentation](https://docs.mergify.io/). You can also trigger Mergify actions by commenting on this pull request: - `@Mergifyio refresh` will re-evaluate the rules - `@Mergifyio rebase` will rebase this PR on its base branch - `@Mergifyio update` will merge the base branch into this PR - `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch Additionally, on Mergify [dashboard](https://dashboard.mergify.io/) you can: - look at your merge queues - generate the Mergify configuration with the config editor. Finally, you can contact us on https://mergify.io/ </details>
This commit is contained in:
parent
90157fc5f4
commit
d587599122
|
@ -23,7 +23,7 @@ func ParamChanges(r *rand.Rand) []simtypes.ParamChange {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return fmt.Sprintf("%s", paramsBytes)
|
||||
return string(paramsBytes)
|
||||
},
|
||||
),
|
||||
simulation.NewSimParamChange(types.ModuleName, string(types.KeyDefaultSendEnabled),
|
||||
|
|
|
@ -13,6 +13,14 @@ 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
|
||||
|
@ -342,6 +350,22 @@ 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
|
||||
}
|
||||
|
@ -358,6 +382,7 @@ func (sk ScopedKeeper) GetCapability(ctx sdk.Context, name string) (*types.Capab
|
|||
// so we delete here to remove unnecessary values in map
|
||||
// TODO: Delete index correctly from capMap by storing some reverse lookup
|
||||
// in-memory map. Issue: https://github.com/cosmos/cosmos-sdk/issues/7805
|
||||
|
||||
return nil, false
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue