X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain.rs;h=a33d667653291169fa87cc7eeed9faaa62580ced;hb=aa1635c16624664ba2fde72c0f58da7437e50b74;hp=0e0dd34439893858b3458f9ec5a4efbdbed371f5;hpb=f27446dee8d4dea6ab9d123948b7b5f339c2a53a;p=ldk-sample diff --git a/src/main.rs b/src/main.rs index 0e0dd34..a33d667 100644 --- a/src/main.rs +++ b/src/main.rs @@ -133,12 +133,23 @@ type ChainMonitor = chainmonitor::ChainMonitor< >, >; +pub(crate) type GossipVerifier = lightning_block_sync::gossip::GossipVerifier< + lightning_block_sync::gossip::TokioSpawner, + Arc, + Arc, + SocketDescriptor, + Arc, + Arc, + IgnoringMessageHandler, + Arc, +>; + pub(crate) type PeerManager = SimpleArcPeerManager< SocketDescriptor, ChainMonitor, BitcoindClient, BitcoindClient, - Arc, + GossipVerifier, FilesystemLogger, >; @@ -147,7 +158,8 @@ pub(crate) type ChannelManager = pub(crate) type NetworkGraph = gossip::NetworkGraph>; -type OnionMessenger = SimpleArcOnionMessenger; +type OnionMessenger = + SimpleArcOnionMessenger; pub(crate) type BumpTxEventHandler = BumpTransactionEventHandler< Arc, @@ -160,7 +172,7 @@ async fn handle_ldk_events( channel_manager: &Arc, bitcoind_client: &BitcoindClient, network_graph: &NetworkGraph, keys_manager: &KeysManager, bump_tx_event_handler: &BumpTxEventHandler, inbound_payments: Arc>, - outbound_payments: Arc>, persister: &Arc, + outbound_payments: Arc>, fs_store: &Arc, network: Network, event: Event, ) { match event { @@ -272,7 +284,7 @@ async fn handle_ldk_events( }); } } - persister.write("", "", INBOUND_PAYMENTS_FNAME, &inbound.encode()).unwrap(); + fs_store.write("", "", INBOUND_PAYMENTS_FNAME, &inbound.encode()).unwrap(); } Event::PaymentSent { payment_preimage, payment_hash, fee_paid_msat, .. } => { let mut outbound = outbound_payments.lock().unwrap(); @@ -296,7 +308,7 @@ async fn handle_ldk_events( io::stdout().flush().unwrap(); } } - persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap(); + fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap(); } Event::OpenChannelRequest { ref temporary_channel_id, ref counterparty_node_id, .. @@ -345,7 +357,14 @@ async fn handle_ldk_events( let payment = outbound.payments.get_mut(&payment_hash).unwrap(); payment.status = HTLCStatus::Failed; } - persister.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap(); + fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap(); + } + Event::InvoiceRequestFailed { payment_id } => { + print!("\nEVENT: Failed to request invoice to send payment with id {}", payment_id); + print!("> "); + io::stdout().flush().unwrap(); + + // TODO: mark the payment as failed } Event::PaymentForwarded { prev_channel_id, @@ -433,7 +452,7 @@ async fn handle_ldk_events( let key = hex_utils::hex_str(&keys_manager.get_secure_random_bytes()); // Note that if the type here changes our read code needs to change as well. let output: SpendableOutputDescriptor = output; - persister.write(PENDING_SPENDABLE_OUTPUT_DIR, "", &key, &output.encode()).unwrap(); + fs_store.write(PENDING_SPENDABLE_OUTPUT_DIR, "", &key, &output.encode()).unwrap(); } } Event::ChannelPending { channel_id, counterparty_node_id, .. } => { @@ -733,11 +752,8 @@ async fn start_ldk() { } // Step 14: Optional: Initialize the P2PGossipSync - let gossip_sync = Arc::new(P2PGossipSync::new( - Arc::clone(&network_graph), - None::>, - logger.clone(), - )); + let gossip_sync = + Arc::new(P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger))); // Step 15: Initialize the PeerManager let channel_manager: Arc = Arc::new(channel_manager); @@ -746,7 +762,7 @@ async fn start_ldk() { Arc::clone(&keys_manager), Arc::clone(&logger), Arc::new(DefaultMessageRouter {}), - IgnoringMessageHandler {}, + Arc::clone(&channel_manager), IgnoringMessageHandler {}, )); let mut ephemeral_bytes = [0; 32]; @@ -766,6 +782,15 @@ async fn start_ldk() { Arc::clone(&keys_manager), )); + // Install a GossipVerifier in in the P2PGossipSync + let utxo_lookup = GossipVerifier::new( + Arc::clone(&bitcoind_client.bitcoind_rpc_client), + lightning_block_sync::gossip::TokioSpawner, + Arc::clone(&gossip_sync), + Arc::clone(&peer_manager), + ); + gossip_sync.add_utxo_lookup(Some(utxo_lookup)); + // ## Running LDK // Step 16: Initialize networking