[Bitcoin] Set Input Selector to UseAll
for Legacy Taproot Building/Signing
#3666
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(Context: We were debugging a BRC20 related issue in Wallet Kit)
So, this took us a while to figure out. One single change is required:
I did some playing around and technically, the existing code should have worked, but the issue is in
tw_utxo
; it does not consider the fees at all when selecting inputs. It does make a fee estimate after the inputs are selected and the issue eventually gets caught by the code:But of course, the input selector should consider fees in the first place when selecting inputs (@JaimeToca the reason we didn't get this specific error is because we used
byte_fee = 0
!). In order to implement this correctly, we'd need to iterate over each input and re-calculate the fee (estimation) on each iteration until we covertotal_output + fee_estimate
(or return an error if otherwise).This this PR makes sure that @JaimeToca can continue working on BRC20 support in Wallet Kit, but the situation is not ideal given that this is DANGEROUS: if the caller does not use
ANY_PLAN
first, the call toRust::tw_bitcoin_legacy_taproot_build_and_sign_transaction
will simply use-up ALL inputs WITHOUT generating a return transaction (meaning, the miner gets the full change amount as a reward). However, this might be fine given thatRust::tw_bitcoin_legacy_taproot_build_and_sign_transaction
already assumes that the change output is provided upfront by the caller anyway (we setdisable_change_output = true
). I let you (@satoshiotomakan) decide.Alternatively, I wrote a PoC implementation of how to do the input selection for covering fees correctly. But given that you're currently restructuring
tw_utxo
anyway then this might interfere with your plan:See #3667 for the full code. The tests look fine, but need to be adjusted because the fee is calculated slightly differently now. E.g: