You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
wallet: remove fetch pre-selected-inputs responsibility from SelectCoins
In the transaction creation process, in order to select which coins the new transaction will spend,
we first obtain all the available coins known by the wallet, which means walking-through the
wallet txes map, gathering the ones that fulfill certain spendability requirements in a vector.
This coins vector is then provided to the Coin Selection process, which first checks if the user
has manually selected any input (which could be internal, aka known by the wallet, or external),
and if it does, it fetches them by searching each of them inside the wallet and/or inside the
Coin Control external tx data.
Then, after finding the pre-selected-inputs and gathering them in a vector, the Coin Selection
process walks-through the entire available coins vector once more just to erase coins that are
in both vectors. So the Coin Selection process doesn’t pick them twice (duplicate inputs inside
the same transaction).
Now, a new method, `FetchCoins` will be responsible for:
1) Lookup the user pre-selected-inputs (which can be internal or external).
2) And, fetch the available coins in the wallet (excluding the already fetched ones).
This new flow allows us to never include the pre-selected-inputs inside the available
coins vector in the first place. So, Coin Selection can perform its main responsibility
without mixing it with having to fetch internal/external coins nor any slow and unneeded
duplicate inputs verification
Improvements:
1) If any pre-selected-input lookup fail, the process will return the error right away.
(Before, the wallet was fetching all the wallet available coins, walking through the
entire txes map, and then failing for an invalid pre-selected-input inside SelectCoins)
2) The pre-selected-inputs lookup failure causes are properly described now on the return error.
(before, we were just returning an "Insufficient Funds" error even if the failure was due
a not solvable external input)
3) Faster Coin Selection, no longer need to "remove the pre-set inputs from the available coins
vector so that Coin Selection doesn't pick them" (which meant to loop-over the entire
available coins vector at coin selection time, erasing coins that were pre-selected).
Now, the available coins vector, which is built after the pre-selected-inputs fetching,
doesn't include the already selected inputs in the first place.
4) Faster transaction creation for transactions that only use manually selected inputs.
We now will return early, as soon as we finish fetching the pre-selected-inputs and
not perform the resources expensive calculation of walking-through the entire wallet
txes map to obtain the available coins (coins that we will not use).
0 commit comments