Skip to content

Commit c78304f

Browse files
committed
ln+events: deprecate UnknownNextPeer in HTLCHandlingType
This variant of HTLCHandlingType contains information about the failure cause along with its type - as an UnknownNextPeer is just an InvalidForward that has the failure type UnknownNextPeer. This commit deprecates the variant's use, while still writing it to disk to allow the option to downgrade. 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 09cf15e commit c78304f

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

lightning/src/events/mod.rs

+43-3
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,16 @@ pub enum HTLCHandlingType {
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.
483485
UnknownNextHop {
484486
/// Short channel id we are requesting to forward an HTLC to.
485487
requested_forward_scid: u64,
486488
},
487489
/// We couldn't forward to the outgoing scid. An example would be attempting to send a duplicate
488490
/// intercept HTLC.
491+
///
492+
/// In LDK v0.2.0 and greater, this variant replaces [`Self::UnknownNextHop`].
489493
InvalidForward {
490494
/// Short channel id we are requesting to forward an HTLC to.
491495
requested_forward_scid: u64
@@ -1797,10 +1801,26 @@ impl Writeable for Event {
17971801
},
17981802
&Event::HTLCHandlingFailed { ref prev_channel_id, ref handling_type, ref handling_failure } => {
17991803
25u8.write(writer)?;
1804+
1805+
// The [`HTLCHandlingType::UnknownNextPeer`] variant is deprecated, but we want to
1806+
// continue writing it to allow downgrading. Detect the case where we're
1807+
// representing it as [`HTLCHandlingType::InvalidForward`] and
1808+
// [`LocalHTLCFailureReason::UnknownNextHop`] and write the old variant instead.
1809+
let downgradable_type = match (handling_type, handling_failure) {
1810+
(HTLCHandlingType::InvalidForward { requested_forward_scid },
1811+
Some(HTLCHandlingFailureReason::Local {
1812+
reason: LocalHTLCFailureReason::UnknownNextPeer
1813+
}))
1814+
=> HTLCHandlingType::UnknownNextHop {
1815+
requested_forward_scid: *requested_forward_scid,
1816+
},
1817+
_ => handling_type.clone()
1818+
};
1819+
18001820
write_tlv_fields!(writer, {
18011821
(0, prev_channel_id, required),
18021822
(1, handling_failure, option),
1803-
(2, handling_type, required),
1823+
(2, downgradable_type, required),
18041824
})
18051825
},
18061826
&Event::BumpTransaction(ref event)=> {
@@ -2255,11 +2275,31 @@ impl MaybeReadable for Event {
22552275
(1, handling_failure, option),
22562276
(2, handling_type_opt, upgradable_required),
22572277
});
2258-
Ok(Some(Event::HTLCHandlingFailed {
2278+
2279+
let mut event = Event::HTLCHandlingFailed {
22592280
prev_channel_id,
22602281
handling_type: _init_tlv_based_struct_field!(handling_type_opt, upgradable_required),
22612282
handling_failure,
2262-
}))
2283+
};
2284+
2285+
// The [`HTLCHandlingType::UnknownNextPeer`] variant is deprecated, but we
2286+
// continue writing it to allow downgrading. If it was written, upgrade
2287+
// it to its new representation of [`HTLCHandlingType::InvalidForward`] and
2288+
// [`LocalHTLCFailureReason::UnknownNextHop`]. This will cover both the case
2289+
// where we have a legacy event and new events that are written with the legacy
2290+
// type be downgradable.
2291+
match event {
2292+
Event::HTLCHandlingFailed { handling_type: HTLCHandlingType::UnknownNextHop { requested_forward_scid }, .. } => {
2293+
event = Event::HTLCHandlingFailed {
2294+
prev_channel_id,
2295+
handling_type: HTLCHandlingType::InvalidForward { requested_forward_scid },
2296+
handling_failure: Some(LocalHTLCFailureReason::UnknownNextPeer.into()),
2297+
}
2298+
}
2299+
_ => panic!("HTLCHandlingFailed wrong type")
2300+
}
2301+
2302+
Ok(Some(event))
22632303
};
22642304
f()
22652305
},

lightning/src/ln/blinded_payment_tests.rs

+2-2
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![HTLCHandlingType::UnknownNextHop { requested_forward_scid: $failed_scid }]);
629+
vec![HTLCHandlingType::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![HTLCHandlingType::UnknownNextHop { requested_forward_scid: intercept_scid }]);
728+
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], vec![HTLCHandlingType::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

+3-3
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 = HTLCHandlingType::UnknownNextHop { requested_forward_scid: short_channel_id };
5736+
let destination = HTLCHandlingType::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 => HTLCHandlingType::UnknownNextHop {
5755+
None => HTLCHandlingType::InvalidForward {
57565756
requested_forward_scid: outgoing_scid,
57575757
},
57585758
}
@@ -5931,7 +5931,7 @@ where
59315931
});
59325932

59335933
let reason = if $next_hop_unknown {
5934-
HTLCHandlingType::UnknownNextHop { requested_forward_scid: short_chan_id }
5934+
HTLCHandlingType::InvalidForward { requested_forward_scid: short_chan_id }
59355935
} else {
59365936
HTLCHandlingType::ReceiveFailed{ payment_hash }
59375937
};

lightning/src/ln/onion_route_tests.rs

+4-4
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(HTLCHandlingType::UnknownNextHop { requested_forward_scid: short_channel_id }));
552+
Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent:true}), Some(short_channel_id), Some(HTLCHandlingType::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-
&[HTLCHandlingType::UnknownNextHop { requested_forward_scid: phantom_scid }]
1754+
&[HTLCHandlingType::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-
&[HTLCHandlingType::UnknownNextHop { requested_forward_scid: phantom_scid }]
1803+
&[HTLCHandlingType::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-
&[HTLCHandlingType::UnknownNextHop { requested_forward_scid: phantom_scid }]
1908+
&[HTLCHandlingType::InvalidForward { requested_forward_scid: phantom_scid }]
19091909
);
19101910
check_added_monitors(&nodes[1], 1);
19111911

lightning/src/ln/payment_tests.rs

+2-2
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![HTLCHandlingType::UnknownNextHop { requested_forward_scid: intercept_scid }]);
1942+
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[1], vec![HTLCHandlingType::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-
&[HTLCHandlingType::UnknownNextHop { requested_forward_scid: route.paths[0].hops[1].short_channel_id }]
3409+
&[HTLCHandlingType::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)