Skip to content

Commit ab4df29

Browse files
committed
Merge #1812: fix(wallet): use map_keychain in Wallet::build_fee_bump
515309e test(wallet): test `build_fee_bump` with single descriptor wallet (valued mammal) 53d16e1 fix(wallet): use `map_keychain` in `Wallet::build_fee_bump` (valued mammal) Pull request description: Previously we failed to remove the change output if the wallet has no internal keychain which caused tx building to fail at the new higher feerate. Fix this by mapping the internal keychain to the de-facto change keychain so that the drain output can be recalculated. fixes #1807 ### Changelog notice Fixed - wallet: Fixed an issue preventing `build_fee_bump` from re-targeting the drain value for some wallets ### 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: * [x] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR ACKs for top commit: notmandatory: ACK 515309e evanlinjin: ACK 515309e Tree-SHA512: 53266c4b0f4a2ebc1fd47cd1c9afb4499fb3c46d75e8bd121a98644cfe879cebf5fa26fab0e6af706452aea79a959660149582dc8df9e53ada6582e62ea5be19
2 parents 9d7211d + 515309e commit ab4df29

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

crates/wallet/src/wallet/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,7 @@ impl Wallet {
16761676
if tx.output.len() > 1 {
16771677
let mut change_index = None;
16781678
for (index, txout) in tx.output.iter().enumerate() {
1679-
let change_keychain = KeychainKind::Internal;
1679+
let change_keychain = self.map_keychain(KeychainKind::Internal);
16801680
match txout_index.index_of_spk(txout.script_pubkey.clone()) {
16811681
Some((keychain, _)) if *keychain == change_keychain => {
16821682
change_index = Some(index)

crates/wallet/src/wallet/tx_builder.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,4 +1052,50 @@ mod test {
10521052
assert_eq!(filtered.len(), 1);
10531053
assert_eq!(filtered[0].keychain, KeychainKind::Internal);
10541054
}
1055+
1056+
#[test]
1057+
fn test_build_fee_bump_remove_change_output_single_desc() {
1058+
use crate::test_utils::*;
1059+
use bdk_chain::BlockId;
1060+
use bitcoin::{hashes::Hash, BlockHash, Network};
1061+
1062+
let mut wallet = Wallet::create_single(get_test_tr_single_sig())
1063+
.network(Network::Regtest)
1064+
.create_wallet_no_persist()
1065+
.unwrap();
1066+
1067+
insert_checkpoint(
1068+
&mut wallet,
1069+
BlockId {
1070+
height: 1,
1071+
hash: BlockHash::all_zeros(),
1072+
},
1073+
);
1074+
1075+
receive_output_in_latest_block(&mut wallet, Amount::ONE_BTC.to_sat());
1076+
1077+
// tx1 sending 15k sat to a recipient
1078+
let recip = ScriptBuf::from_hex(
1079+
"5120e8f5c4dc2f5d6a7595e7b108cb063da9c7550312da1e22875d78b9db62b59cd5",
1080+
)
1081+
.unwrap();
1082+
let mut builder = wallet.build_tx();
1083+
builder.add_recipient(recip.clone(), Amount::from_sat(15_000));
1084+
builder.fee_absolute(Amount::from_sat(1_000));
1085+
let psbt = builder.finish().unwrap();
1086+
1087+
let tx = psbt.extract_tx().unwrap();
1088+
let txid = tx.compute_txid();
1089+
let feerate = wallet.calculate_fee_rate(&tx).unwrap().to_sat_per_kwu();
1090+
insert_tx(&mut wallet, tx);
1091+
1092+
// build fee bump
1093+
let mut builder = wallet.build_fee_bump(txid).unwrap();
1094+
assert_eq!(
1095+
builder.params.recipients,
1096+
vec![(recip, Amount::from_sat(15_000))]
1097+
);
1098+
builder.fee_rate(FeeRate::from_sat_per_kwu(feerate + 250));
1099+
let _ = builder.finish().unwrap();
1100+
}
10551101
}

0 commit comments

Comments
 (0)