Skip to content

Commit 678732d

Browse files
committed
Bump BDK wallet dependencies
Update the direct BDK wallet stack to the latest crate releases. This lets follow-up wallet event code use the upstream BDK API. It also preserves temporary transaction cleanup after BDK removed its cancel_tx helper. Co-Authored-By: HAL 9000
1 parent 8a54260 commit 678732d

4 files changed

Lines changed: 27 additions & 19 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning
5454
lightning-macros = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }
5555
lightning-dns-resolver = { git = "https://github.com/lightningdevkit/rust-lightning", rev = "3dfcc4cca1866c5e5d4d4eaf3b82e09584e2ce5c" }
5656

57-
bdk_chain = { version = "0.23.0", default-features = false, features = ["std"] }
58-
bdk_esplora = { version = "0.22.0", default-features = false, features = ["async-https-rustls", "tokio"]}
57+
bdk_chain = { version = "0.23.3", default-features = false, features = ["std"] }
58+
bdk_esplora = { version = "0.22.2", default-features = false, features = ["async-https-rustls", "tokio"]}
5959
bdk_electrum = { version = "0.24.0", default-features = false, features = ["use-rustls-ring"]}
60-
bdk_wallet = { version = "2.3.0", default-features = false, features = ["std", "keys-bip39"]}
60+
bdk_wallet = { version = "3.1.0", default-features = false, features = ["std", "keys-bip39"]}
6161

6262
bitreq = { version = "0.3", default-features = false, features = ["async-https", "json-using-serde"] }
6363
rustls = { version = "0.23", default-features = false }

src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ where
16481648
})
16491649
.collect(),
16501650
};
1651-
if let Err(e) = self.wallet.cancel_tx(&tx) {
1651+
if let Err(e) = self.wallet.cancel_tx(tx) {
16521652
log_error!(self.logger, "Failed reclaiming unused addresses: {}", e);
16531653
return Err(ReplayEvent());
16541654
}

src/wallet/mod.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ use std::sync::{Arc, Mutex};
1313
use bdk_chain::spk_client::{FullScanRequest, SyncRequest};
1414
use bdk_wallet::descriptor::ExtendedDescriptor;
1515
use bdk_wallet::error::{BuildFeeBumpError, CreateTxError};
16-
use bdk_wallet::event::WalletEvent;
1716
#[allow(deprecated)]
1817
use bdk_wallet::SignOptions;
19-
use bdk_wallet::{Balance, KeychainKind, PersistedWallet, Update};
18+
use bdk_wallet::{Balance, KeychainKind, PersistedWallet, Update, WalletEvent};
2019
use bitcoin::address::NetworkUnchecked;
2120
use bitcoin::blockdata::constants::WITNESS_SCALE_FACTOR;
2221
use bitcoin::blockdata::locktime::absolute::LockTime;
@@ -513,11 +512,11 @@ impl Wallet {
513512
Ok(address_info.address)
514513
}
515514

516-
pub(crate) fn cancel_tx(&self, tx: &Transaction) -> Result<(), Error> {
515+
pub(crate) fn cancel_tx(&self, tx: Transaction) -> Result<(), Error> {
517516
let mut locked_wallet = self.inner.lock().expect("lock");
518517
let mut locked_persister = self.persister.lock().expect("lock");
519518

520-
locked_wallet.cancel_tx(tx);
519+
Self::cancel_tx_inner(&mut locked_wallet, tx);
521520
self.runtime.block_on(locked_wallet.persist_async(&mut locked_persister)).map_err(|e| {
522521
log_error!(self.logger, "Failed to persist wallet: {}", e);
523522
Error::PersistenceFailed
@@ -526,6 +525,17 @@ impl Wallet {
526525
Ok(())
527526
}
528527

528+
fn cancel_tx_inner(
529+
locked_wallet: &mut PersistedWallet<KVStoreWalletPersister>, tx: Transaction,
530+
) {
531+
for txout in tx.output {
532+
if let Some((keychain, index)) = locked_wallet.derivation_of_spk(txout.script_pubkey) {
533+
// This mirrors the removed BDK helper: it only frees superficial usage marks.
534+
locked_wallet.unmark_used(keychain, index);
535+
}
536+
}
537+
}
538+
529539
pub(crate) fn get_balances(
530540
&self, total_anchor_channels_reserve_sats: u64,
531541
) -> Result<(u64, u64), Error> {
@@ -678,7 +688,7 @@ impl Wallet {
678688
None,
679689
)?;
680690

681-
locked_wallet.cancel_tx(&tmp_psbt.unsigned_tx);
691+
Self::cancel_tx_inner(&mut locked_wallet, tmp_psbt.unsigned_tx);
682692

683693
Ok(max_amount)
684694
}
@@ -708,7 +718,7 @@ impl Wallet {
708718
Some(&shared_input),
709719
)?;
710720

711-
locked_wallet.cancel_tx(&tmp_psbt.unsigned_tx);
721+
Self::cancel_tx_inner(&mut locked_wallet, tmp_psbt.unsigned_tx);
712722

713723
Ok(splice_amount)
714724
}
@@ -764,7 +774,7 @@ impl Wallet {
764774
e
765775
})?;
766776

767-
locked_wallet.cancel_tx(&tmp_psbt.unsigned_tx);
777+
Self::cancel_tx_inner(&mut locked_wallet, tmp_psbt.unsigned_tx);
768778

769779
let mut tx_builder = locked_wallet.build_tx();
770780
tx_builder

tests/integration_tests_rust.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,15 +1175,13 @@ async fn splice_channel() {
11751175
expect_channel_ready_event!(node_b, node_a.node_id());
11761176

11771177
let expected_splice_in_fee_sat = 251;
1178-
let expected_splice_in_onchain_cost_sat = 254;
1178+
let expected_splice_in_onchain_cost_sat = 253;
11791179

1180-
// LDK's fee calculation differs from BDK wallet's, which over pays on fees. Rather than giving
1181-
// the extra fees to the miner, LDK sends it to the channel balance since there may not be a
1182-
// change output.
1183-
//
1184-
// TODO: Some of the discrepancy is addressed upstream, so this number should be adjusted when
1185-
// updating the BDK wallet dependency. See: https://github.com/bitcoindevkit/bdk_wallet/pull/479
1186-
let expected_splice_in_lightning_balance_sat = 4_000_003;
1180+
// BDK 3.1.0 avoids the previous per-UTXO fee rounding during coin selection. Keep the
1181+
// remaining 2-sat LDK/BDK fee-accounting drift explicit so a dependency change cannot silently
1182+
// reintroduce the larger surplus. Rather than giving the extra sats to the miner, LDK sends
1183+
// them to the channel balance since there may not be a change output.
1184+
let expected_splice_in_lightning_balance_sat = 4_000_002;
11871185

11881186
let payments = node_b.list_payments();
11891187
let payment =

0 commit comments

Comments
 (0)