This started in #24845 but grew out of scope of it.
So, points tackled:
-
Avoid extra
GetWalletTx
lookups insideAvailableCoins -> IsSpentKey
.IsSpentKey
was receiving the tx hash and index to internally lookup the tx inside the wallet’s map. As all theIsSpentKey
function callers already have the wtx available, them can provide thescriptPubKey
directly. -
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::AvailableCoins
directly. (the non-spendable coins skip examples are insideAttemptSelection->GroupOutputs
andGetAvailableBalance
). -
Refactored
AvailableCoins
in several ways:a) Now it will return a new struct
CoinsResult
instead 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
IsLockedCoin
andIsSpent
methods now accept anOutPoint
instead of a hash:index. Which let me cleanup a bunch of extra code. -
Speeded up the wallet ‘GetAvailableBalance’: filtering
AvailableCoins
by spendable outputs only and using the ‘AvailableCoins’ retrievedtotal_amount
instead of looping over all the retrieved coins once more.
Side topic, all this process will look even nicer with #25218