-
Notifications
You must be signed in to change notification settings - Fork 44
fix(wallet): Don't fail in build_fee_bump for missing parent txid
#337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ValuedMammal
wants to merge
2
commits into
bitcoindevkit:master
Choose a base branch
from
ValuedMammal:fix/build_fee_bump_foreign_utxo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,9 @@ use bdk_wallet::signer::SignOptions; | |
| use bdk_wallet::test_utils::*; | ||
| use bdk_wallet::tx_builder::AddForeignUtxoError; | ||
| use bdk_wallet::KeychainKind; | ||
| use bitcoin::{psbt, Address, Amount}; | ||
| use bitcoin::{hashes::Hash, psbt, Address, Amount, FeeRate, OutPoint, TxOut, Weight}; | ||
|
|
||
| use common::parse_descriptor; | ||
|
|
||
| mod common; | ||
|
|
||
|
|
@@ -290,3 +292,53 @@ fn test_taproot_foreign_utxo() { | |
| "foreign_utxo should be in there" | ||
| ); | ||
| } | ||
|
|
||
| // Test that we can fee-bump a tx containing a foreign utxo | ||
| #[test] | ||
| fn test_add_foreign_utxo_build_fee_bump() { | ||
| let (mut wallet, _) = get_funded_wallet_wpkh(); | ||
| let drain_spk = wallet | ||
| .next_unused_address(KeychainKind::External) | ||
| .script_pubkey(); | ||
|
|
||
| let (desc, _) = parse_descriptor(get_test_tr_single_sig()); | ||
| let spk = desc.at_derivation_index(0).unwrap().script_pubkey(); | ||
| let witness_utxo = TxOut { | ||
| value: Amount::ONE_SAT, | ||
| script_pubkey: spk, | ||
| }; | ||
| // Remember to include this as a "floating" txout in the wallet. | ||
| let outpoint = OutPoint::new(Hash::hash(b"prev"), 1); | ||
| wallet.insert_txout(outpoint, witness_utxo.clone()); | ||
| let satisfaction_weight = Weight::from_wu(71); | ||
| let psbt_input = psbt::Input { | ||
| witness_utxo: Some(witness_utxo), | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let mut tx_builder = wallet.build_tx(); | ||
| tx_builder | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default fee rate of this tx is important but not expressed in the creation of the first tx of the test. A comment may be necessary here. |
||
| .add_foreign_utxo(outpoint, psbt_input, satisfaction_weight) | ||
| .unwrap() | ||
| .only_witness_utxo() | ||
| .fee_rate(FeeRate::from_sat_per_vb_unchecked(2)) | ||
| .drain_to(drain_spk.clone()); | ||
| let psbt = tx_builder.finish().unwrap(); | ||
| let tx = psbt.unsigned_tx.clone(); | ||
| assert!(tx.input.iter().any(|txin| txin.previous_output == outpoint)); | ||
| let txid1 = tx.compute_txid(); | ||
| wallet.apply_unconfirmed_txs([(tx, 123456)]); | ||
|
|
||
| // Now build fee bump. | ||
| let mut tx_builder = wallet | ||
| .build_fee_bump(txid1) | ||
| .expect("`build_fee_bump` should succeed"); | ||
| tx_builder | ||
| .set_recipients(vec![]) | ||
| .drain_to(drain_spk) | ||
| .only_witness_utxo() | ||
| .fee_rate(FeeRate::from_sat_per_vb_unchecked(5)); | ||
| let psbt = tx_builder.finish().unwrap(); | ||
| let tx = &psbt.unsigned_tx; | ||
| assert!(tx.input.iter().any(|txin| txin.previous_output == outpoint)); | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale to not use
calculate_fee_rate?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed redundant since
calculate_fee_ratealready callscalculate_fee, so I chose to inline the implementation here.