Skip to content

Commit b97caa3

Browse files
authored
fix(baseapp): avoid header height overwrite block height (#20107)
1 parent 06a2ae3 commit b97caa3

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
117117
* (x/bank) [#20028](https://github.com/cosmos/cosmos-sdk/pull/20028) Align query with multi denoms for send-enabled.
118118
* (cli) [#20020](https://github.com/cosmos/cosmos-sdk/pull/20020) Make bootstrap-state command support both new and legacy genesis format.
119119
* (baseapp) [#19616](https://github.com/cosmos/cosmos-sdk/pull/19616) Don't share gas meter in tx execution.
120+
* (baseapp) [#20107](https://github.com/cosmos/cosmos-sdk/pull/20107) Allow height overwrite BlockHeight in header.
120121

121122
### API Breaking Changes
122123

baseapp/abci.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1250,13 +1250,13 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e
12501250
// branch the commit multi-store for safety
12511251
ctx := sdk.NewContext(cacheMS, true, app.logger).
12521252
WithMinGasPrices(app.minGasPrices).
1253-
WithBlockHeight(height).
12541253
WithGasMeter(storetypes.NewGasMeter(app.queryGasLimit)).
12551254
WithHeaderInfo(coreheader.Info{
12561255
ChainID: app.chainID,
12571256
Height: height,
12581257
}).
1259-
WithBlockHeader(app.checkState.Context().BlockHeader())
1258+
WithBlockHeader(app.checkState.Context().BlockHeader()).
1259+
WithBlockHeight(height)
12601260

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

baseapp/baseapp_test.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -709,24 +709,33 @@ func TestABCI_CreateQueryContext(t *testing.T) {
709709
_, err = app.Commit()
710710
require.NoError(t, err)
711711
testCases := []struct {
712-
name string
713-
height int64
714-
prove bool
715-
expErr bool
712+
name string
713+
height int64
714+
headerHeight int64
715+
prove bool
716+
expErr bool
716717
}{
717-
{"valid height", 2, true, false},
718-
{"future height", 10, true, true},
719-
{"negative height, prove=true", -1, true, true},
720-
{"negative height, prove=false", -1, false, true},
718+
{"valid height", 2, 2, true, false},
719+
{"valid height with different initial height", 2, 1, true, false},
720+
{"future height", 10, 10, true, true},
721+
{"negative height, prove=true", -1, -1, true, true},
722+
{"negative height, prove=false", -1, -1, false, true},
721723
}
722724

723725
for _, tc := range testCases {
724726
t.Run(tc.name, func(t *testing.T) {
725-
_, err := app.CreateQueryContext(tc.height, tc.prove)
727+
if tc.headerHeight != tc.height {
728+
_, err := app.InitChain(&abci.RequestInitChain{
729+
InitialHeight: tc.headerHeight,
730+
})
731+
require.NoError(t, err)
732+
}
733+
ctx, err := app.CreateQueryContext(tc.height, tc.prove)
726734
if tc.expErr {
727735
require.Error(t, err)
728736
} else {
729737
require.NoError(t, err)
738+
require.Equal(t, tc.height, ctx.BlockHeight())
730739
}
731740
})
732741
}

0 commit comments

Comments
 (0)