From 63d4ae286b8dad74080d35e095d1b490ddcde474 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 31 Oct 2022 00:03:46 +0000 Subject: [PATCH] Update to LDK 0.0.112 --- Cargo.lock | 30 ++++++++++---------- Cargo.toml | 14 +++++----- src/bitcoind_client.rs | 7 +++-- src/cli.rs | 62 ++++++++++++++++++++++++++++++++++++------ src/main.rs | 33 +++++++++++++--------- 5 files changed, 99 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be79831..f1ac403 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -237,18 +237,18 @@ checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "lightning" -version = "0.0.111" +version = "0.0.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86c207bcbca1c9dfb3668b81e2ad35b81370e583f2f8c5ee642a9f07925b05e" +checksum = "5deb857f23c88083ac09bc31fe4eadccf4b2779fb3c973862691258bff38b0e2" dependencies = [ "bitcoin", ] [[package]] name = "lightning-background-processor" -version = "0.0.111" +version = "0.0.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dfef23242b3656fa54a050b5cc4f1f7938d27cbf940c6c9e5b9a08f198f8d86" +checksum = "382ee5cabdacb852187c84c86bd47fe6fb29189cddad30546e25ec1731e35c68" dependencies = [ "bitcoin", "lightning", @@ -257,13 +257,13 @@ dependencies = [ [[package]] name = "lightning-block-sync" -version = "0.0.111" +version = "0.0.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1bb816be90f9b182627822ba3ed0b68cbf29315228fe54e4436fe5ad12df25" +checksum = "03590e7bc8b4c622ec3bcec03f7e00c774aafb91c0d6b5e854993e05be677730" dependencies = [ "bitcoin", "chunked_transfer", - "futures", + "futures-util", "lightning", "serde", "serde_json", @@ -271,9 +271,9 @@ dependencies = [ [[package]] name = "lightning-invoice" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "023d5bd83191e13281b877526efb503a96aaae7ef97c7ba6359ba73f9c1bee11" +checksum = "0fc6ec960257cddce1b85d5ce258821a6138dcd0ae9fd9661b2c3061df588289" dependencies = [ "bech32 0.9.1", "bitcoin_hashes", @@ -284,9 +284,9 @@ dependencies = [ [[package]] name = "lightning-net-tokio" -version = "0.0.111" +version = "0.0.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce3c24e8e3d2c34ec503d3a0f76c07b0f4815705737a6a739058638c774580a" +checksum = "2fb57b9c19e929656d578d1019bb66b1121c1217a101f5ca73f68630f74edb20" dependencies = [ "bitcoin", "lightning", @@ -295,9 +295,9 @@ dependencies = [ [[package]] name = "lightning-persister" -version = "0.0.111" +version = "0.0.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "235c5419f4f1b699176f51709317c88651c6bcfe3104be87294e1b0ba11a16af" +checksum = "5010dc150e128199635af3469ef842e161c0a8630abee3a4ca9cf13bc935cb01" dependencies = [ "bitcoin", "libc", @@ -307,9 +307,9 @@ dependencies = [ [[package]] name = "lightning-rapid-gossip-sync" -version = "0.0.111" +version = "0.0.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff55ab0918a12e5eecf511a0ae924340361dd64213139af689da51c0759f59b8" +checksum = "ccd6cea4c9191247d3ed262feaffb3f43814eafede9097364c413aea17cf281b" dependencies = [ "bitcoin", "lightning", diff --git a/Cargo.toml b/Cargo.toml index b8cf0f8..8dc32b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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.111", features = ["max_level_trace"] } -lightning-block-sync = { version = "0.0.111", features = [ "rpc-client" ] } -lightning-invoice = { version = "0.19" } -lightning-net-tokio = { version = "0.0.111" } -lightning-persister = { version = "0.0.111" } -lightning-background-processor = { version = "0.0.111" } -lightning-rapid-gossip-sync = { version = "0.0.111" } +lightning = { version = "0.0.112", features = ["max_level_trace"] } +lightning-block-sync = { version = "0.0.112", features = [ "rpc-client" ] } +lightning-invoice = { version = "0.20" } +lightning-net-tokio = { version = "0.0.112" } +lightning-persister = { version = "0.0.112" } +lightning-background-processor = { version = "0.0.112" } +lightning-rapid-gossip-sync = { version = "0.0.112" } base64 = "0.13.0" bitcoin = "0.29.0" diff --git a/src/bitcoind_client.rs b/src/bitcoind_client.rs index 93321dd..84efbfc 100644 --- a/src/bitcoind_client.rs +++ b/src/bitcoind_client.rs @@ -1,6 +1,5 @@ use crate::convert::{BlockchainInfo, FeeResponse, FundedTx, NewAddress, RawTx, SignedTx}; use base64; -use bitcoin::blockdata::block::Block; use bitcoin::blockdata::transaction::Transaction; use bitcoin::consensus::encode; use bitcoin::hash_types::{BlockHash, Txid}; @@ -8,7 +7,7 @@ use bitcoin::util::address::Address; use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator}; use lightning_block_sync::http::HttpEndpoint; use lightning_block_sync::rpc::RpcClient; -use lightning_block_sync::{AsyncBlockSourceResult, BlockHeaderData, BlockSource}; +use lightning_block_sync::{AsyncBlockSourceResult, BlockData, BlockHeaderData, BlockSource}; use serde_json; use std::collections::HashMap; use std::str::FromStr; @@ -40,7 +39,9 @@ impl BlockSource for BitcoindClient { Box::pin(async move { self.bitcoind_rpc_client.get_header(header_hash, height_hint).await }) } - fn get_block<'a>(&'a self, header_hash: &'a BlockHash) -> AsyncBlockSourceResult<'a, Block> { + fn get_block<'a>( + &'a self, header_hash: &'a BlockHash, + ) -> AsyncBlockSourceResult<'a, BlockData> { Box::pin(async move { self.bitcoind_rpc_client.get_block(header_hash).await }) } diff --git a/src/cli.rs b/src/cli.rs index d53b74b..0638b95 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -9,12 +9,13 @@ use bitcoin::hashes::Hash; use bitcoin::network::constants::Network; use bitcoin::secp256k1::PublicKey; use lightning::chain::keysinterface::{KeysInterface, KeysManager, Recipient}; -use lightning::ln::msgs::NetAddress; +use lightning::ln::msgs::{DecodeError, NetAddress}; use lightning::ln::{PaymentHash, PaymentPreimage}; -use lightning::onion_message::Destination; +use lightning::onion_message::{CustomOnionMessageContents, Destination, OnionMessageContents}; use lightning::routing::gossip::NodeId; use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig}; use lightning::util::events::EventHandler; +use lightning::util::ser::{MaybeReadableArgs, Writeable, Writer}; use lightning_invoice::payment::PaymentError; use lightning_invoice::{utils, Currency, Invoice}; use std::env; @@ -140,12 +141,35 @@ pub(crate) fn parse_startup_args() -> Result { }) } +struct UserOnionMessageContents { + tlv_type: u64, + data: Vec, +} + +impl CustomOnionMessageContents for UserOnionMessageContents { + fn tlv_type(&self) -> u64 { + self.tlv_type + } +} +impl MaybeReadableArgs for UserOnionMessageContents { + fn read(_r: &mut R, _args: u64) -> Result, DecodeError> { + // UserOnionMessageContents is only ever passed to `send_onion_message`, never to an + // `OnionMessageHandler`, thus it does not need to implement the read side here. + unreachable!(); + } +} +impl Writeable for UserOnionMessageContents { + fn write(&self, w: &mut W) -> Result<(), std::io::Error> { + w.write_all(&self.data) + } +} + pub(crate) async fn poll_for_user_input( invoice_payer: Arc>, peer_manager: Arc, channel_manager: Arc, keys_manager: Arc, network_graph: Arc, onion_messenger: Arc, inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage, - ldk_data_dir: String, network: Network, + ldk_data_dir: String, network: Network, logger: Arc, ) { println!( "LDK startup successful. Enter \"help\" to view available commands. Press Ctrl-D to quit." @@ -304,11 +328,12 @@ pub(crate) async fn poll_for_user_input( get_invoice( amt_msat.unwrap(), - inbound_payments.clone(), - channel_manager.clone(), - keys_manager.clone(), + Arc::clone(&inbound_payments), + &*channel_manager, + Arc::clone(&keys_manager), network, expiry_secs.unwrap(), + Arc::clone(&logger), ); } "connectpeer" => { @@ -456,10 +481,25 @@ pub(crate) async fn poll_for_user_input( if errored { continue; } + let tlv_type = match words.next().map(|ty_str| ty_str.parse()) { + Some(Ok(ty)) if ty >= 64 => ty, + _ => { + println!("Need an integral message type above 64"); + continue; + } + }; + let data = match words.next().map(|s| hex_utils::to_vec(s)) { + Some(Some(data)) => data, + _ => { + println!("Need a hex data string"); + continue; + } + }; let destination_pk = node_pks.pop().unwrap(); match onion_messenger.send_onion_message( &node_pks, Destination::Node(destination_pk), + OnionMessageContents::Custom(UserOnionMessageContents { tlv_type, data }), None, ) { Ok(()) => println!("SUCCESS: forwarded onion message to first hop"), @@ -499,7 +539,9 @@ fn help() { println!(" getinvoice "); println!("\n Other:"); println!(" signmessage "); - println!(" sendonionmessage "); + println!( + " sendonionmessage " + ); println!(" nodeinfo"); } @@ -764,8 +806,9 @@ fn keysend( } fn get_invoice( - amt_msat: u64, payment_storage: PaymentInfoStorage, channel_manager: Arc, + amt_msat: u64, payment_storage: PaymentInfoStorage, channel_manager: &ChannelManager, keys_manager: Arc, network: Network, expiry_secs: u32, + logger: Arc, ) { let mut payments = payment_storage.lock().unwrap(); let currency = match network { @@ -775,8 +818,9 @@ fn get_invoice( Network::Signet => Currency::Signet, }; let invoice = match utils::create_invoice_from_channelmanager( - &channel_manager, + channel_manager, keys_manager, + logger, currency, Some(amt_msat), "ldk-tutorial-node".to_string(), diff --git a/src/main.rs b/src/main.rs index 0d5915d..4314ac8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,8 +15,8 @@ use bitcoin::BlockHash; use bitcoin_bech32::WitnessProgram; use lightning::chain; use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator}; -use lightning::chain::chainmonitor; use lightning::chain::keysinterface::{InMemorySigner, KeysInterface, KeysManager, Recipient}; +use lightning::chain::{chainmonitor, ChannelMonitorUpdateStatus}; use lightning::chain::{BestBlock, Filter, Watch}; use lightning::ln::channelmanager; use lightning::ln::channelmanager::{ @@ -43,6 +43,7 @@ use lightning_persister::FilesystemPersister; use rand::{thread_rng, Rng}; use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::convert::TryInto; use std::fmt; use std::fs; use std::fs::File; @@ -100,16 +101,15 @@ pub(crate) type PeerManager = SimpleArcPeerManager< pub(crate) type ChannelManager = SimpleArcChannelManager; -pub(crate) type InvoicePayer = payment::InvoicePayer< - Arc, - Router, - Arc, Arc>>>, +pub(crate) type InvoicePayer = + payment::InvoicePayer, Router, Arc, E>; + +type Router = DefaultRouter< + Arc, Arc, - E, + Arc, Arc>>>, >; -type Router = DefaultRouter, Arc>; - pub(crate) type NetworkGraph = gossip::NetworkGraph>; type OnionMessenger = SimpleArcOnionMessenger; @@ -544,7 +544,10 @@ async fn start_ldk() { for item in chain_listener_channel_monitors.drain(..) { let channel_monitor = item.1 .0; let funding_outpoint = item.2; - chain_monitor.watch_channel(funding_outpoint, channel_monitor).unwrap(); + assert_eq!( + chain_monitor.watch_channel(funding_outpoint, channel_monitor), + ChannelMonitorUpdateStatus::Completed + ); } // Step 11: Optional: Initialize the P2PGossipSync @@ -560,8 +563,11 @@ async fn start_ldk() { // Step 12: Initialize the PeerManager let channel_manager: Arc = Arc::new(channel_manager); - let onion_messenger: Arc = - Arc::new(OnionMessenger::new(keys_manager.clone(), logger.clone())); + let onion_messenger: Arc = Arc::new(OnionMessenger::new( + Arc::clone(&keys_manager), + Arc::clone(&logger), + IgnoringMessageHandler {}, + )); let mut ephemeral_bytes = [0; 32]; let current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs(); rand::thread_rng().fill_bytes(&mut ephemeral_bytes); @@ -573,7 +579,7 @@ async fn start_ldk() { let peer_manager: Arc = Arc::new(PeerManager::new( lightning_msg_handler, keys_manager.get_node_secret(Recipient::Node).unwrap(), - current_time, + current_time.try_into().unwrap(), &ephemeral_bytes, logger.clone(), IgnoringMessageHandler {}, @@ -663,11 +669,11 @@ async fn start_ldk() { network_graph.clone(), logger.clone(), keys_manager.get_secure_random_bytes(), + scorer.clone(), ); let invoice_payer = Arc::new(InvoicePayer::new( channel_manager.clone(), router, - scorer.clone(), logger.clone(), event_handler, payment::Retry::Timeout(Duration::from_secs(10)), @@ -758,6 +764,7 @@ async fn start_ldk() { outbound_payments, ldk_data_dir.clone(), network, + Arc::clone(&logger), ) .await; -- 2.30.2