beta7: wallet perf — single AvailableCoins pass in SelectCoins + limit-aware listtransactions#129
Draft
RhettCreighton wants to merge 1 commit into
Draft
beta7: wallet perf — single AvailableCoins pass in SelectCoins + limit-aware listtransactions#129RhettCreighton wants to merge 1 commit into
RhettCreighton wants to merge 1 commit into
Conversation
…t-aware listtransactions Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Two safe, value-preserving wallet perf wins. Neither changes any returned value (balances, coin-selection results, RPC output) — they only avoid redundant work.
1.
CWallet::SelectCoins— singleAvailableCoinspassSelectCoinspreviously calledAvailableCoinstwice per selection — once withfIncludeCoinBase=falseand once withtrue— doing two fullmapWalletscans. The only filter difference between the two calls is the coinbase-exclusion line, so the no-coinbase set is exactly the with-coinbase set minus coinbase-tx outputs.We now do a single pass (
fIncludeCoinBase=true) and partition in-memory viaout.tx->IsCoinBase(). The non-coinbase outputs keep their original relative order, and all downstream consumers (fOnlyCoinbaseCoinsRet, thefProtectCoinbaseset choice, thevCoinsWithCoinbase.size() > vCoinsNoCoinbase.size()check, the value-sum loops, the coin-control set insert, andSelectCoinsMinConf'srandom_shuffle) are order-independent or see identical contents. Selected-coin set is unchanged.2.
listtransactions/OrderedTxItems— limit-aware pathOrderedTxItemsbuilt the full ordered multimap of all wallet txs + accounting entries regardless of the requestedcount/from. Added an optionalnLimitarg (default 0 = unchanged full behavior) that keeps only the newestnLimititems (largestnOrderPos) by trimming the smallest as it builds.listtransactionsrequestsnLimit = count + fromand iterates newest-first as before. Because a single tx can expand to 0..N output rows, a trimmed window could in rare cases under-supply the requested rows; so when the window was actually capped and we still couldn't fillcount+fromrows, we fall back to the original unlimited pass. This guarantees byte-identical output ordering and contents for the returned slice, while saving the full-wallet multimap build in the common case (window smaller than wallet, txs yielding >= 1 row).Files
src/wallet/wallet.cpp— singleAvailableCoinspass inSelectCoins; limit-awareOrderedTxItemssrc/wallet/wallet.h—OrderedTxItemsgainsint nLimit = 0(default preserves old behavior)src/wallet/rpcwallet.cpp—listtransactionslimit-aware path + safe fallbackConsensus impact: none
No change to block/tx validation, PoW, script, serialization, chainparams, or activation heights. No amount math or balance-computation function touched.
Behavior preserved
Both changes are pure work-avoidance. Coin-selection results are identical;
listtransactionsoutput is identical (with a guaranteed fallback to the original code path if a trimmed window can't fill the requested rows).DRAFT: pending maintainer build-verification.