From: valentinewallace Date: Tue, 19 Oct 2021 18:41:09 +0000 (-0400) Subject: Merge pull request #39 from TheBlueMatt/main X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-sample;a=commitdiff_plain;h=5b4fe6393bee3d5b82637baf60560fa63dd4ffaa;hp=32bfe68205f4ce0ae0683fd66e861b3656e3df7d Merge pull request #39 from TheBlueMatt/main Update dependencies to LDK 0.0.102 --- diff --git a/Cargo.toml b/Cargo.toml index b027721..cc9f501 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,12 +8,12 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -lightning = { version = "0.0.101" } -lightning-block-sync = { version = "0.0.101", features = [ "rpc-client" ] } -lightning-invoice = { version = "0.9.0" } -lightning-net-tokio = { version = "0.0.101" } -lightning-persister = { version = "0.0.101" } -lightning-background-processor = { version = "0.0.101" } +lightning = { version = "0.0.102" } +lightning-block-sync = { version = "0.0.102", features = [ "rpc-client" ] } +lightning-invoice = { version = "0.10.0" } +lightning-net-tokio = { version = "0.0.102" } +lightning-persister = { version = "0.0.102" } +lightning-background-processor = { version = "0.0.102" } base64 = "0.13.0" bitcoin = "0.27" @@ -22,7 +22,7 @@ bech32 = "0.8" hex = "0.3" futures = "0.3" -time = "0.2" +chrono = "0.4" rand = "0.4" serde_json = { version = "1.0" } tokio = { version = "1.5", features = [ "io-util", "macros", "rt", "rt-multi-thread", "sync", "net", "time" ] } diff --git a/src/cli.rs b/src/cli.rs index 66fc316..b8db89d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -8,13 +8,14 @@ use bitcoin::hashes::Hash; use bitcoin::network::constants::Network; use bitcoin::secp256k1::key::PublicKey; use lightning::chain; -use lightning::chain::keysinterface::KeysManager; +use lightning::chain::keysinterface::{KeysInterface, KeysManager}; use lightning::ln::features::InvoiceFeatures; use lightning::ln::msgs::NetAddress; use lightning::ln::{PaymentHash, PaymentSecret}; use lightning::routing::network_graph::NetGraphMsgHandler; use lightning::routing::router; use lightning::routing::router::RouteHint; +use lightning::routing::scorer::Scorer; use lightning::util::config::{ChannelConfig, ChannelHandshakeLimits, UserConfig}; use lightning_invoice::{utils, Currency, Invoice}; use std::env; @@ -411,6 +412,24 @@ pub(crate) async fn poll_for_user_input( } "nodeinfo" => node_info(channel_manager.clone(), peer_manager.clone()), "listpeers" => list_peers(peer_manager.clone()), + "signmessage" => { + const MSG_STARTPOS: usize = "signmsg".len() + 1; + if line.as_bytes().len() <= MSG_STARTPOS { + println!("ERROR: signmsg requires a message"); + print!("> "); + io::stdout().flush().unwrap(); + continue; + } + println!( + "{:?}", + lightning::util::message_signing::sign( + &line.as_bytes()[MSG_STARTPOS..], + &keys_manager.get_node_secret() + ) + ); + print!("> "); + io::stdout().flush().unwrap(); + } _ => println!("Unknown command. See `\"help\" for available commands."), } } @@ -430,6 +449,7 @@ fn help() { println!("forceclosechannel "); println!("nodeinfo"); println!("listpeers"); + println!("signmessage "); } fn node_info(channel_manager: Arc, peer_manager: Arc) { @@ -608,6 +628,7 @@ fn send_payment( amt_msat, final_cltv, logger, + &Scorer::default(), ); if let Err(e) = route { println!("ERROR: failed to find route: {}", e.err); @@ -615,7 +636,7 @@ fn send_payment( } let status = match channel_manager.send_payment(&route.unwrap(), payment_hash, &payment_secret) { - Ok(()) => { + Ok(_payment_id) => { println!("EVENT: initiated sending {} msats to {}", amt_msat, payee); HTLCStatus::Pending } @@ -655,6 +676,7 @@ fn keysend( amt_msat, 40, logger, + &Scorer::default(), ) { Ok(r) => r, Err(e) => { @@ -664,7 +686,7 @@ fn keysend( }; let mut payments = payment_storage.lock().unwrap(); - let payment_hash = channel_manager.send_spontaneous_payment(&route, None).unwrap(); + let payment_hash = channel_manager.send_spontaneous_payment(&route, None).unwrap().0; payments.insert( payment_hash, PaymentInfo { diff --git a/src/disk.rs b/src/disk.rs index 2c1834a..b641ebb 100644 --- a/src/disk.rs +++ b/src/disk.rs @@ -1,6 +1,7 @@ use crate::cli; use bitcoin::secp256k1::key::PublicKey; use bitcoin::BlockHash; +use chrono::Utc; use lightning::routing::network_graph::NetworkGraph; use lightning::util::logger::{Logger, Record}; use lightning::util::ser::{Readable, Writeable, Writer}; @@ -10,7 +11,6 @@ use std::fs::File; use std::io::{BufRead, BufReader, BufWriter}; use std::net::SocketAddr; use std::path::Path; -use time::OffsetDateTime; pub(crate) struct FilesystemLogger { data_dir: String, @@ -27,7 +27,10 @@ impl Logger for FilesystemLogger { let raw_log = record.args.to_string(); let log = format!( "{} {:<5} [{}:{}] {}\n", - OffsetDateTime::now_utc().format("%F %T"), + // Note that a "real" lightning node almost certainly does *not* want subsecond + // precision for message-receipt information as it makes log entries a target for + // deanonymization attacks. For testing, however, its quite useful. + Utc::now().format("%Y-%m-%d %H:%M:%S%.3f"), record.level.to_string(), record.module_path, record.line, diff --git a/src/main.rs b/src/main.rs index 6f35975..f66d4ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,8 +9,6 @@ use crate::disk::FilesystemLogger; use bitcoin::blockdata::constants::genesis_block; use bitcoin::blockdata::transaction::Transaction; use bitcoin::consensus::encode; -use bitcoin::hashes::sha256::Hash as Sha256; -use bitcoin::hashes::Hash; use bitcoin::network::constants::Network; use bitcoin::secp256k1::Secp256k1; use bitcoin::BlockHash; @@ -184,11 +182,10 @@ async fn handle_ldk_events( } } } - Event::PaymentSent { payment_preimage } => { - let hashed = PaymentHash(Sha256::hash(&payment_preimage.0).into_inner()); + Event::PaymentSent { payment_preimage, payment_hash } => { let mut payments = outbound_payments.lock().unwrap(); - for (payment_hash, payment) in payments.iter_mut() { - if *payment_hash == hashed { + for (hash, payment) in payments.iter_mut() { + if *hash == *payment_hash { payment.preimage = Some(*payment_preimage); payment.status = HTLCStatus::Succeeded; println!( @@ -209,16 +206,20 @@ async fn handle_ldk_events( network_update: _, all_paths_failed, path: _, + short_channel_id, } => { print!( - "\nEVENT: Failed to send payment{} to payment hash {:?}: ", + "\nEVENT: Failed to send payment{} to payment hash {:?}", if *all_paths_failed { "" } else { " along MPP path" }, hex_utils::hex_str(&payment_hash.0) ); + if let Some(scid) = short_channel_id { + print!(" because of failure at channel {}", scid); + } if *rejected_by_dest { - println!("re-attempting the payment will not succeed"); + println!(": re-attempting the payment will not succeed"); } else { - println!("payment may be retried"); + println!(": payment may be retried"); } print!("> "); io::stdout().flush().unwrap(); @@ -271,7 +272,7 @@ async fn handle_ldk_events( .unwrap(); bitcoind_client.broadcast_transaction(&spending_tx); } - Event::ChannelClosed { channel_id, reason } => { + Event::ChannelClosed { channel_id, reason, user_channel_id: _ } => { println!( "\nEVENT: Channel {} closed due to: {:?}", hex_utils::hex_str(channel_id), @@ -280,6 +281,10 @@ async fn handle_ldk_events( print!("> "); io::stdout().flush().unwrap(); } + Event::DiscardFunding { .. } => { + // A "real" node should probably "lock" the UTXOs spent in funding transactions until + // the funding transaction either confirms, or this event is generated. + } } }