Skip to content

Commit 7828a00

Browse files
mergify[bot]mmsqejulienrbrt
authoredApr 22, 2024··
fix(baseapp): avoid header height overwrite block height (backport #20107) (#20129)
Co-authored-by: mmsqe <[email protected]> Co-authored-by: Julien Robert <[email protected]>
·
1 parent 3437fd5 commit 7828a00

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
3838

3939
## [Unreleased]
4040

41+
### Bug Fixes
42+
43+
* (baseapp) [#20107](https://github.com/cosmos/cosmos-sdk/pull/20107) Avoid header height overwrite block height.
44+
4145
## [v0.50.6](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.6) - 2024-04-22
4246

4347
### Features

‎baseapp/abci.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1230,8 +1230,9 @@ 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-
WithBlockHeight(height).
1234-
WithGasMeter(storetypes.NewGasMeter(app.queryGasLimit)).WithBlockHeader(header)
1233+
WithGasMeter(storetypes.NewGasMeter(app.queryGasLimit)).
1234+
WithBlockHeader(header).
1235+
WithBlockHeight(height)
12351236

12361237
if height != lastBlockHeight {
12371238
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)
Please sign in to comment.