fix: x/capability InitMemStore should not consume gas (#15030)
This commit is contained in:
parent
dfb3271cdd
commit
e9dbe6f86a
@ -270,6 +270,7 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* (x/capability) [#15030](https://github.com/cosmos/cosmos-sdk/pull/15030) Fixed bug where `x/capability` consumed `GasMeter` gas during `InitMemStore`.
|
||||
* [#14995](https://github.com/cosmos/cosmos-sdk/pull/14995) Allow unknown fields in `ParseTypedEvent`.
|
||||
* [#14952](https://github.com/cosmos/cosmos-sdk/pull/14952) Pin version of github.com/syndtr/goleveldb `v1.0.1-0.20210819022825-2ae1ddf74ef7` to avoid issues in the store.
|
||||
* (store) [#14931](https://github.com/cosmos/cosmos-sdk/pull/14931) Exclude in-memory KVStores, i.e. `StoreTypeMemory`, from CommitInfo commitments.
|
||||
|
||||
@ -70,13 +70,16 @@ func (suite *CapabilityTestSuite) TestInitializeMemStore() {
|
||||
|
||||
// Mock app beginblock and ensure that no gas has been consumed and memstore is initialized
|
||||
ctx = suite.app.BaseApp.NewContext(false, cmtproto.Header{}).WithBlockGasMeter(storetypes.NewGasMeter(50))
|
||||
prevGas := ctx.BlockGasMeter().GasConsumed()
|
||||
prevBlockGas := ctx.BlockGasMeter().GasConsumed()
|
||||
prevGas := ctx.GasMeter().GasConsumed()
|
||||
restartedModule := capability.NewAppModule(suite.cdc, *newKeeper, true)
|
||||
restartedModule.BeginBlock(ctx, abci.RequestBeginBlock{})
|
||||
gasUsed := ctx.GasMeter().GasConsumed()
|
||||
suite.Require().True(newKeeper.IsInitialized(ctx), "memstore initialized flag not set")
|
||||
gasUsed := ctx.BlockGasMeter().GasConsumed()
|
||||
blockGasUsed := ctx.BlockGasMeter().GasConsumed()
|
||||
|
||||
suite.Require().Equal(prevGas, gasUsed, "beginblocker consumed gas during execution")
|
||||
suite.Require().Equal(prevBlockGas, blockGasUsed, "ensure beginblocker consumed no block gas during execution")
|
||||
suite.Require().Equal(prevGas, gasUsed, "ensure beginblocker consumed no gas during execution")
|
||||
|
||||
// Mock the first transaction getting capability and subsequently failing
|
||||
// by using a cached context and discarding all cached writes.
|
||||
|
||||
@ -119,8 +119,9 @@ func (k *Keeper) InitMemStore(ctx sdk.Context) {
|
||||
panic(fmt.Sprintf("invalid memory store type; got %s, expected: %s", memStoreType, storetypes.StoreTypeMemory))
|
||||
}
|
||||
|
||||
// create context with no block gas meter to ensure we do not consume gas during local initialization logic.
|
||||
noGasCtx := ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter())
|
||||
// Create a context with no `BlockGasMeter`, and no `GasMeter`. This ensures we do not consume gas during local
|
||||
// initialization logic.
|
||||
noGasCtx := ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()).WithGasMeter(storetypes.NewInfiniteGasMeter())
|
||||
|
||||
// check if memory store has not been initialized yet by checking if initialized flag is nil.
|
||||
if !k.IsInitialized(noGasCtx) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user