Skip to content

Commit 225a22b

Browse files
Don't forward HTLC intercepts over unestablished channels
1 parent 602698d commit 225a22b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lightning/src/ln/channelmanager.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -3071,7 +3071,14 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
30713071
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
30723072

30733073
let next_hop_scid = match self.channel_state.lock().unwrap().by_id.get(next_hop_channel_id) {
3074-
Some(chan) => chan.get_short_channel_id().unwrap_or(chan.outbound_scid_alias()),
3074+
Some(chan) => {
3075+
if !chan.is_usable() {
3076+
return Err(APIError::APIMisuseError {
3077+
err: format!("Channel with id {:?} not fully established", next_hop_channel_id)
3078+
})
3079+
}
3080+
chan.get_short_channel_id().unwrap_or(chan.outbound_scid_alias())
3081+
},
30753082
None => return Err(APIError::APIMisuseError {
30763083
err: format!("Channel with id {:?} not found", next_hop_channel_id)
30773084
})

lightning/src/ln/payment_tests.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,12 @@ fn do_test_intercepted_payment(test: InterceptTest) {
14871487
.expected_htlc_error_data(0x4000 | 10, &[]);
14881488
expect_payment_failed_conditions(&nodes[0], payment_hash, false, fail_conditions);
14891489
} else if test == InterceptTest::Forward {
1490+
// Check that we'll fail as expected when sending to a channel that isn't in `ChannelReady` yet.
1491+
let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
1492+
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();
1493+
assert_eq!(unusable_chan_err , APIError::APIMisuseError { err: format!("Channel with id {:?} not fully established", temp_chan_id) });
1494+
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);
1495+
14901496
// Open the just-in-time channel so the payment can then be forwarded.
14911497
let (_, channel_id) = open_zero_conf_channel(&nodes[1], &nodes[2], None);
14921498

0 commit comments

Comments
 (0)