Merge pull request #123 from TheBlueMatt/main
authorElias Rohrer <dev@tnull.de>
Tue, 14 Nov 2023 07:52:20 +0000 (08:52 +0100)
committerGitHub <noreply@github.com>
Tue, 14 Nov 2023 07:52:20 +0000 (08:52 +0100)
Upgrade to LDK 0.0.118

1  2 
src/main.rs

diff --combined src/main.rs
index 33b17078f3b9aea808d7cc2b83f4d5dcd1fa5fa8,6480805d92759eed4d90407ada06a3f6eb7f202f..4c57c168e474fa238e9cd8eb4c9636cba41c07b2
@@@ -20,7 -20,7 +20,7 @@@ use lightning::events::bump_transaction
  use lightning::events::{Event, PaymentFailureReason, PaymentPurpose};
  use lightning::ln::channelmanager::{self, RecentPaymentDetails};
  use lightning::ln::channelmanager::{
-       ChainParameters, ChannelManagerReadArgs, SimpleArcChannelManager,
+       ChainParameters, ChannelManagerReadArgs, PaymentId, SimpleArcChannelManager,
  };
  use lightning::ln::msgs::DecodeError;
  use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler, SimpleArcPeerManager};
@@@ -109,11 -109,19 +109,19 @@@ impl_writeable_tlv_based!(PaymentInfo, 
        (6, amt_msat, required),
  });
  
- pub(crate) struct PaymentInfoStorage {
+ pub(crate) struct InboundPaymentInfoStorage {
        payments: HashMap<PaymentHash, PaymentInfo>,
  }
  
- impl_writeable_tlv_based!(PaymentInfoStorage, {
+ impl_writeable_tlv_based!(InboundPaymentInfoStorage, {
+       (0, payments, required),
+ });
+ pub(crate) struct OutboundPaymentInfoStorage {
+       payments: HashMap<PaymentId, PaymentInfo>,
+ }
+ impl_writeable_tlv_based!(OutboundPaymentInfoStorage, {
        (0, payments, required),
  });
  
@@@ -139,7 -147,7 +147,7 @@@ pub(crate) type GossipVerifier = lightn
        Arc<FilesystemLogger>,
        SocketDescriptor,
        Arc<ChannelManager>,
-       Arc<SimpleArcOnionMessenger<FilesystemLogger>>,
+       Arc<OnionMessenger>,
        IgnoringMessageHandler,
        Arc<KeysManager>,
  >;
@@@ -158,7 -166,8 +166,8 @@@ pub(crate) type ChannelManager 
  
  pub(crate) type NetworkGraph = gossip::NetworkGraph<Arc<FilesystemLogger>>;
  
- type OnionMessenger = SimpleArcOnionMessenger<FilesystemLogger>;
+ type OnionMessenger =
+       SimpleArcOnionMessenger<ChainMonitor, BitcoindClient, BitcoindClient, FilesystemLogger>;
  
  pub(crate) type BumpTxEventHandler = BumpTransactionEventHandler<
        Arc<BitcoindClient>,
  async fn handle_ldk_events(
        channel_manager: &Arc<ChannelManager>, bitcoind_client: &BitcoindClient,
        network_graph: &NetworkGraph, keys_manager: &KeysManager,
-       bump_tx_event_handler: &BumpTxEventHandler, inbound_payments: Arc<Mutex<PaymentInfoStorage>>,
-       outbound_payments: Arc<Mutex<PaymentInfoStorage>>, fs_store: &Arc<FilesystemStore>,
+       bump_tx_event_handler: &BumpTxEventHandler,
+       inbound_payments: Arc<Mutex<InboundPaymentInfoStorage>>,
+       outbound_payments: Arc<Mutex<OutboundPaymentInfoStorage>>, fs_store: &Arc<FilesystemStore>,
        network: Network, event: Event,
  ) {
        match event {
                        // satisfied.
                        let funded_tx = bitcoind_client.fund_raw_transaction(raw_tx).await;
  
 -                      // Sign the final funding transaction and broadcast it.
 +                      // Sign the final funding transaction and give it to LDK, who will eventually broadcast it.
                        let signed_tx = bitcoind_client.sign_raw_transaction_with_wallet(funded_tx.hex).await;
                        assert_eq!(signed_tx.complete, true);
                        let final_tx: Transaction =
                        }
                        fs_store.write("", "", INBOUND_PAYMENTS_FNAME, &inbound.encode()).unwrap();
                }
-               Event::PaymentSent { payment_preimage, payment_hash, fee_paid_msat, .. } => {
+               Event::PaymentSent {
+                       payment_preimage, payment_hash, fee_paid_msat, payment_id, ..
+               } => {
                        let mut outbound = outbound_payments.lock().unwrap();
-                       for (hash, payment) in outbound.payments.iter_mut() {
-                               if *hash == payment_hash {
+                       for (id, payment) in outbound.payments.iter_mut() {
+                               if *id == payment_id.unwrap() {
                                        payment.preimage = Some(payment_preimage);
                                        payment.status = HTLCStatus::Succeeded;
                                        println!(
                Event::PaymentPathFailed { .. } => {}
                Event::ProbeSuccessful { .. } => {}
                Event::ProbeFailed { .. } => {}
-               Event::PaymentFailed { payment_hash, reason, .. } => {
+               Event::PaymentFailed { payment_hash, reason, payment_id, .. } => {
                        print!(
                                "\nEVENT: Failed to send payment to payment hash {}: {:?}",
                                payment_hash,
                        io::stdout().flush().unwrap();
  
                        let mut outbound = outbound_payments.lock().unwrap();
-                       if outbound.payments.contains_key(&payment_hash) {
-                               let payment = outbound.payments.get_mut(&payment_hash).unwrap();
+                       if outbound.payments.contains_key(&payment_id) {
+                               let payment = outbound.payments.get_mut(&payment_id).unwrap();
+                               payment.status = HTLCStatus::Failed;
+                       }
+                       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();
+                       let mut outbound = outbound_payments.lock().unwrap();
+                       if outbound.payments.contains_key(&payment_id) {
+                               let payment = outbound.payments.get_mut(&payment_id).unwrap();
                                payment.status = HTLCStatus::Failed;
                        }
                        fs_store.write("", "", OUTBOUND_PAYMENTS_FNAME, &outbound.encode()).unwrap();
@@@ -754,7 -778,7 +778,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];
                }
        });
  
-       let inbound_payments = Arc::new(Mutex::new(disk::read_payment_info(Path::new(&format!(
-               "{}/{}",
-               ldk_data_dir, INBOUND_PAYMENTS_FNAME
-       )))));
-       let outbound_payments = Arc::new(Mutex::new(disk::read_payment_info(Path::new(&format!(
-               "{}/{}",
-               ldk_data_dir, OUTBOUND_PAYMENTS_FNAME
-       )))));
-       let recent_payments_payment_hashes = channel_manager
+       let inbound_payments = Arc::new(Mutex::new(disk::read_inbound_payment_info(Path::new(
+               &format!("{}/{}", ldk_data_dir, INBOUND_PAYMENTS_FNAME),
+       ))));
+       let outbound_payments = Arc::new(Mutex::new(disk::read_outbound_payment_info(Path::new(
+               &format!("{}/{}", ldk_data_dir, OUTBOUND_PAYMENTS_FNAME),
+       ))));
+       let recent_payments_payment_ids = channel_manager
                .list_recent_payments()
                .into_iter()
                .filter_map(|p| match p {
-                       RecentPaymentDetails::Pending { payment_hash, .. } => Some(payment_hash),
-                       RecentPaymentDetails::Fulfilled { payment_hash, .. } => payment_hash,
-                       RecentPaymentDetails::Abandoned { payment_hash, .. } => Some(payment_hash),
-                       RecentPaymentDetails::AwaitingInvoice { payment_id: _ } => todo!(),
+                       RecentPaymentDetails::Pending { payment_id, .. } => Some(payment_id),
+                       RecentPaymentDetails::Fulfilled { payment_id, .. } => Some(payment_id),
+                       RecentPaymentDetails::Abandoned { payment_id, .. } => Some(payment_id),
+                       RecentPaymentDetails::AwaitingInvoice { payment_id } => Some(payment_id),
                })
-               .collect::<Vec<PaymentHash>>();
-       for (payment_hash, payment_info) in outbound_payments
+               .collect::<Vec<PaymentId>>();
+       for (payment_id, payment_info) in outbound_payments
                .lock()
                .unwrap()
                .payments
                .iter_mut()
                .filter(|(_, i)| matches!(i.status, HTLCStatus::Pending))
        {
-               if !recent_payments_payment_hashes.contains(payment_hash) {
+               if !recent_payments_payment_ids.contains(payment_id) {
                        payment_info.status = HTLCStatus::Failed;
                }
        }