Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #693: Fix the early InsufficientFunds error in the branch and b…
…ound 9d85c96 Fix the early InsufficientFunds error in the branch and bound (Alekos Filini) Pull request description: ### Description We were wrongly considering the sum of "effective value" (i.e. value - fee cost) when reporting an early "insufficient funds" error in the branch and bound coin selection. This commit fixes essentially two issues: - Very high fee rates could cause a panic during the i64 -> u64 conversion because we assumed the sum of effective values would never be negative - Since we were comparing the sum of effective values of *all* the UTXOs (even the optional UTXOs with negative effective value) with the target we'd like to reach, we could in some cases error and tell the user we don't have enough funds, while in fact we do! Since we are not required to spend any of the optional UTXOs, so we could just ignore the ones that *cost us* money to spend and excluding them could potentially allow us to reach the target. There's a third issue that was present before and remains even with this fix: when we report the "available" funds in the error, we are ignoring UTXOs with negative effective value, so it may look like there are less funds in the wallet than there actually are. I don't know how to convey the right message the user: if we actually consider them we just make the "needed" value larger and larger (which may be confusing, because if the user asks BDK to send 10k satoshis, why do we say that we actually need 100k?), while if we don't we could report an incorrect "available" value. ### Notes to the reviewers I'm opening this as a draft before adding tests because I want to gather some feedback on the available vs needed error reporting. I personally think reporting a reasonable "needed" value is more important than the "available", because in a wallet app I would expect this is the value that would be shown to the user. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### Bugfixes: * [ ] This pull request breaks the existing API * [ ] I've added tests to reproduce the issue which are now passing * [ ] I'm linking the issue being fixed by this PR ACKs for top commit: danielabrozzoni: utACK 9d85c96 Tree-SHA512: 9a06758cba61ade73198f35b08070987d5eb065e01750ce62409f86b37cd0b0894640e9f75c8b2c26543c0da04e3f77bd397fab540e789f221661aae828db224
- Loading branch information