]> git.bitcoin.ninja Git - ldk-sample/commitdiff
Do not panic if we fail to fund a channel
authorMatt Corallo <git@bluematt.me>
Mon, 5 Jul 2021 02:34:33 +0000 (02:34 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 5 Jul 2021 02:39:21 +0000 (02:39 +0000)
I saw this where a bitcoind was hung connecting a block, and while
we were waiting the peer refused the channel via an error message.
When bitcoind eventually returned, we paniced as the channel was
now gone.

src/main.rs

index 3932a58192432302f4f426cf690666e672157731..b7d74aa0ffb57c0ed427ead353f162b3acd20dbd 100644 (file)
@@ -139,7 +139,15 @@ async fn handle_ldk_events(
                        let final_tx: Transaction =
                                encode::deserialize(&hex_utils::to_vec(&signed_tx.hex).unwrap()).unwrap();
                        // Give the funding transaction back to LDK for opening the channel.
-                       channel_manager.funding_transaction_generated(&temporary_channel_id, final_tx).unwrap();
+                       if channel_manager
+                               .funding_transaction_generated(&temporary_channel_id, final_tx)
+                               .is_err()
+                       {
+                               println!(
+                                       "\nERROR: Channel went away before we could fund it. The peer disconnected or refused the channel.");
+                               print!("> ");
+                               io::stdout().flush().unwrap();
+                       }
                }
                Event::PaymentReceived { payment_hash, payment_preimage, payment_secret, amt, .. } => {
                        let mut payments = inbound_payments.lock().unwrap();