Skip to content

Commit

Permalink
Use an OMDomainResolver by default to resolve HRNs for others
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Jan 13, 2025
1 parent 00fee9f commit 04aaa24
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
62 changes: 45 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -154,22 +159,36 @@ pub(crate) type GossipVerifier = lightning_block_sync::gossip::GossipVerifier<
Arc<FilesystemLogger>,
>;

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<GossipVerifier>,
FilesystemLogger,
Arc<ChannelManager>,
Arc<P2PGossipSync<Arc<NetworkGraph>, Arc<GossipVerifier>, Arc<FilesystemLogger>>>,
Arc<OnionMessenger>,
Arc<FilesystemLogger>,
IgnoringMessageHandler,
Arc<KeysManager>,
>;

pub(crate) type ChannelManager =
SimpleArcChannelManager<ChainMonitor, BitcoindClient, BitcoindClient, FilesystemLogger>;

pub(crate) type NetworkGraph = gossip::NetworkGraph<Arc<FilesystemLogger>>;

type OnionMessenger =
SimpleArcOnionMessenger<ChainMonitor, BitcoindClient, BitcoindClient, FilesystemLogger>;
// Note that if you do not use an `OMDomainResolver` here you should use SimpleArcOnionMessenger
// instead.
type OnionMessenger = LdkOnionMessenger<
Arc<KeysManager>,
Arc<KeysManager>,
Arc<FilesystemLogger>,
Arc<ChannelManager>,
Arc<DefaultMessageRouter<Arc<NetworkGraph>, Arc<FilesystemLogger>, Arc<KeysManager>>>,
Arc<ChannelManager>,
Arc<ChannelManager>,
Arc<OMDomainResolver<Arc<ChannelManager>>>,
IgnoringMessageHandler,
>;

pub(crate) type BumpTxEventHandler = BumpTransactionEventHandler<
Arc<BitcoindClient>,
Expand Down Expand Up @@ -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<ChannelManager> = 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<OnionMessenger> = Arc::new(OnionMessenger::new(
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Expand All @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -888,7 +916,7 @@ async fn start_ldk() {
}
});

// Step 18: Connect and Disconnect Blocks
// Step 19: Connect and Disconnect Blocks
let output_sweeper: Arc<OutputSweeper> = Arc::new(output_sweeper);
let channel_manager_listener = channel_manager.clone();
let chain_monitor_listener = chain_monitor.clone();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 04aaa24

Please sign in to comment.