Skip to content

Commit

Permalink
WIP: Update to LDK 0.0.123.
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinewallace committed May 6, 2024
1 parent e6dd91c commit 49bb446
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 49 deletions.
45 changes: 23 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
lightning = { version = "0.0.121", features = ["max_level_trace"] }
lightning-block-sync = { version = "0.0.121", features = [ "rpc-client", "tokio" ] }
lightning-invoice = { version = "0.29.0" }
lightning-net-tokio = { version = "0.0.121" }
lightning-persister = { version = "0.0.121" }
lightning-background-processor = { version = "0.0.121", features = [ "futures" ] }
lightning-rapid-gossip-sync = { version = "0.0.121" }
lightning = { git = "https://github.com/lightningdevkit/rust-lightning.git", rev = "37c431a", features = ["max_level_trace"] }
lightning-block-sync = { git = "https://github.com/lightningdevkit/rust-lightning.git", rev = "37c431a", features = [ "rpc-client", "tokio" ] }
lightning-invoice = { git = "https://github.com/lightningdevkit/rust-lightning.git", rev = "37c431a" }
lightning-net-tokio = { git = "https://github.com/lightningdevkit/rust-lightning.git", rev = "37c431a" }
lightning-persister = { git = "https://github.com/lightningdevkit/rust-lightning.git", rev = "37c431a" }
lightning-background-processor = { git = "https://github.com/lightningdevkit/rust-lightning.git", rev = "37c431a", features = [ "futures" ] }
lightning-rapid-gossip-sync = { git = "https://github.com/lightningdevkit/rust-lightning.git", rev = "37c431a" }

base64 = "0.13.0"
bitcoin = "0.30.2"
Expand Down
23 changes: 14 additions & 9 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ pub(crate) fn poll_for_user_input(
);
},
"getoffer" => {
let offer_builder = channel_manager.create_offer_builder(String::new());
let offer_builder = channel_manager.create_offer_builder();
if let Err(e) = offer_builder {
println!("ERROR: Failed to initiate offer building: {:?}", e);
continue;
Expand Down Expand Up @@ -603,14 +603,14 @@ fn node_info(channel_manager: &Arc<ChannelManager>, peer_manager: &Arc<PeerManag
println!("\t\t num_usable_channels: {}", chans.iter().filter(|c| c.is_usable).count());
let local_balance_msat = chans.iter().map(|c| c.balance_msat).sum::<u64>();
println!("\t\t local_balance_msat: {}", local_balance_msat);
println!("\t\t num_peers: {}", peer_manager.get_peer_node_ids().len());
println!("\t\t num_peers: {}", peer_manager.list_peers().len());
println!("\t}},");
}

fn list_peers(peer_manager: Arc<PeerManager>) {
println!("\t{{");
for (pubkey, _) in peer_manager.get_peer_node_ids() {
println!("\t\t pubkey: {}", pubkey);
for peer_details in peer_manager.list_peers() {
println!("\t\t pubkey: {}", peer_details.counterparty_node_id);
}
println!("\t}},");
}
Expand Down Expand Up @@ -701,8 +701,8 @@ fn list_payments(
pub(crate) async fn connect_peer_if_necessary(
pubkey: PublicKey, peer_addr: SocketAddr, peer_manager: Arc<PeerManager>,
) -> Result<(), ()> {
for (node_pubkey, _) in peer_manager.get_peer_node_ids() {
if node_pubkey == pubkey {
for peer_details in peer_manager.list_peers() {
if peer_details.counterparty_node_id == pubkey {
return Ok(());
}
}
Expand All @@ -725,7 +725,12 @@ pub(crate) async fn do_connect_peer(
_ = &mut connection_closed_future => return Err(()),
_ = tokio::time::sleep(Duration::from_millis(10)) => {},
};
if peer_manager.get_peer_node_ids().iter().find(|(id, _)| *id == pubkey).is_some() {
if peer_manager
.list_peers()
.iter()
.find(|peer| peer.counterparty_node_id == pubkey)
.is_some()
{
return Ok(());
}
}
Expand All @@ -747,8 +752,8 @@ fn do_disconnect_peer(
}

//check the pubkey matches a valid connected peer
let peers = peer_manager.get_peer_node_ids();
if !peers.iter().any(|(pk, _)| &pubkey == pk) {
let peers = peer_manager.list_peers();
if !peers.iter().any(|peer| peer.counterparty_node_id == pubkey) {
println!("Error: Could not find peer {}", pubkey);
return Err(());
}
Expand Down
30 changes: 21 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ async fn handle_ldk_events(
print!("> ");
io::stdout().flush().unwrap();
let payment_preimage = match purpose {
PaymentPurpose::InvoicePayment { payment_preimage, .. } => payment_preimage,
PaymentPurpose::Bolt11InvoicePayment { payment_preimage, .. } => payment_preimage,
PaymentPurpose::Bolt12OfferPayment { payment_preimage, .. } => payment_preimage,
PaymentPurpose::Bolt12RefundPayment { payment_preimage, .. } => payment_preimage,
PaymentPurpose::SpontaneousPayment(preimage) => Some(preimage),
};
channel_manager.claim_funds(payment_preimage.unwrap());
Expand All @@ -267,9 +269,15 @@ async fn handle_ldk_events(
print!("> ");
io::stdout().flush().unwrap();
let (payment_preimage, payment_secret) = match purpose {
PaymentPurpose::InvoicePayment { payment_preimage, payment_secret, .. } => {
PaymentPurpose::Bolt11InvoicePayment {
payment_preimage, payment_secret, ..
} => (payment_preimage, Some(payment_secret)),
PaymentPurpose::Bolt12OfferPayment { payment_preimage, payment_secret, .. } => {
(payment_preimage, Some(payment_secret))
},
PaymentPurpose::Bolt12RefundPayment {
payment_preimage, payment_secret, ..
} => (payment_preimage, Some(payment_secret)),
PaymentPurpose::SpontaneousPayment(preimage) => (Some(preimage), None),
};
let mut inbound = inbound_payments.lock().unwrap();
Expand Down Expand Up @@ -381,9 +389,12 @@ async fn handle_ldk_events(
Event::PaymentForwarded {
prev_channel_id,
next_channel_id,
fee_earned_msat,
total_fee_earned_msat,
claim_from_onchain_tx,
outbound_amount_forwarded_msat,
skimmed_fee_msat: _,
prev_user_channel_id: _,
next_user_channel_id: _,
} => {
let read_only_network_graph = network_graph.read_only();
let nodes = read_only_network_graph.nodes();
Expand Down Expand Up @@ -426,7 +437,7 @@ async fn handle_ldk_events(
} else {
"?".to_string()
};
if let Some(fee_earned) = fee_earned_msat {
if let Some(fee_earned) = total_fee_earned_msat {
println!(
"\nEVENT: Forwarded payment for {} msat{}{}, earning {} msat {}",
amt_args, from_prev_str, to_next_str, fee_earned, from_onchain_str
Expand Down Expand Up @@ -677,7 +688,7 @@ async fn start_ldk() {
let router = Arc::new(DefaultRouter::new(
network_graph.clone(),
logger.clone(),
keys_manager.get_secure_random_bytes(),
keys_manager.clone(),
scorer.clone(),
scoring_fee_params,
));
Expand Down Expand Up @@ -712,7 +723,7 @@ async fn start_ldk() {
restarting_node = false;

let polled_best_block = polled_chain_tip.to_best_block();
let polled_best_block_hash = polled_best_block.block_hash();
let polled_best_block_hash = polled_best_block.block_hash;
let chain_params =
ChainParameters { network: args.network, best_block: polled_best_block };
let fresh_channel_manager = channelmanager::ChannelManager::new(
Expand Down Expand Up @@ -789,7 +800,8 @@ async fn start_ldk() {
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&logger),
Arc::new(DefaultMessageRouter::new(Arc::clone(&network_graph))),
Arc::clone(&channel_manager),
Arc::new(DefaultMessageRouter::new(Arc::clone(&network_graph), Arc::clone(&keys_manager))),
Arc::clone(&channel_manager),
IgnoringMessageHandler {},
));
Expand Down Expand Up @@ -969,12 +981,12 @@ async fn start_ldk() {
interval.tick().await;
match disk::read_channel_peer_data(Path::new(&peer_data_path)) {
Ok(info) => {
let peers = connect_pm.get_peer_node_ids();
let peers = connect_pm.list_peers();
for node_id in connect_cm
.list_channels()
.iter()
.map(|chan| chan.counterparty.node_id)
.filter(|id| !peers.iter().any(|(pk, _)| id == pk))
.filter(|id| !peers.iter().any(|peer| peer.counterparty_node_id == *id))
{
if stop_connect.load(Ordering::Acquire) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Duration;
use std::{fs, io};

use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
use lightning::sign::{EntropySource, KeysManager, SpendableOutputDescriptor};
use lightning::sign::{EntropySource, KeysManager, OutputSpender, SpendableOutputDescriptor};
use lightning::util::logger::Logger;
use lightning::util::persist::KVStore;
use lightning::util::ser::{Readable, WithoutLength, Writeable};
Expand Down Expand Up @@ -118,7 +118,7 @@ pub(crate) async fn periodic_sweep(
// e.g. high-latency mix networks and some CoinJoin implementations, have
// better privacy.
// Logic copied from core: https://github.com/bitcoin/bitcoin/blob/1d4846a8443be901b8a5deb0e357481af22838d0/src/wallet/spend.cpp#L936
let mut cur_height = channel_manager.current_best_block().height();
let mut cur_height = channel_manager.current_best_block().height;

// 10% of the time
if thread_rng().gen_range(0, 10) == 0 {
Expand Down

0 comments on commit 49bb446

Please sign in to comment.