This comes with #26559.
Solving few bugs inside the wallet’s transaction creation
process and adding test coverage for them.
Plus, making use of the CoinsResult::total_amount
cached value
inside the Coin Selection process to return early if we don’t have
enough funds to cover the target amount.
Bugs
-
The
CoinsResult::Erase
method removes only one output from the available coins vector (there is a loop break that should have never been there) and not all the preset inputs.Which on master is not a problem, because since #25685 we are no longer using the method. But, it’s a bug on v24 (check #26559).
This method it’s being fixed and not removed because I’m later using it to solve another bug inside this PR.
-
As we update the total cached amount of the
CoinsResult
object insideAvailableCoins
and we don’t use such function inside the coin selection tests (we manually load up theCoinsResult
object), there is a discrepancy between the outputs that we add/erase and the total amount cached value.
Improvements
- This makes use of the
CoinsResult
total amount field to early return with an “Insufficient funds” error inside Coin Selection if the tx target amount is greater than the sum of all the wallet available coins plus the preset inputs amounts (we don’t need to perform the entire coin selection process if we already know that there aren’t enough funds inside our wallet).
Test Coverage
-
Adds test coverage for the duplicated preset input selection bug that we have in v24. Where the wallet invalidly selects the preset inputs twice during the Coin Selection process. Which ends up with a “good” Coin Selection result that does not cover the total tx target amount. Which, alone, crashes the wallet due an insane fee. But.. to make it worst, adding the subtract fee from output functionality to this mix ends up with the wallet by-passing the “insane” fee assertion, decreasing the output amount to fulfill the insane fee, and.. sadly, broadcasting the tx to the network.
-
Adds test coverage for the
CoinsResult::Erase
method.