feat: optimize staking EndBlock/BeginBlock queue iterators#1768
Draft
thomas-nguy wants to merge 3 commits intocrypto-org-chain:release/v0.53.xfrom
Draft
feat: optimize staking EndBlock/BeginBlock queue iterators#1768thomas-nguy wants to merge 3 commits intocrypto-org-chain:release/v0.53.xfrom
thomas-nguy wants to merge 3 commits intocrypto-org-chain:release/v0.53.xfrom
Conversation
|
I remember I did something similar to this, ie trying to reduce the range of iteration, before trying to create an in memory cache. However, the duration taken to create the iterator still causes significant lag in the endblocker, staking endblocker is still taking around 700ms |
randy-cro
reviewed
Feb 19, 2026
randy-cro
reviewed
Feb 19, 2026
|
|
||
| // SetHistoricalInfo sets the historical info at a given height | ||
| // SetHistoricalInfo sets the historical info at a given height. When the min-height | ||
| // hint is unset (e.g. genesis), sets it to this height so IterateHistoricalInfo is bounded. |
There was a problem hiding this comment.
dont think historical info is exported or imported for genesis
2dbf89d to
6a40c78
Compare
6a40c78 to
b9ce84f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduces staking EndBlock (and BeginBlock historical info) cost when chain and queue data grow by avoiding full-prefix scans on time/height-ordered queues. Iterators now start from a tracked queue head (or, for HistoricalInfo, a min height) and can early-exit when there are no mature entries.
Problem
Profiling showed bottlenecks in:
Each was iterating from the prefix start (e.g. time 0) up to the current block time/height every block. As the chain and queues grew, that range and the cost of creating/using the iterator increased even when only a few entries matured per block.
Solution
Persist the minimum (earliest) completion key still in each queue.
Iteration: Start the iterator from this head key instead of the prefix start (fallback to prefix start if head is missing).
Early exit: If the stored head is after current block time/height, skip creating the iterator and return.
Head updates:
On enqueue (e.g. SetUBDQueueTimeSlice, SetRedelegationQueueTimeSlice, SetUnbondingValidatorsQueue): set head when the new key is earlier than the current head (or head is unset).
Validator queue: head is updated only on enqueue; if the head key is later deleted, the next block’s iterator still starts at that key and the store seeks to the next existing key.
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!to the type prefix if API or client breaking changeCHANGELOG.mdmake lintandmake testReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!in the type prefix if API or client breaking change