Skip to content

Commit 7b18024

Browse files
committed
WIP Async bumping
1 parent a12ceaf commit 7b18024

File tree

3 files changed

+110
-91
lines changed

3 files changed

+110
-91
lines changed

Cargo.toml

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,29 @@ default = []
5050
#lightning-transaction-sync = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main", features = ["esplora-async-https", "electrum", "time"] }
5151
#lightning-liquidity = { git = "https://github.com/lightningdevkit/rust-lightning", branch = "main" }
5252

53-
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b", features = ["std"] }
54-
lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
55-
lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b", features = ["std"] }
56-
lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
57-
lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
58-
lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
59-
lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
60-
lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b", features = ["rpc-client", "tokio"] }
61-
lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b", features = ["esplora-async-https", "electrum", "time"] }
62-
lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
63-
lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
64-
65-
#lightning = { path = "../rust-lightning/lightning", features = ["std"] }
66-
#lightning-types = { path = "../rust-lightning/lightning-types" }
67-
#lightning-invoice = { path = "../rust-lightning/lightning-invoice", features = ["std"] }
68-
#lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
69-
#lightning-persister = { path = "../rust-lightning/lightning-persister" }
70-
#lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
71-
#lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
72-
#lightning-block-sync = { path = "../rust-lightning/lightning-block-sync", features = ["rpc-client", "tokio"] }
73-
#lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async-https", "electrum", "time"] }
74-
#lightning-liquidity = { path = "../rust-lightning/lightning-liquidity", features = ["std"] }
53+
#lightning = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b", features = ["std"] }
54+
#lightning-types = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
55+
#lightning-invoice = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b", features = ["std"] }
56+
#lightning-net-tokio = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
57+
#lightning-persister = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
58+
#lightning-background-processor = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
59+
#lightning-rapid-gossip-sync = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
60+
#lightning-block-sync = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b", features = ["rpc-client", "tokio"] }
61+
#lightning-transaction-sync = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b", features = ["esplora-async-https", "electrum", "time"] }
62+
#lightning-liquidity = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
63+
#lightning-macros = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b" }
64+
65+
lightning = { path = "../rust-lightning/lightning", features = ["std"] }
66+
lightning-types = { path = "../rust-lightning/lightning-types" }
67+
lightning-invoice = { path = "../rust-lightning/lightning-invoice", features = ["std"] }
68+
lightning-net-tokio = { path = "../rust-lightning/lightning-net-tokio" }
69+
lightning-persister = { path = "../rust-lightning/lightning-persister" }
70+
lightning-background-processor = { path = "../rust-lightning/lightning-background-processor" }
71+
lightning-rapid-gossip-sync = { path = "../rust-lightning/lightning-rapid-gossip-sync" }
72+
lightning-block-sync = { path = "../rust-lightning/lightning-block-sync", features = ["rpc-client", "tokio"] }
73+
lightning-transaction-sync = { path = "../rust-lightning/lightning-transaction-sync", features = ["esplora-async-https", "electrum", "time"] }
74+
lightning-liquidity = { path = "../rust-lightning/lightning-liquidity", features = ["std"] }
75+
lightning-macros = { path = "../rust-lightning/lightning-macros" }
7576

7677
bdk_chain = { version = "0.21.1", default-features = false, features = ["std"] }
7778
bdk_esplora = { version = "0.20.1", default-features = false, features = ["async-https-rustls", "tokio"]}
@@ -105,8 +106,8 @@ winapi = { version = "0.3", features = ["winbase"] }
105106
[dev-dependencies]
106107
#lightning = { version = "0.1.0", features = ["std", "_test_utils"] }
107108
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
108-
lightning = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b", features = ["std", "_test_utils"] }
109-
#lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
109+
#lightning = { git = "https://github.com/tnull/rust-lightning", rev = "367d0cc495f55d8d50d36276136e873ea628f44b", features = ["std", "_test_utils"] }
110+
lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
110111
proptest = "1.0.0"
111112
regex = "1.5.6"
112113

src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ where
15001500
BumpTransactionEvent::HTLCResolution { .. } => {},
15011501
}
15021502

1503-
self.bump_tx_event_handler.handle_event(&bte);
1503+
self.bump_tx_event_handler.handle_event(&bte).await;
15041504
},
15051505
LdkEvent::OnionMessageIntercepted { .. } => {
15061506
debug_assert!(false, "We currently don't support onion message interception, so this event should never be emitted.");

src/wallet/mod.rs

Lines changed: 84 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl Wallet {
299299
#[cfg(debug_assertions)]
300300
if balance.confirmed != Amount::ZERO {
301301
debug_assert!(
302-
self.list_confirmed_utxos().map_or(false, |v| !v.is_empty()),
302+
self.list_confirmed_utxos_inner().map_or(false, |v| !v.is_empty()),
303303
"Confirmed amounts should always be available for Anchor spending"
304304
);
305305
}
@@ -549,70 +549,8 @@ impl Wallet {
549549

550550
Ok(txid)
551551
}
552-
}
553-
554-
impl Listen for Wallet {
555-
fn filtered_block_connected(
556-
&self, _header: &bitcoin::block::Header,
557-
_txdata: &lightning::chain::transaction::TransactionData, _height: u32,
558-
) {
559-
debug_assert!(false, "Syncing filtered blocks is currently not supported");
560-
// As far as we can tell this would be a no-op anyways as we don't have to tell BDK about
561-
// the header chain of intermediate blocks. According to the BDK team, it's sufficient to
562-
// only connect full blocks starting from the last point of disagreement.
563-
}
564-
565-
fn block_connected(&self, block: &bitcoin::Block, height: u32) {
566-
let mut locked_wallet = self.inner.lock().unwrap();
567-
568-
let pre_checkpoint = locked_wallet.latest_checkpoint();
569-
if pre_checkpoint.height() != height - 1
570-
|| pre_checkpoint.hash() != block.header.prev_blockhash
571-
{
572-
log_debug!(
573-
self.logger,
574-
"Detected reorg while applying a connected block to on-chain wallet: new block with hash {} at height {}",
575-
block.header.block_hash(),
576-
height
577-
);
578-
}
579-
580-
match locked_wallet.apply_block(block, height) {
581-
Ok(()) => {
582-
if let Err(e) = self.update_payment_store(&mut *locked_wallet) {
583-
log_error!(self.logger, "Failed to update payment store: {}", e);
584-
return;
585-
}
586-
},
587-
Err(e) => {
588-
log_error!(
589-
self.logger,
590-
"Failed to apply connected block to on-chain wallet: {}",
591-
e
592-
);
593-
return;
594-
},
595-
};
596552

597-
let mut locked_persister = self.persister.lock().unwrap();
598-
match locked_wallet.persist(&mut locked_persister) {
599-
Ok(_) => (),
600-
Err(e) => {
601-
log_error!(self.logger, "Failed to persist on-chain wallet: {}", e);
602-
return;
603-
},
604-
};
605-
}
606-
607-
fn block_disconnected(&self, _header: &bitcoin::block::Header, _height: u32) {
608-
// This is a no-op as we don't have to tell BDK about disconnections. According to the BDK
609-
// team, it's sufficient in case of a reorg to always connect blocks starting from the last
610-
// point of disagreement.
611-
}
612-
}
613-
614-
impl WalletSource for Wallet {
615-
fn list_confirmed_utxos(&self) -> Result<Vec<Utxo>, ()> {
553+
fn list_confirmed_utxos_inner(&self) -> Result<Vec<Utxo>, ()> {
616554
let locked_wallet = self.inner.lock().unwrap();
617555
let mut utxos = Vec::new();
618556
let confirmed_txs: Vec<Txid> = locked_wallet
@@ -704,7 +642,7 @@ impl WalletSource for Wallet {
704642
Ok(utxos)
705643
}
706644

707-
fn get_change_script(&self) -> Result<ScriptBuf, ()> {
645+
fn get_change_script_inner(&self) -> Result<ScriptBuf, ()> {
708646
let mut locked_wallet = self.inner.lock().unwrap();
709647
let mut locked_persister = self.persister.lock().unwrap();
710648

@@ -716,7 +654,7 @@ impl WalletSource for Wallet {
716654
Ok(address_info.address.script_pubkey())
717655
}
718656

719-
fn sign_psbt(&self, mut psbt: Psbt) -> Result<Transaction, ()> {
657+
fn sign_psbt_inner(&self, mut psbt: Psbt) -> Result<Transaction, ()> {
720658
let locked_wallet = self.inner.lock().unwrap();
721659

722660
// While BDK populates both `witness_utxo` and `non_witness_utxo` fields, LDK does not. As
@@ -746,6 +684,86 @@ impl WalletSource for Wallet {
746684
}
747685
}
748686

687+
impl Listen for Wallet {
688+
fn filtered_block_connected(
689+
&self, _header: &bitcoin::block::Header,
690+
_txdata: &lightning::chain::transaction::TransactionData, _height: u32,
691+
) {
692+
debug_assert!(false, "Syncing filtered blocks is currently not supported");
693+
// As far as we can tell this would be a no-op anyways as we don't have to tell BDK about
694+
// the header chain of intermediate blocks. According to the BDK team, it's sufficient to
695+
// only connect full blocks starting from the last point of disagreement.
696+
}
697+
698+
fn block_connected(&self, block: &bitcoin::Block, height: u32) {
699+
let mut locked_wallet = self.inner.lock().unwrap();
700+
701+
let pre_checkpoint = locked_wallet.latest_checkpoint();
702+
if pre_checkpoint.height() != height - 1
703+
|| pre_checkpoint.hash() != block.header.prev_blockhash
704+
{
705+
log_debug!(
706+
self.logger,
707+
"Detected reorg while applying a connected block to on-chain wallet: new block with hash {} at height {}",
708+
block.header.block_hash(),
709+
height
710+
);
711+
}
712+
713+
match locked_wallet.apply_block(block, height) {
714+
Ok(()) => {
715+
if let Err(e) = self.update_payment_store(&mut *locked_wallet) {
716+
log_error!(self.logger, "Failed to update payment store: {}", e);
717+
return;
718+
}
719+
},
720+
Err(e) => {
721+
log_error!(
722+
self.logger,
723+
"Failed to apply connected block to on-chain wallet: {}",
724+
e
725+
);
726+
return;
727+
},
728+
};
729+
730+
let mut locked_persister = self.persister.lock().unwrap();
731+
match locked_wallet.persist(&mut locked_persister) {
732+
Ok(_) => (),
733+
Err(e) => {
734+
log_error!(self.logger, "Failed to persist on-chain wallet: {}", e);
735+
return;
736+
},
737+
};
738+
}
739+
740+
fn block_disconnected(&self, _header: &bitcoin::block::Header, _height: u32) {
741+
// This is a no-op as we don't have to tell BDK about disconnections. According to the BDK
742+
// team, it's sufficient in case of a reorg to always connect blocks starting from the last
743+
// point of disagreement.
744+
}
745+
}
746+
747+
impl WalletSource for Wallet {
748+
fn list_confirmed_utxos<'a>(
749+
&'a self,
750+
) -> Pin<Box<dyn Future<Output = Result<Vec<Utxo>, ()>> + Send + 'a>> {
751+
Box::pin(async move { self.list_confirmed_utxos_inner() })
752+
}
753+
754+
fn get_change_script<'a>(
755+
&'a self,
756+
) -> Pin<Box<dyn Future<Output = Result<ScriptBuf, ()>> + Send + 'a>> {
757+
Box::pin(async move { self.get_change_script_inner() })
758+
}
759+
760+
fn sign_psbt<'a>(
761+
&'a self, psbt: Psbt,
762+
) -> Pin<Box<dyn Future<Output = Result<Transaction, ()>> + Send + 'a>> {
763+
Box::pin(async move { self.sign_psbt_inner(psbt) })
764+
}
765+
}
766+
749767
/// Similar to [`KeysManager`], but overrides the destination and shutdown scripts so they are
750768
/// directly spendable by the BDK wallet.
751769
pub(crate) struct WalletKeysManager {

0 commit comments

Comments
 (0)