Skip to content

Commit e59aa4d

Browse files
mmsqemergify[bot]
authored andcommitted
fix(baseapp): avoid header height overwrite block height (#20107)
(cherry picked from commit b97caa3) # Conflicts: # CHANGELOG.md # baseapp/abci.go
1 parent c4d9a49 commit e59aa4d

File tree

3 files changed

+112
-9
lines changed

3 files changed

+112
-9
lines changed

CHANGELOG.md

+84
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,90 @@ Ref: https://keepachangelog.com/en/1.0.0/
6565
* (baseapp) [#19970](https://github.com/cosmos/cosmos-sdk/pull/19970) Fix default config values to use no-op mempool as default.
6666
* (crypto) [#20027](https://github.com/cosmos/cosmos-sdk/pull/20027) secp256r1 keys now implement gogoproto's customtype interface.
6767
* (x/bank) [#20028](https://github.com/cosmos/cosmos-sdk/pull/20028) Align query with multi denoms for send-enabled.
68+
<<<<<<< HEAD
69+
=======
70+
* (cli) [#20020](https://github.com/cosmos/cosmos-sdk/pull/20020) Make bootstrap-state command support both new and legacy genesis format.
71+
* (baseapp) [#19616](https://github.com/cosmos/cosmos-sdk/pull/19616) Don't share gas meter in tx execution.
72+
* (baseapp) [#20107](https://github.com/cosmos/cosmos-sdk/pull/20107) Allow height overwrite BlockHeight in header.
73+
74+
### API Breaking Changes
75+
76+
* (x/simulation)[#20056](https://github.com/cosmos/cosmos-sdk/pull/20056) `SimulateFromSeed` now takes an address codec as argument.
77+
* (x/crisis) [#20043](https://github.com/cosmos/cosmos-sdk/pull/20043) Changed `NewMsgVerifyInvariant` to accept a string as argument instead of an `AccAddress`.
78+
* (x/genutil) [#19926](https://github.com/cosmos/cosmos-sdk/pull/19926) Removal of the Address.String() method and related changes:
79+
* Added an address codec as an argument to `CollectTxs`, `GenAppStateFromConfig`, and `AddGenesisAccount`.
80+
* Removed the `ValidatorAddressCodec` argument from `CollectGenTxsCmd`, now utilizing the context for this purpose.
81+
* Changed `ValidateAccountInGenesis` to accept a string instead of an `AccAddress`.
82+
* (server) [#19854](https://github.com/cosmos/cosmos-sdk/pull/19854) Remove `servertypes.ModuleInitFlags` types and from `server.AddCommands` as `StartCmdOptions` already achieves the same goal.
83+
* (types) [#19792](https://github.com/cosmos/cosmos-sdk/pull/19792) In `MsgSimulatorFn` `sdk.Context` argument is replaced for an `address.Codec`. It also returns an error.
84+
* (types) [#19742](https://github.com/cosmos/cosmos-sdk/pull/19742) Removes the use of `Accounts.String`
85+
* `SimulationState` now has address and validator codecs as fields.
86+
* (types) [#19447](https://github.com/cosmos/cosmos-sdk/pull/19447) `module.testutil.MakeTestEncodingConfig` now takes `CodecOptions` as argument.
87+
* (types) [#19512](https://github.com/cosmos/cosmos-sdk/pull/19512) Remove basic manager and all related functions (`module.BasicManager`, `module.NewBasicManager`, `module.NewBasicManagerFromManager`, `NewGenesisOnlyAppModule`).
88+
* The module manager now can do everything that the basic manager was doing.
89+
* When using runtime, just inject the module manager when needed using your app config.
90+
* All `AppModuleBasic` structs have been removed.
91+
* (x/consensus) [#19488](https://github.com/cosmos/cosmos-sdk/pull/19488) Consensus module creation takes `appmodule.Environment` instead of individual services.
92+
* (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `x/genutil` now handles the application export. `server.AddCommands` does not take an `AppExporter` but instead `genutilcli.Commands` does.
93+
* (x/gov/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/18036) `MsgDeposit` has been removed because of AutoCLI migration.
94+
* (x/staking/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/17986) `MsgRedelegateExec`, `MsgUnbondExec` has been removed because of AutoCLI migration.
95+
* (x/bank/testutil) [#17868](https://github.com/cosmos/cosmos-sdk/pull/17868) `MsgSendExec` has been removed because of AutoCLI migration.
96+
* (app) [#17838](https://github.com/cosmos/cosmos-sdk/pull/17838) Params module was removed from simapp and all imports of the params module removed throughout the repo.
97+
* The Cosmos SDK has migrated away from using params, if your app still uses it, then you can leave it plugged into your app
98+
* (types/simulation) [#17737](https://github.com/cosmos/cosmos-sdk/pull/17737) Remove unused parameter from `RandomFees`
99+
* (client/keys) [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503) `clientkeys.NewKeyOutput`, `MkConsKeyOutput`, `MkValKeyOutput`, `MkAccKeyOutput`, `MkAccKeysOutput` now take their corresponding address codec instead of using the global SDK config.
100+
* (types) `module.BeginBlockAppModule` has been replaced by Core API `appmodule.HasBeginBlocker`.
101+
* (types) `module.EndBlockAppModule` has been replaced by Core API `appmodule.HasEndBlocker` or `module.HasABCIEndBlock` when needing validator updates.
102+
* (client) [#17259](https://github.com/cosmos/cosmos-sdk/pull/17259) Remove deprecated `clientCtx.PrintObjectLegacy`. Use `clientCtx.PrintProto` or `clientCtx.PrintRaw` instead.
103+
* (types) [#16918](https://github.com/cosmos/cosmos-sdk/pull/16918) Remove `IntProto` and `DecProto`. Instead, `math.Int` and `math.LegacyDec` should be used respectively. Both types support `Marshal` and `Unmarshal` which should be used for binary marshaling.
104+
* (client) [#17215](https://github.com/cosmos/cosmos-sdk/pull/17215) `server.StartCmd`,`server.ExportCmd`,`server.NewRollbackCmd`,`pruning.Cmd`,`genutilcli.InitCmd`,`genutilcli.GenTxCmd`,`genutilcli.CollectGenTxsCmd`,`genutilcli.AddGenesisAccountCmd`, do not take a home directory anymore. It is inferred from the root command.
105+
* (baseapp) [#16244](https://github.com/cosmos/cosmos-sdk/pull/16244) `SetProtocolVersion` has been renamed to `SetAppVersion`. It now updates the consensus params in baseapp's `ParamStore`.
106+
* (types) [#17348](https://github.com/cosmos/cosmos-sdk/pull/17348) Remove the `WrapServiceResult` function.
107+
* The `*sdk.Result` returned by the msg server router will not contain the `.Data` field.
108+
* (types) [#17426](https://github.com/cosmos/cosmos-sdk/pull/17426) `NewContext` does not take a `cmtproto.Header{}` any longer.
109+
* `WithChainID` / `WithBlockHeight` / `WithBlockHeader` must be used to set values on the context
110+
* (types) [#17738](https://github.com/cosmos/cosmos-sdk/pull/17738) `WithBlockTime()` was removed & `BlockTime()` were deprecated in favor of `WithHeaderInfo()` & `HeaderInfo()`. `BlockTime` now gets data from `HeaderInfo()` instead of `BlockHeader()`.
111+
* (client) [#17746](https://github.com/cosmos/cosmos-sdk/pull/17746) `txEncodeAmino` & `txDecodeAmino` txs via grpc and rest were removed
112+
* `RegisterLegacyAmino` was removed from `AppModuleBasic`
113+
* (types) [#17885](https://github.com/cosmos/cosmos-sdk/pull/17885) `InitGenesis` & `ExportGenesis` now take `context.Context` instead of `sdk.Context`
114+
* (x/group) [#17937](https://github.com/cosmos/cosmos-sdk/pull/17937) Groups module was moved to its own go.mod `cosmossdk.io/x/group`
115+
* (x/gov) [#18197](https://github.com/cosmos/cosmos-sdk/pull/18197) Gov module was moved to its own go.mod `cosmossdk.io/x/gov`
116+
* (x/distribution) [#18199](https://github.com/cosmos/cosmos-sdk/pull/18199) Distribution module was moved to its own go.mod `cosmossdk.io/x/distribution`
117+
* (x/slashing) [#18201](https://github.com/cosmos/cosmos-sdk/pull/18201) Slashing module was moved to its own go.mod `cosmossdk.io/x/slashing`
118+
* (x/staking) [#18257](https://github.com/cosmos/cosmos-sdk/pull/18257) Staking module was moved to its own go.mod `cosmossdk.io/x/staking`
119+
* (x/authz) [#18265](https://github.com/cosmos/cosmos-sdk/pull/18265) Authz module was moved to its own go.mod `cosmossdk.io/x/authz`
120+
* (x/mint) [#18283](https://github.com/cosmos/cosmos-sdk/pull/18283) Mint module was moved to its own go.mod `cosmossdk.io/x/mint`
121+
* (x/consensus) [#18041](https://github.com/cosmos/cosmos-sdk/pull/18041) `ToProtoConsensusParams()` returns an error
122+
* (x/slashing) [#18115](https://github.com/cosmos/cosmos-sdk/pull/18115) `NewValidatorSigningInfo` takes strings instead of `sdk.AccAddress`
123+
* (types) [#18268](https://github.com/cosmos/cosmos-sdk/pull/18268) Remove global setting of basedenom. Use the staking module parameter instead
124+
* (x/auth) [#18351](https://github.com/cosmos/cosmos-sdk/pull/18351) Auth module was moved to its own go.mod `cosmossdk.io/x/auth`
125+
* (types) [#18372](https://github.com/cosmos/cosmos-sdk/pull/18372) Removed global configuration for coin type and purpose. Setters and getters should be removed and access directly to defined types.
126+
* (types) [#18695](https://github.com/cosmos/cosmos-sdk/pull/18695) Removed global configuration for txEncoder.
127+
* (types) [#18607](https://github.com/cosmos/cosmos-sdk/pull/18607) Removed address verifier from global config, moved verifier function to bech32 codec.
128+
* (server) [#18909](https://github.com/cosmos/cosmos-sdk/pull/18909) Remove configuration endpoint on grpc reflection endpoint in favour of auth module bech32prefix endpoint already exposed.
129+
* (crypto) [#19541](https://github.com/cosmos/cosmos-sdk/pull/19541) The deprecated `FromTmProtoPublicKey`, `ToTmProtoPublicKey`, `FromTmPubKeyInterface` and `ToTmPubKeyInterface` functions have been removed. Use their replacements (`Cmt` instead of `Tm`) instead.
130+
* (types) [#19652](https://github.com/cosmos/cosmos-sdk/pull/19652) and [#19758](https://github.com/cosmos/cosmos-sdk/pull/19758)
131+
* Moved`types/module.HasRegisterInterfaces` to `cosmossdk.io/core`.
132+
* Moved `RegisterInterfaces` and `RegisterImplementations` from `InterfaceRegistry` to `cosmossdk.io/core/registry.InterfaceRegistrar` interface.
133+
* (types) [#19627](https://github.com/cosmos/cosmos-sdk/pull/19627) and [#19735](https://github.com/cosmos/cosmos-sdk/pull/19735) All genesis interfaces now don't take `codec.JsonCodec`.
134+
* Every module has the codec already, passing it created an unneeded dependency.
135+
* Additionally, to reflect this change, the module manager does not take a codec either.
136+
* (runtime) [#19747](https://github.com/cosmos/cosmos-sdk/pull/19747) `runtime.ValidatorAddressCodec` and `runtime.ConsensusAddressCodec` have been moved to `core`.
137+
* (baseapp) [#19993](https://github.com/cosmos/cosmos-sdk/pull/19993) Indicate pruning with error code "not found" rather than "invalid request".
138+
139+
### Client Breaking Changes
140+
141+
* (runtime) [#19040](https://github.com/cosmos/cosmos-sdk/pull/19040) Simplify app config implementation and deprecate `/cosmos/app/v1alpha1/config` query.
142+
143+
### CLI Breaking Changes
144+
145+
* (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `appd export` has moved with other genesis commands, use `appd genesis export` instead.
146+
147+
### Deprecated
148+
149+
* (simapp) [#19146](https://github.com/cosmos/cosmos-sdk/pull/19146) Replace `--v` CLI option with `--validator-count`/`-n`.
150+
* (module) [#19370](https://github.com/cosmos/cosmos-sdk/pull/19370) Deprecate `module.Configurator`, use `appmodule.HasMigrations` and `appmodule.HasServices` instead from Core API.
151+
>>>>>>> b97caa35c (fix(baseapp): avoid header height overwrite block height (#20107))
68152
69153
## [v0.50.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.5) - 2024-03-12
70154

baseapp/abci.go

+10
Original file line numberDiff line numberDiff line change
@@ -1230,8 +1230,18 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e
12301230
header := app.checkState.Context().BlockHeader()
12311231
ctx := sdk.NewContext(cacheMS, header, true, app.logger).
12321232
WithMinGasPrices(app.minGasPrices).
1233+
<<<<<<< HEAD
12331234
WithBlockHeight(height).
12341235
WithGasMeter(storetypes.NewGasMeter(app.queryGasLimit)).WithBlockHeader(header)
1236+
=======
1237+
WithGasMeter(storetypes.NewGasMeter(app.queryGasLimit)).
1238+
WithHeaderInfo(coreheader.Info{
1239+
ChainID: app.chainID,
1240+
Height: height,
1241+
}).
1242+
WithBlockHeader(app.checkState.Context().BlockHeader()).
1243+
WithBlockHeight(height)
1244+
>>>>>>> b97caa35c (fix(baseapp): avoid header height overwrite block height (#20107))
12351245

12361246
if height != lastBlockHeight {
12371247
rms, ok := app.cms.(*rootmulti.Store)

baseapp/baseapp_test.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -702,24 +702,33 @@ func TestABCI_CreateQueryContext(t *testing.T) {
702702
require.NoError(t, err)
703703

704704
testCases := []struct {
705-
name string
706-
height int64
707-
prove bool
708-
expErr bool
705+
name string
706+
height int64
707+
headerHeight int64
708+
prove bool
709+
expErr bool
709710
}{
710-
{"valid height", 2, true, false},
711-
{"future height", 10, true, true},
712-
{"negative height, prove=true", -1, true, true},
713-
{"negative height, prove=false", -1, false, true},
711+
{"valid height", 2, 2, true, false},
712+
{"valid height with different initial height", 2, 1, true, false},
713+
{"future height", 10, 10, true, true},
714+
{"negative height, prove=true", -1, -1, true, true},
715+
{"negative height, prove=false", -1, -1, false, true},
714716
}
715717

716718
for _, tc := range testCases {
717719
t.Run(tc.name, func(t *testing.T) {
718-
_, err := app.CreateQueryContext(tc.height, tc.prove)
720+
if tc.headerHeight != tc.height {
721+
_, err := app.InitChain(&abci.RequestInitChain{
722+
InitialHeight: tc.headerHeight,
723+
})
724+
require.NoError(t, err)
725+
}
726+
ctx, err := app.CreateQueryContext(tc.height, tc.prove)
719727
if tc.expErr {
720728
require.Error(t, err)
721729
} else {
722730
require.NoError(t, err)
731+
require.Equal(t, tc.height, ctx.BlockHeight())
723732
}
724733
})
725734
}

0 commit comments

Comments
 (0)