Skip to content

Commit a624501

Browse files
committed
Upgrade to LDK v0.0.123-beta
1 parent 71b1d3c commit a624501

File tree

9 files changed

+120
-100
lines changed

9 files changed

+120
-100
lines changed

Cargo.toml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ panic = 'abort' # Abort on panic
2828
default = []
2929

3030
[dependencies]
31-
lightning = { version = "0.0.121", features = ["std"] }
32-
lightning-invoice = { version = "0.29.0" }
33-
lightning-net-tokio = { version = "0.0.121" }
34-
lightning-persister = { version = "0.0.121" }
35-
lightning-background-processor = { version = "0.0.121", features = ["futures"] }
36-
lightning-rapid-gossip-sync = { version = "0.0.121" }
37-
lightning-transaction-sync = { version = "0.0.121", features = ["esplora-async-https", "time"] }
38-
lightning-liquidity = { version = "0.1.0-alpha.1", features = ["std"] }
31+
lightning = { version = "0.0.123-beta", features = ["std"] }
32+
lightning-invoice = { version = "0.31.0-beta" }
33+
lightning-net-tokio = { version = "0.0.123-beta" }
34+
lightning-persister = { version = "0.0.123-beta" }
35+
lightning-background-processor = { version = "0.0.123-beta", features = ["futures"] }
36+
lightning-rapid-gossip-sync = { version = "0.0.123-beta" }
37+
lightning-transaction-sync = { version = "0.0.123-beta", features = ["esplora-async-https", "time"] }
38+
#lightning-liquidity = { version = "0.1.0-alpha.1", features = ["std"] }
39+
40+
lightning-liquidity = { git = "https://github.com/tnull/lightning-liquidity", rev = "abf7088c0e03221c0f122e797f34802c9e99a3d4", features = ["std"] }
3941

4042
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std"] }
4143
#lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main" }
@@ -78,7 +80,7 @@ prost = { version = "0.11.6", default-features = false}
7880
winapi = { version = "0.3", features = ["winbase"] }
7981

8082
[dev-dependencies]
81-
lightning = { version = "0.0.121", features = ["std", "_test_utils"] }
83+
lightning = { version = "0.0.123-beta", features = ["std", "_test_utils"] }
8284
#lightning = { git = "https://github.com/lightningdevkit/rust-lightning", branch="main", features = ["std", "_test_utils"] }
8385
electrum-client = { version = "0.15.1", default-features = true }
8486
bitcoincore-rpc = { version = "0.17.0", default-features = false }

bindings/ldk_node.udl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,19 @@ enum PaymentFailureReason {
190190

191191
[Enum]
192192
interface ClosureReason {
193-
CounterpartyForceClosed ( UntrustedString peer_msg );
194-
HolderForceClosed ();
195-
CooperativeClosure ();
196-
CommitmentTxConfirmed ();
197-
FundingTimedOut ();
198-
ProcessingError ( string err );
199-
DisconnectedPeer ();
200-
OutdatedChannelManager ();
201-
CounterpartyCoopClosedUnfundedChannel ();
202-
FundingBatchClosure ();
193+
CounterpartyForceClosed(UntrustedString peer_msg);
194+
HolderForceClosed();
195+
LegacyCooperativeClosure();
196+
CounterpartyInitiatedCooperativeClosure();
197+
LocallyInitiatedCooperativeClosure();
198+
CommitmentTxConfirmed();
199+
FundingTimedOut();
200+
ProcessingError(string err);
201+
DisconnectedPeer();
202+
OutdatedChannelManager();
203+
CounterpartyCoopClosedUnfundedChannel();
204+
FundingBatchClosure();
205+
HTLCsTimedOut();
203206
};
204207

205208
enum PaymentDirection {

src/builder.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::peer_store::PeerStore;
1515
use crate::sweep::OutputSweeper;
1616
use crate::tx_broadcaster::TransactionBroadcaster;
1717
use crate::types::{
18-
ChainMonitor, ChannelManager, FakeMessageRouter, GossipSync, KeysManager, NetworkGraph,
18+
ChainMonitor, ChannelManager, GossipSync, KeysManager, MessageRouter, NetworkGraph,
1919
OnionMessenger, PeerManager,
2020
};
2121
use crate::wallet::Wallet;
@@ -664,7 +664,7 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
664664
let router = Arc::new(DefaultRouter::new(
665665
Arc::clone(&network_graph),
666666
Arc::clone(&logger),
667-
keys_manager.get_secure_random_bytes(),
667+
Arc::clone(&keys_manager),
668668
Arc::clone(&scorer),
669669
scoring_fee_params,
670670
));
@@ -776,12 +776,15 @@ fn build_with_store_internal<K: KVStore + Sync + Send + 'static>(
776776
})?;
777777
}
778778

779+
let message_router = MessageRouter::new(Arc::clone(&network_graph), Arc::clone(&keys_manager));
780+
779781
// Initialize the PeerManager
780-
let onion_messenger: Arc<OnionMessenger> = Arc::new(OnionMessenger::new(
782+
let onion_messenger: Arc<OnionMessenger<K>> = Arc::new(OnionMessenger::new(
781783
Arc::clone(&keys_manager),
782784
Arc::clone(&keys_manager),
783785
Arc::clone(&logger),
784-
Arc::new(FakeMessageRouter {}),
786+
Arc::clone(&channel_manager),
787+
Arc::new(message_router),
785788
IgnoringMessageHandler {},
786789
IgnoringMessageHandler {},
787790
));

src/event.rs

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ where
347347
let confirmation_target = ConfirmationTarget::NonAnchorChannelFee;
348348

349349
// We set nLockTime to the current height to discourage fee sniping.
350-
let cur_height = self.channel_manager.current_best_block().height();
350+
let cur_height = self.channel_manager.current_best_block().height;
351351
let locktime = LockTime::from_height(cur_height).unwrap_or(LockTime::ZERO);
352352

353353
// Sign the final funding transaction and broadcast it.
@@ -474,7 +474,7 @@ where
474474
amount_msat,
475475
);
476476
let payment_preimage = match purpose {
477-
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret } => {
477+
PaymentPurpose::Bolt11InvoicePayment { payment_preimage, payment_secret } => {
478478
if payment_preimage.is_some() {
479479
payment_preimage
480480
} else {
@@ -483,6 +483,26 @@ where
483483
.ok()
484484
}
485485
},
486+
PaymentPurpose::Bolt12OfferPayment { .. } => {
487+
// TODO: support BOLT12.
488+
log_error!(
489+
self.logger,
490+
"Failed to claim unsupported BOLT12 payment with hash: {}",
491+
payment_hash
492+
);
493+
self.channel_manager.fail_htlc_backwards(&payment_hash);
494+
return;
495+
},
496+
PaymentPurpose::Bolt12RefundPayment { .. } => {
497+
// TODO: support BOLT12.
498+
log_error!(
499+
self.logger,
500+
"Failed to claim unsupported BOLT12 payment with hash: {}",
501+
payment_hash
502+
);
503+
self.channel_manager.fail_htlc_backwards(&payment_hash);
504+
return;
505+
},
486506
PaymentPurpose::SpontaneousPayment(preimage) => Some(preimage),
487507
};
488508

@@ -521,7 +541,11 @@ where
521541
amount_msat,
522542
);
523543
match purpose {
524-
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
544+
PaymentPurpose::Bolt11InvoicePayment {
545+
payment_preimage,
546+
payment_secret,
547+
..
548+
} => {
525549
let update = PaymentDetailsUpdate {
526550
preimage: Some(payment_preimage),
527551
secret: Some(Some(payment_secret)),
@@ -550,6 +574,24 @@ where
550574
},
551575
}
552576
},
577+
PaymentPurpose::Bolt12OfferPayment { .. } => {
578+
// TODO: support BOLT12.
579+
log_error!(
580+
self.logger,
581+
"Failed to claim unsupported BOLT12 payment with hash: {}",
582+
payment_hash
583+
);
584+
return;
585+
},
586+
PaymentPurpose::Bolt12RefundPayment { .. } => {
587+
// TODO: support BOLT12.
588+
log_error!(
589+
self.logger,
590+
"Failed to claim unsupported BOLT12 payment with hash: {}",
591+
payment_hash
592+
);
593+
return;
594+
},
553595
PaymentPurpose::SpontaneousPayment(preimage) => {
554596
let payment = PaymentDetails {
555597
preimage: Some(preimage),
@@ -717,9 +759,10 @@ where
717759
LdkEvent::PaymentForwarded {
718760
prev_channel_id,
719761
next_channel_id,
720-
fee_earned_msat,
762+
total_fee_earned_msat,
721763
claim_from_onchain_tx,
722764
outbound_amount_forwarded_msat,
765+
..
723766
} => {
724767
let read_only_network_graph = self.network_graph.read_only();
725768
let nodes = read_only_network_graph.nodes();
@@ -752,7 +795,7 @@ where
752795
let to_next_str =
753796
format!(" to {}{}", node_str(&next_channel_id), channel_str(&next_channel_id));
754797

755-
let fee_earned = fee_earned_msat.unwrap_or(0);
798+
let fee_earned = total_fee_earned_msat.unwrap_or(0);
756799
let outbound_amount_forwarded_msat = outbound_amount_forwarded_msat.unwrap_or(0);
757800
if claim_from_onchain_tx {
758801
log_info!(
@@ -780,6 +823,7 @@ where
780823
former_temporary_channel_id,
781824
counterparty_node_id,
782825
funding_txo,
826+
..
783827
} => {
784828
log_info!(
785829
self.logger,

src/fee_estimator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ where
4242
ConfirmationTarget::AnchorChannelFee,
4343
ConfirmationTarget::NonAnchorChannelFee,
4444
ConfirmationTarget::ChannelCloseMinimum,
45+
ConfirmationTarget::OutputSpendingFee,
4546
];
4647
for target in confirmation_targets {
4748
let num_blocks = match target {
@@ -51,6 +52,7 @@ where
5152
ConfirmationTarget::AnchorChannelFee => 1008,
5253
ConfirmationTarget::NonAnchorChannelFee => 12,
5354
ConfirmationTarget::ChannelCloseMinimum => 144,
55+
ConfirmationTarget::OutputSpendingFee => 12,
5456
};
5557

5658
let estimates = self.esplora_client.get_fee_estimates().await.map_err(|e| {
@@ -119,6 +121,7 @@ where
119121
ConfirmationTarget::AnchorChannelFee => 500,
120122
ConfirmationTarget::NonAnchorChannelFee => 1000,
121123
ConfirmationTarget::ChannelCloseMinimum => 500,
124+
ConfirmationTarget::OutputSpendingFee => 1000,
122125
};
123126

124127
// We'll fall back on this, if we really don't have any other information.

src/lib.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub use error::Error as NodeError;
107107
use error::Error;
108108

109109
pub use event::Event;
110-
pub use types::{BestBlock, ChannelConfig};
110+
pub use types::ChannelConfig;
111111

112112
pub use io::utils::generate_entropy_mnemonic;
113113

@@ -138,7 +138,7 @@ pub use types::{ChannelDetails, PeerDetails, UserChannelId};
138138

139139
use logger::{log_error, log_info, log_trace, FilesystemLogger, Logger};
140140

141-
use lightning::chain::Confirm;
141+
use lightning::chain::{BestBlock, Confirm};
142142
use lightning::ln::channelmanager::{self, PaymentId, RecipientOnionFields, Retry};
143143
use lightning::ln::msgs::SocketAddress;
144144
use lightning::ln::{PaymentHash, PaymentPreimage};
@@ -157,7 +157,6 @@ use lightning_transaction_sync::EsploraSyncClient;
157157
use lightning::routing::router::{PaymentParameters, RouteParameters};
158158
use lightning_invoice::{payment, Bolt11Invoice, Currency};
159159

160-
use bitcoin::hashes::sha256::Hash as Sha256;
161160
use bitcoin::hashes::Hash;
162161
use bitcoin::secp256k1::PublicKey;
163162

@@ -515,9 +514,9 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
515514
}
516515
_ = interval.tick() => {
517516
let pm_peers = connect_pm
518-
.get_peer_node_ids()
517+
.list_peers()
519518
.iter()
520-
.map(|(peer, _addr)| *peer)
519+
.map(|peer| peer.counterparty_node_id)
521520
.collect::<Vec<_>>();
522521

523522
for peer_info in connect_peer_store.list_peers().iter().filter(|info| !pm_peers.contains(&info.node_id)) {
@@ -579,7 +578,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
579578
continue;
580579
}
581580

582-
if bcast_pm.get_peer_node_ids().is_empty() {
581+
if bcast_pm.list_peers().is_empty() {
583582
// Skip if we don't have any connected peers to gossip to.
584583
continue;
585584
}
@@ -1301,7 +1300,7 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
13011300
}
13021301

13031302
let payment_preimage = PaymentPreimage(self.keys_manager.get_secure_random_bytes());
1304-
let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0).to_byte_array());
1303+
let payment_hash = PaymentHash::from(payment_preimage);
13051304

13061305
if let Some(payment) = self.payment_store.get(&payment_hash) {
13071306
if payment.status == PaymentStatus::Pending
@@ -1690,11 +1689,9 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
16901689

16911690
let mut total_lightning_balance_sats = 0;
16921691
let mut lightning_balances = Vec::new();
1693-
for funding_txo in self.chain_monitor.list_monitors() {
1692+
for (funding_txo, channel_id) in self.chain_monitor.list_monitors() {
16941693
match self.chain_monitor.get_monitor(funding_txo) {
16951694
Ok(monitor) => {
1696-
// TODO: Switch to `channel_id` with LDK 0.0.122: let channel_id = monitor.channel_id();
1697-
let channel_id = funding_txo.to_channel_id();
16981695
// unwrap safety: `get_counterparty_node_id` will always be `Some` after 0.0.110 and
16991696
// LDK Node 0.1 depended on 0.0.115 already.
17001697
let counterparty_node_id = monitor.get_counterparty_node_id().unwrap();
@@ -1758,12 +1755,13 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
17581755
let mut peers = Vec::new();
17591756

17601757
// First add all connected peers, preferring to list the connected address if available.
1761-
let connected_peers = self.peer_manager.get_peer_node_ids();
1758+
let connected_peers = self.peer_manager.list_peers();
17621759
let connected_peers_len = connected_peers.len();
1763-
for (node_id, con_addr_opt) in connected_peers {
1760+
for connected_peer in connected_peers {
1761+
let node_id = connected_peer.counterparty_node_id;
17641762
let stored_peer = self.peer_store.get_peer(&node_id);
17651763
let stored_addr_opt = stored_peer.as_ref().map(|p| p.address.clone());
1766-
let address = match (con_addr_opt, stored_addr_opt) {
1764+
let address = match (connected_peer.socket_address, stored_addr_opt) {
17671765
(Some(con_addr), _) => con_addr,
17681766
(None, Some(stored_addr)) => stored_addr,
17691767
(None, None) => continue,
@@ -1858,10 +1856,8 @@ async fn connect_peer_if_necessary<K: KVStore + Sync + Send + 'static>(
18581856
node_id: PublicKey, addr: SocketAddress, peer_manager: Arc<PeerManager<K>>,
18591857
logger: Arc<FilesystemLogger>,
18601858
) -> Result<(), Error> {
1861-
for (pman_node_id, _pman_addr) in peer_manager.get_peer_node_ids() {
1862-
if node_id == pman_node_id {
1863-
return Ok(());
1864-
}
1859+
if peer_manager.peer_by_node_id(&node_id).is_some() {
1860+
return Ok(());
18651861
}
18661862

18671863
do_connect_peer(node_id, addr, peer_manager, logger).await
@@ -1896,7 +1892,7 @@ async fn do_connect_peer<K: KVStore + Sync + Send + 'static>(
18961892
std::task::Poll::Pending => {},
18971893
}
18981894
// Avoid blocking the tokio context by sleeping a bit
1899-
match peer_manager.get_peer_node_ids().iter().find(|(id, _addr)| *id == node_id) {
1895+
match peer_manager.peer_by_node_id(&node_id) {
19001896
Some(_) => return Ok(()),
19011897
None => tokio::time::sleep(Duration::from_millis(10)).await,
19021898
}

src/sweep.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ where
199199
fn rebroadcast_if_necessary(&self) {
200200
let (cur_height, cur_hash) = {
201201
let best_block = self.best_block.lock().unwrap();
202-
(best_block.height(), best_block.block_hash())
202+
(best_block.height, best_block.block_hash)
203203
};
204204

205205
let mut respend_descriptors = Vec::new();
@@ -277,7 +277,7 @@ where
277277
}
278278

279279
fn prune_confirmed_outputs(&self) {
280-
let cur_height = self.best_block.lock().unwrap().height();
280+
let cur_height = self.best_block.lock().unwrap().height;
281281
let mut locked_outputs = self.outputs.lock().unwrap();
282282

283283
// Prune all outputs that have sufficient depth by now.
@@ -314,7 +314,7 @@ where
314314
&self, output_descriptors: &Vec<SpendableOutputDescriptor>, cur_height: u32,
315315
) -> Result<Transaction, ()> {
316316
let tx_feerate =
317-
self.fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee);
317+
self.fee_estimator.get_est_sat_per_1000_weight(ConfirmationTarget::OutputSpendingFee);
318318

319319
let destination_address = self.wallet.get_new_address().map_err(|e| {
320320
log_error!(self.logger, "Failed to get destination address from wallet: {}", e);
@@ -370,9 +370,9 @@ where
370370
) {
371371
{
372372
let best_block = self.best_block.lock().unwrap();
373-
assert_eq!(best_block.block_hash(), header.prev_blockhash,
373+
assert_eq!(best_block.block_hash, header.prev_blockhash,
374374
"Blocks must be connected in chain-order - the connected header must build on the last connected header");
375-
assert_eq!(best_block.height(), height - 1,
375+
assert_eq!(best_block.height, height - 1,
376376
"Blocks must be connected in chain-order - the connected block height must be one greater than the previous height");
377377
}
378378

@@ -384,9 +384,9 @@ where
384384
let new_height = height - 1;
385385
{
386386
let mut best_block = self.best_block.lock().unwrap();
387-
assert_eq!(best_block.block_hash(), header.block_hash(),
387+
assert_eq!(best_block.block_hash, header.block_hash(),
388388
"Blocks must be disconnected in chain-order - the disconnected header must be the last connected header");
389-
assert_eq!(best_block.height(), height,
389+
assert_eq!(best_block.height, height,
390390
"Blocks must be disconnected in chain-order - the disconnected block must have the correct height");
391391
*best_block = BestBlock::new(header.prev_blockhash, new_height)
392392
}

0 commit comments

Comments
 (0)