fix: remove unbounded collect in finalize_all_subnet_root_dividends#2456
Open
ionodeionode wants to merge 1 commit intoopentensor:mainfrom
Open
fix: remove unbounded collect in finalize_all_subnet_root_dividends#2456ionodeionode wants to merge 1 commit intoopentensor:mainfrom
ionodeionode wants to merge 1 commit intoopentensor:mainfrom
Conversation
…pentensor#2411) Replace the unbounded Vec collect with a lazy iterator drain to avoid O(N) memory allocation when cleaning up RootClaimable entries during subnet dissolution. This prevents potential block weight limit violations and high memory usage with large numbers of hotkeys. The storage iterator cursor remains valid while mutating other keys in the same map, so we can safely process each hotkey without materializing the full key set in memory. Closes opentensor#2411
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
Fixes #2411
Problem
finalize_all_subnet_root_dividendscollects all hotkey keys fromRootClaimablestorage into aVecbefore iterating and mutating each one:This is O(N) in both reads and memory where N is the total number of hotkeys with any root claimable balance. Since this function is called from
do_dissolve_network(an extrinsic), with thousands of hotkeys this could:collect::<Vec<_>>()Solution
Replace the unbounded `collect()" with a lazy iterator drain:
This processes each hotkey without materializing the full key set in memory. Substrate's storage iterators are safe to use while mutating other keys of the same map (cursor invalidation only occurs when the current key is removed, which we don't do here — we only mutate the value).
Impact