This started in #24845 but grew out of scope of it.
So, points tackled:
Avoid extra
GetWalletTxlookups insideAvailableCoins -> IsSpentKey.IsSpentKeywas receiving the tx hash and index to internally lookup the tx inside the wallet's map. As all theIsSpentKeyfunction callers already have the wtx available, them can provide thescriptPubKeydirectly.Most of the time, we call
Wallet::AvailableCoins, and later on the process, skip the non-spendable coins from the result in subsequent for-loops. So to speedup the process: introduced the ability to filter by "only_spendable" coins insideWallet::AvailableCoinsdirectly. (the non-spendable coins skip examples are insideAttemptSelection->GroupOutputsandGetAvailableBalance).Refactored
AvailableCoinsin several ways:a) Now it will return a new struct
CoinsResultinstead of receiving the vCoins vector reference (which was being cleared at the beginning of the method anyway). --> this is coming from #24845 but cherry-picked it here too to make the following commits look nicer.b) Unified all the 'wtx.tx->vout[I]' calls into a single call (coming from this comment #24699 (review)).
The wallet
IsLockedCoinandIsSpentmethods now accept anOutPointinstead of a hash:index. Which let me cleanup a bunch of extra code.Speeded up the wallet 'GetAvailableBalance': filtering
AvailableCoinsby spendable outputs only and using the 'AvailableCoins' retrievedtotal_amountinstead of looping over all the retrieved coins once more.
Side topic, all this process will look even nicer with #25218