]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Don't forward HTLC intercepts over unestablished channels
authorValentine Wallace <vwallace@protonmail.com>
Wed, 23 Nov 2022 00:15:56 +0000 (19:15 -0500)
committerValentine Wallace <vwallace@protonmail.com>
Wed, 30 Nov 2022 17:52:23 +0000 (12:52 -0500)
lightning/src/ln/channelmanager.rs
lightning/src/ln/payment_tests.rs

index f27ca53bcf07a3c42334ee0b8cec05e681cdfc34..20014f799ee5db53eec61bd1ad4c66cf3096e0ec 100644 (file)
@@ -3078,7 +3078,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
                let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
 
                let next_hop_scid = match self.channel_state.lock().unwrap().by_id.get(next_hop_channel_id) {
-                       Some(chan) => chan.get_short_channel_id().unwrap_or(chan.outbound_scid_alias()),
+                       Some(chan) => {
+                               if !chan.is_usable() {
+                                       return Err(APIError::APIMisuseError {
+                                               err: format!("Channel with id {:?} not fully established", next_hop_channel_id)
+                                       })
+                               }
+                               chan.get_short_channel_id().unwrap_or(chan.outbound_scid_alias())
+                       },
                        None => return Err(APIError::APIMisuseError {
                                err: format!("Channel with id {:?} not found", next_hop_channel_id)
                        })
index ead5bcbd4694cf95c93abc717dfd633b7071e55a..2da80ae3f1c92abc5274071ee6945fb61aacebaa 100644 (file)
@@ -1487,6 +1487,12 @@ fn do_test_intercepted_payment(test: InterceptTest) {
                        .expected_htlc_error_data(0x4000 | 10, &[]);
                expect_payment_failed_conditions(&nodes[0], payment_hash, false, fail_conditions);
        } else if test == InterceptTest::Forward {
+               // Check that we'll fail as expected when sending to a channel that isn't in `ChannelReady` yet.
+               let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
+               let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
+               assert_eq!(unusable_chan_err , APIError::APIMisuseError { err: format!("Channel with id {:?} not fully established", temp_chan_id) });
+               assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);
+
                // Open the just-in-time channel so the payment can then be forwarded.
                let (_, channel_id) = open_zero_conf_channel(&nodes[1], &nodes[2], None);