[[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",
[[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",
[[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",
[[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",
[[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",
[[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",
# 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"
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};
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;
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 })
}
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;
})
}
+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."
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" => {
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"),
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");
}
}
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 {
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(),
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::{
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;
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>;
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
// 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);
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 {},
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)),
outbound_payments,
ldk_data_dir.clone(),
network,
+ Arc::clone(&logger),
)
.await;