]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Update to LDK 0.0.112
authorMatt Corallo <git@bluematt.me>
Mon, 31 Oct 2022 00:03:46 +0000 (00:03 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 31 Oct 2022 23:38:21 +0000 (23:38 +0000)
Cargo.lock
Cargo.toml
src/bitcoind_client.rs
src/cli.rs
src/main.rs

index be7983146fab886db1570a69675ab373d3aad34c..f1ac403d78f265b4e4ed4b4f04809bba6f906e79 100644 (file)
@@ -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",
index b8cf0f886267532fc2470587e971ae5df67d7acd..8dc32b35bdbfff7493f91119fbd84c8d02c49a6b 100644 (file)
@@ -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"
index 93321dd0a44a26f9a4ed35788778629dd7f6ef2b..84efbfca331433d01dd810df44ea95495092e556 100644 (file)
@@ -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 })
        }
 
index d53b74bbd98609279923b3b104639f3d4b8a1f68..0638b95e5efc42a3d85306b31e2761debfa046e6 100644 (file)
@@ -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<LdkUserInfo, ()> {
        })
 }
 
+struct UserOnionMessageContents {
+       tlv_type: u64,
+       data: Vec<u8>,
+}
+
+impl CustomOnionMessageContents for UserOnionMessageContents {
+       fn tlv_type(&self) -> u64 {
+               self.tlv_type
+       }
+}
+impl MaybeReadableArgs<u64> for UserOnionMessageContents {
+       fn read<R: std::io::Read>(_r: &mut R, _args: u64) -> Result<Option<Self>, 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<W: Writer>(&self, w: &mut W) -> Result<(), std::io::Error> {
+               w.write_all(&self.data)
+       }
+}
+
 pub(crate) async fn poll_for_user_input<E: EventHandler>(
        invoice_payer: Arc<InvoicePayer<E>>, peer_manager: Arc<PeerManager>,
        channel_manager: Arc<ChannelManager>, keys_manager: Arc<KeysManager>,
        network_graph: Arc<NetworkGraph>, onion_messenger: Arc<OnionMessenger>,
        inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage,
-       ldk_data_dir: String, network: Network,
+       ldk_data_dir: String, network: Network, logger: Arc<disk::FilesystemLogger>,
 ) {
        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<E: EventHandler>(
 
                                        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<E: EventHandler>(
                                        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 <amt_msats> <expiry_secs>");
        println!("\n  Other:");
        println!("      signmessage <message>");
-       println!("      sendonionmessage <node_id_1,node_id_2,..,destination_node_id>");
+       println!(
+               "      sendonionmessage <node_id_1,node_id_2,..,destination_node_id> <type> <hex_bytes>"
+       );
        println!("      nodeinfo");
 }
 
@@ -764,8 +806,9 @@ fn keysend<E: EventHandler, K: KeysInterface>(
 }
 
 fn get_invoice(
-       amt_msat: u64, payment_storage: PaymentInfoStorage, channel_manager: Arc<ChannelManager>,
+       amt_msat: u64, payment_storage: PaymentInfoStorage, channel_manager: &ChannelManager,
        keys_manager: Arc<KeysManager>, network: Network, expiry_secs: u32,
+       logger: Arc<disk::FilesystemLogger>,
 ) {
        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(),
index 0d5915d9effc49415a10e0080a49e90af83aae81..4314ac87131dc05ee92f56b51ebfc36e5f3336f2 100644 (file)
@@ -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<ChainMonitor, BitcoindClient, BitcoindClient, FilesystemLogger>;
 
-pub(crate) type InvoicePayer<E> = payment::InvoicePayer<
-       Arc<ChannelManager>,
-       Router,
-       Arc<Mutex<ProbabilisticScorer<Arc<NetworkGraph>, Arc<FilesystemLogger>>>>,
+pub(crate) type InvoicePayer<E> =
+       payment::InvoicePayer<Arc<ChannelManager>, Router, Arc<FilesystemLogger>, E>;
+
+type Router = DefaultRouter<
+       Arc<NetworkGraph>,
        Arc<FilesystemLogger>,
-       E,
+       Arc<Mutex<ProbabilisticScorer<Arc<NetworkGraph>, Arc<FilesystemLogger>>>>,
 >;
 
-type Router = DefaultRouter<Arc<NetworkGraph>, Arc<FilesystemLogger>>;
-
 pub(crate) type NetworkGraph = gossip::NetworkGraph<Arc<FilesystemLogger>>;
 
 type OnionMessenger = SimpleArcOnionMessenger<FilesystemLogger>;
@@ -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<ChannelManager> = Arc::new(channel_manager);
-       let onion_messenger: Arc<OnionMessenger> =
-               Arc::new(OnionMessenger::new(keys_manager.clone(), logger.clone()));
+       let onion_messenger: Arc<OnionMessenger> = 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<PeerManager> = 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;