Skip to content

Commit 8fc8b3b

Browse files
committed
ln+events: deprecate UnknownNextPeer in HTLCHandlingFailureType
This variant of HTLCHandlingFailureType contains information about the failure cause along with its type - as an UnknownNextPeer is just an InvalidForward that has the failure type UnknownNextPeer. Use of the variant is deprecated, and any old events are upgraded to the new representation. As a result, downgrading nodes will get an InvalidForward where they otherwise would have had an UnknownNextPeer. The alternative would be to continue to write the old representation to prevent this information loss on downgrade, but it comes at the cost of not being able to remove the UnknownNextPeer variant in future (and some extra handling code). The deprecated attribute is not used because it cannot be silenced in impl_writeable_tlv_based_enum, which uses UnknownNextPeer to remain downgradable.
1 parent d1289ce commit 8fc8b3b

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

lightning/src/events/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,17 @@ pub enum HTLCHandlingFailureType {
480480
channel_id: ChannelId,
481481
},
482482
/// Scenario where we are unsure of the next node to forward the HTLC to.
483+
///
484+
/// Deprecated: will only be used in versions before LDK v0.2.0. Downgrades will result in
485+
/// this type being represented as [`Self::InvalidForward`].
483486
UnknownNextHop {
484487
/// Short channel id we are requesting to forward an HTLC to.
485488
requested_forward_scid: u64,
486489
},
487490
/// We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
488491
/// intercept HTLC.
492+
///
493+
/// In LDK v0.2.0 and greater, this variant replaces [`Self::UnknownNextHop`].
489494
InvalidForward {
490495
/// Short channel id we are requesting to forward an HTLC to.
491496
requested_forward_scid: u64
@@ -2255,10 +2260,17 @@ impl MaybeReadable for Event {
22552260
(1, failure_reason, option),
22562261
(2, failure_type_opt, upgradable_required),
22572262
});
2263+
2264+
// If a legacy HTLCHandlingFailureType::UnknownNextHop was written, upgrade
2265+
// it to its new representation, otherwise leave unchanged.
2266+
if let Some(HTLCHandlingFailureType::UnknownNextHop { requested_forward_scid }) = failure_type_opt.0 {
2267+
failure_type_opt.0 = Some(HTLCHandlingFailureType::InvalidForward { requested_forward_scid });
2268+
failure_reason = Some(LocalHTLCFailureReason::UnknownNextPeer.into());
2269+
}
22582270
Ok(Some(Event::HTLCHandlingFailed {
22592271
prev_channel_id,
22602272
failure_type: _init_tlv_based_struct_field!(failure_type_opt, upgradable_required),
2261-
failure_reason,
2273+
failure_reason
22622274
}))
22632275
};
22642276
f()

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ fn do_forward_fail_in_process_pending_htlc_fwds(check: ProcessPendingHTLCsCheck,
626626

627627
$curr_node.node.process_pending_htlc_forwards();
628628
expect_htlc_handling_failed_destinations!($curr_node.node.get_and_clear_pending_events(),
629-
vec![HTLCHandlingFailureType::UnknownNextHop { requested_forward_scid: $failed_scid }]);
629+
vec![HTLCHandlingFailureType::InvalidForward { requested_forward_scid: $failed_scid }]);
630630
$curr_node.node.process_pending_htlc_forwards();
631631
},
632632
}
@@ -725,7 +725,7 @@ fn do_blinded_intercept_payment(intercept_node_fails: bool) {
725725

726726
if intercept_node_fails {
727727
nodes[1].node.fail_intercepted_htlc(intercept_id).unwrap();
728-
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], vec![HTLCHandlingFailureType::UnknownNextHop { requested_forward_scid: intercept_scid }]);
728+
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], vec![HTLCHandlingFailureType::InvalidForward { requested_forward_scid: intercept_scid }]);
729729
nodes[1].node.process_pending_htlc_forwards();
730730
check_added_monitors!(&nodes[1], 1);
731731
fail_blinded_htlc_backwards(payment_hash, 1, &[&nodes[0], &nodes[1]], false);

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5733,7 +5733,7 @@ where
57335733
});
57345734

57355735
let reason = HTLCFailReason::from_failure_code(LocalHTLCFailureReason::UnknownNextPeer);
5736-
let destination = HTLCHandlingFailureType::UnknownNextHop { requested_forward_scid: short_channel_id };
5736+
let destination = HTLCHandlingFailureType::InvalidForward { requested_forward_scid: short_channel_id };
57375737
self.fail_htlc_backwards_internal(&htlc_source, &payment.forward_info.payment_hash, &reason, destination);
57385738
} else { unreachable!() } // Only `PendingHTLCRouting::Forward`s are intercepted
57395739

@@ -5752,7 +5752,7 @@ where
57525752
node_id: Some(*outgoing_counterparty_node_id),
57535753
channel_id: *outgoing_channel_id,
57545754
},
5755-
None => HTLCHandlingFailureType::UnknownNextHop {
5755+
None => HTLCHandlingFailureType::InvalidForward {
57565756
requested_forward_scid: outgoing_scid,
57575757
},
57585758
}
@@ -5932,7 +5932,7 @@ where
59325932
});
59335933

59345934
let reason = if $next_hop_unknown {
5935-
HTLCHandlingFailureType::UnknownNextHop { requested_forward_scid: short_chan_id }
5935+
HTLCHandlingFailureType::InvalidForward { requested_forward_scid: short_chan_id }
59365936
} else {
59375937
HTLCHandlingFailureType::Receive{ payment_hash }
59385938
};

lightning/src/ln/onion_route_tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ fn test_onion_failure() {
549549
bogus_route.paths[0].hops[1].short_channel_id -= 1;
550550
let short_channel_id = bogus_route.paths[0].hops[1].short_channel_id;
551551
run_onion_failure_test("unknown_next_peer", 100, &nodes, &bogus_route, &payment_hash, &payment_secret, |_| {}, ||{}, true, Some(LocalHTLCFailureReason::UnknownNextPeer),
552-
Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent:true}), Some(short_channel_id), Some(HTLCHandlingFailureType::UnknownNextHop { requested_forward_scid: short_channel_id }));
552+
Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent:true}), Some(short_channel_id), Some(HTLCHandlingFailureType::InvalidForward { requested_forward_scid: short_channel_id }));
553553

554554
let short_channel_id = channels[1].0.contents.short_channel_id;
555555
let amt_to_forward = nodes[1].node.per_peer_state.read().unwrap().get(&nodes[2].node.get_our_node_id())
@@ -1751,7 +1751,7 @@ fn test_phantom_failure_modified_cltv() {
17511751
expect_pending_htlcs_forwardable!(nodes[1]);
17521752
expect_htlc_handling_failed_destinations!(
17531753
nodes[1].node.get_and_clear_pending_events(),
1754-
&[HTLCHandlingFailureType::UnknownNextHop { requested_forward_scid: phantom_scid }]
1754+
&[HTLCHandlingFailureType::InvalidForward { requested_forward_scid: phantom_scid }]
17551755
);
17561756
check_added_monitors(&nodes[1], 1);
17571757

@@ -1800,7 +1800,7 @@ fn test_phantom_failure_expires_too_soon() {
18001800
expect_pending_htlcs_forwardable!(nodes[1]);
18011801
expect_htlc_handling_failed_destinations!(
18021802
nodes[1].node.get_and_clear_pending_events(),
1803-
&[HTLCHandlingFailureType::UnknownNextHop { requested_forward_scid: phantom_scid }]
1803+
&[HTLCHandlingFailureType::InvalidForward { requested_forward_scid: phantom_scid }]
18041804
);
18051805
check_added_monitors(&nodes[1], 1);
18061806

@@ -1905,7 +1905,7 @@ fn do_test_phantom_dust_exposure_failure(multiplier_dust_limit: bool) {
19051905
expect_pending_htlcs_forwardable!(nodes[1]);
19061906
expect_htlc_handling_failed_destinations!(
19071907
nodes[1].node.get_and_clear_pending_events(),
1908-
&[HTLCHandlingFailureType::UnknownNextHop { requested_forward_scid: phantom_scid }]
1908+
&[HTLCHandlingFailureType::InvalidForward { requested_forward_scid: phantom_scid }]
19091909
);
19101910
check_added_monitors(&nodes[1], 1);
19111911

lightning/src/ln/payment_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ fn do_test_intercepted_payment(test: InterceptTest) {
19391939
if test == InterceptTest::Fail {
19401940
// Ensure we can fail the intercepted payment back.
19411941
nodes[1].node.fail_intercepted_htlc(intercept_id).unwrap();
1942-
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], vec![HTLCHandlingFailureType::UnknownNextHop { requested_forward_scid: intercept_scid }]);
1942+
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], vec![HTLCHandlingFailureType::InvalidForward { requested_forward_scid: intercept_scid }]);
19431943
nodes[1].node.process_pending_htlc_forwards();
19441944
let update_fail = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
19451945
check_added_monitors!(&nodes[1], 1);
@@ -3406,7 +3406,7 @@ fn test_threaded_payment_retries() {
34063406
nodes[1].node.process_pending_htlc_forwards();
34073407
expect_htlc_handling_failed_destinations!(
34083408
nodes[1].node.get_and_clear_pending_events(),
3409-
&[HTLCHandlingFailureType::UnknownNextHop { requested_forward_scid: route.paths[0].hops[1].short_channel_id }]
3409+
&[HTLCHandlingFailureType::InvalidForward { requested_forward_scid: route.paths[0].hops[1].short_channel_id }]
34103410
);
34113411
check_added_monitors(&nodes[1], 1);
34123412

0 commit comments

Comments
 (0)