fix: incorrect retention height when commitHeight equals minRetainBlocks (#24526)

This commit is contained in:
beer-1
2025-04-17 16:11:35 +00:00
committed by GitHub
parent 6b723d2dd7
commit 553f8955c3
3 changed files with 19 additions and 4 deletions
+1
View File
@@ -103,6 +103,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (baseapp) [#24074](https://github.com/cosmos/cosmos-sdk/pull/24074) Use CometBFT's ComputeProtoSizeForTxs in defaultTxSelector.SelectTxForProposal for consistency.
* (cli) [#24090](https://github.com/cosmos/cosmos-sdk/pull/24090) Prune cmd should disable async pruning.
* (x/auth) [#19239](https://github.com/cosmos/cosmos-sdk/pull/19239) Sets from flag in multi-sign command to avoid no key name provided error.
* (baseapp) [#24526](https://github.com/cosmos/cosmos-sdk/pull/24526) Fix incorrect retention height when `commitHeight` equals `minRetainBlocks`.
## [v0.50.12](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.12) - 2025-02-20
+6 -4
View File
@@ -1319,8 +1319,11 @@ func (app *BaseApp) CreateQueryContextWithCheckHeader(height int64, prove, check
// be a need to vary retention for other nodes, e.g. sentry nodes which do not
// need historical blocks.
func (app *BaseApp) GetBlockRetentionHeight(commitHeight int64) int64 {
// pruning is disabled if minRetainBlocks is zero
if app.minRetainBlocks == 0 {
// If minRetainBlocks is zero, pruning is disabled and we return 0
// If commitHeight is less than or equal to minRetainBlocks, return 0 since there are not enough
// blocks to trigger pruning yet. This ensures we keep all blocks until we have at least minRetainBlocks.
retentionBlockWindow := commitHeight - int64(app.minRetainBlocks)
if app.minRetainBlocks == 0 || retentionBlockWindow <= 0 {
return 0
}
@@ -1362,8 +1365,7 @@ func (app *BaseApp) GetBlockRetentionHeight(commitHeight int64) int64 {
}
}
v := commitHeight - int64(app.minRetainBlocks)
retentionHeight = minNonZero(retentionHeight, v)
retentionHeight = minNonZero(retentionHeight, retentionBlockWindow)
if retentionHeight <= 0 {
// prune nothing in the case of a non-positive height
+12
View File
@@ -1322,6 +1322,18 @@ func TestABCI_GetBlockRetentionHeight(t *testing.T) {
commitHeight: 10000,
expected: 0,
},
"no pruning due to min retain blocks equal to commit height": {
bapp: baseapp.NewBaseApp(name, logger, db, nil, baseapp.SetMinRetainBlocks(499000)),
maxAgeBlocks: 362880,
commitHeight: 499000,
expected: 0,
},
"no pruning due to min retain blocks greater than commit height": {
bapp: baseapp.NewBaseApp(name, logger, db, nil, baseapp.SetMinRetainBlocks(499001)),
maxAgeBlocks: 362880,
commitHeight: 499000,
expected: 0,
},
"disable pruning": {
bapp: baseapp.NewBaseApp(
name, logger, db, nil,