]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Forward HTLCs after a timeout and a few other cleanups
authorValentine Wallace <vwallace@protonmail.com>
Thu, 18 Mar 2021 22:30:20 +0000 (18:30 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Mon, 3 May 2021 22:30:07 +0000 (18:30 -0400)
README.md
src/main.rs

index 740aa25b735defcb3afe66819edb74fb33025fca..4b9e99a892569c031c362f2e4c6c3ade98fa3184 100644 (file)
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@ Sample node implementation using LDK.
 
 ## Installation
 ```
-git clone git@github.com:valentinewallace/ldk-sample.git
+git clone git@github.com:lightningdevkit/ldk-sample.git
 ```
 
 ## Usage
index 421db95ef833da8142462d3a93f19f01a96df884..37d464a96c3eaeea37d3e2d7ef6e3d14032b1b99 100644 (file)
@@ -130,6 +130,7 @@ fn handle_ldk_events(peer_manager: Arc<PeerManager>, channel_manager: Arc<Channe
                         txid: final_tx.txid(),
                         index: if change_output_position == 0 { 1 } else { 0 }
                     };
+                    // Give the funding transaction back to LDK for opening the channel.
                     loop_channel_manager.funding_transaction_generated(&temporary_channel_id,
                                                                        outpoint);
                     pending_txs.insert(outpoint, final_tx);
@@ -173,7 +174,7 @@ fn handle_ldk_events(peer_manager: Arc<PeerManager>, channel_manager: Arc<Channe
                         }
                     }
                                        },
-                                       Event::PaymentFailed { payment_hash, rejected_by_dest, .. } => {
+                                       Event::PaymentFailed { payment_hash, rejected_by_dest } => {
                     print!("\nNEW EVENT: Failed to send payment to payment hash {:?}: ",
                            hex_utils::hex_str(&payment_hash.0));
                     if rejected_by_dest {
@@ -189,8 +190,14 @@ fn handle_ldk_events(peer_manager: Arc<PeerManager>, channel_manager: Arc<Channe
                         *status = HTLCStatus::Failed;
                     }
                                        },
-                                       Event::PendingHTLCsForwardable { .. } => {
-                    loop_channel_manager.process_pending_htlc_forwards();
+                                       Event::PendingHTLCsForwardable { time_forwardable } => {
+                    let forwarding_channel_manager = loop_channel_manager.clone();
+                    thread::spawn(move || {
+                        let min = time_forwardable.as_secs();
+                        let seconds_to_sleep = thread_rng().gen_range(min, min * 5);
+                        thread::sleep(Duration::new(seconds_to_sleep, 0));
+                        forwarding_channel_manager.process_pending_htlc_forwards();
+                    });
                                        },
                 Event::SpendableOutputs { outputs } => {
                     let destination_address = bitcoind_client.get_new_address();