From 04aaa24ab8c2a76f9e4ba0b487ed81fe86c55344 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 13 Jan 2025 15:32:48 +0000 Subject: [PATCH] Use an `OMDomainResolver` by default to resolve HRNs for others --- Cargo.toml | 1 + src/main.rs | 62 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1d8e4a2..68b0591 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" [dependencies] lightning = { version = "0.1.0-beta1", features = ["dnssec"] } lightning-block-sync = { version = "0.1.0-beta1", features = [ "rpc-client", "tokio" ] } +lightning-dns-resolver = { version = "0.1.0-beta1" } lightning-invoice = { version = "0.33.0-beta1" } lightning-net-tokio = { version = "0.1.0-beta1" } lightning-persister = { version = "0.1.0-beta1" } diff --git a/src/main.rs b/src/main.rs index 02b8193..370838d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,9 +24,13 @@ use lightning::ln::channelmanager::{ ChainParameters, ChannelManagerReadArgs, PaymentId, SimpleArcChannelManager, }; use lightning::ln::msgs::DecodeError; -use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler, SimpleArcPeerManager}; +use lightning::ln::peer_handler::{ + IgnoringMessageHandler, MessageHandler, PeerManager as LdkPeerManager, +}; use lightning::ln::types::ChannelId; -use lightning::onion_message::messenger::{DefaultMessageRouter, SimpleArcOnionMessenger}; +use lightning::onion_message::messenger::{ + DefaultMessageRouter, OnionMessenger as LdkOnionMessenger, +}; use lightning::routing::gossip; use lightning::routing::gossip::{NodeId, P2PGossipSync}; use lightning::routing::router::DefaultRouter; @@ -48,6 +52,7 @@ use lightning_block_sync::init; use lightning_block_sync::poll; use lightning_block_sync::SpvClient; use lightning_block_sync::UnboundedCache; +use lightning_dns_resolver::OMDomainResolver; use lightning_net_tokio::SocketDescriptor; use lightning_persister::fs_store::FilesystemStore; use rand::{thread_rng, Rng}; @@ -154,13 +159,16 @@ pub(crate) type GossipVerifier = lightning_block_sync::gossip::GossipVerifier< Arc, >; -pub(crate) type PeerManager = SimpleArcPeerManager< +// Note that if you do not use an `OMDomainResolver` here you should use SimpleArcPeerManager +// instead. +pub(crate) type PeerManager = LdkPeerManager< SocketDescriptor, - ChainMonitor, - BitcoindClient, - BitcoindClient, - Arc, - FilesystemLogger, + Arc, + Arc, Arc, Arc>>, + Arc, + Arc, + IgnoringMessageHandler, + Arc, >; pub(crate) type ChannelManager = @@ -168,8 +176,19 @@ pub(crate) type ChannelManager = pub(crate) type NetworkGraph = gossip::NetworkGraph>; -type OnionMessenger = - SimpleArcOnionMessenger; +// Note that if you do not use an `OMDomainResolver` here you should use SimpleArcOnionMessenger +// instead. +type OnionMessenger = LdkOnionMessenger< + Arc, + Arc, + Arc, + Arc, + Arc, Arc, Arc>>, + Arc, + Arc, + Arc>>, + IgnoringMessageHandler, +>; pub(crate) type BumpTxEventHandler = BumpTransactionEventHandler< Arc, @@ -822,8 +841,17 @@ async fn start_ldk() { let gossip_sync = Arc::new(P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger))); - // Step 16: Initialize the PeerManager + // Step 16 an OMDomainResolver as a service to other nodes + // As a service to other LDK users, using an `OMDomainResolver` allows others to resolve BIP + // 353 Human Readable Names for others, providing them DNSSEC proofs over lightning onion + // messages. Doing this only makes sense for a always-online public routing node, and doesn't + // provide you any direct value, but its nice to offer the service for others. let channel_manager: Arc = Arc::new(channel_manager); + let resolver = "8.8.8.8:53".to_socket_addrs().unwrap().next().unwrap(); + let domain_resolver = + Arc::new(OMDomainResolver::new(resolver, Some(Arc::clone(&channel_manager)))); + + // Step 17: Initialize the PeerManager let onion_messenger: Arc = Arc::new(OnionMessenger::new( Arc::clone(&keys_manager), Arc::clone(&keys_manager), @@ -832,7 +860,7 @@ async fn start_ldk() { Arc::clone(&message_router), Arc::clone(&channel_manager), Arc::clone(&channel_manager), - Arc::clone(&channel_manager), + domain_resolver, IgnoringMessageHandler {}, )); let mut ephemeral_bytes = [0; 32]; @@ -862,7 +890,7 @@ async fn start_ldk() { gossip_sync.add_utxo_lookup(Some(Arc::new(utxo_lookup))); // ## Running LDK - // Step 17: Initialize networking + // Step 18: Initialize networking let peer_manager_connection_handler = peer_manager.clone(); let listening_port = args.ldk_peer_listening_port; @@ -888,7 +916,7 @@ async fn start_ldk() { } }); - // Step 18: Connect and Disconnect Blocks + // Step 19: Connect and Disconnect Blocks let output_sweeper: Arc = Arc::new(output_sweeper); let channel_manager_listener = channel_manager.clone(); let chain_monitor_listener = chain_monitor.clone(); @@ -937,7 +965,7 @@ async fn start_ldk() { .write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound_payments.lock().unwrap().encode()) .unwrap(); - // Step 19: Handle LDK Events + // Step 20: Handle LDK Events let channel_manager_event_listener = Arc::clone(&channel_manager); let bitcoind_client_event_listener = Arc::clone(&bitcoind_client); let network_graph_event_listener = Arc::clone(&network_graph); @@ -979,10 +1007,10 @@ async fn start_ldk() { } }; - // Step 20: Persist ChannelManager and NetworkGraph + // Step 21: Persist ChannelManager and NetworkGraph let persister = Arc::new(FilesystemStore::new(ldk_data_dir.clone().into())); - // Step 21: Background Processing + // Step 22: Background Processing let (bp_exit, bp_exit_check) = tokio::sync::watch::channel(()); let mut background_processor = tokio::spawn(process_events_async( Arc::clone(&persister),