Skip to content

Commit 803366a

Browse files
committed
Do not check the ordering of HTLCs in PaymentClaim[able,ed]
In the next commit we'll change the order of HTLCs in `PaymentClaim[able,ed]` events. This shouldn't break anything, but our current functional tests check that the HTLCs are provided in the order they expect (the order they were received). Instead, here we only validate that each claimed HTLC matches one expected path.
1 parent cdd1298 commit 803366a

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

lightning/src/ln/functional_test_utils.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -1083,19 +1083,29 @@ macro_rules! check_added_monitors {
10831083
}
10841084
}
10851085

1086-
/// Checks whether the claimed HTLC for the specified path has the correct channel information.
1087-
///
1088-
/// This will panic if the path is empty, if the HTLC's channel ID is not actually a channel that
1089-
/// connects the final two nodes in the path, or if the `user_channel_id` is incorrect.
1090-
pub fn check_claimed_htlc_channel<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], htlc: &ClaimedHTLC) {
1086+
fn claimed_htlc_matches_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], htlc: &ClaimedHTLC) -> bool {
10911087
let mut nodes = path.iter().rev();
10921088
let dest = nodes.next().expect("path should have a destination").node;
10931089
let prev = nodes.next().unwrap_or(&origin_node).node;
10941090
let dest_channels = dest.list_channels();
10951091
let ch = dest_channels.iter().find(|ch| ch.channel_id == htlc.channel_id)
10961092
.expect("HTLC's channel should be one of destination node's channels");
1097-
assert_eq!(htlc.user_channel_id, ch.user_channel_id);
1098-
assert_eq!(ch.counterparty.node_id, prev.get_our_node_id());
1093+
htlc.user_channel_id == ch.user_channel_id &&
1094+
ch.counterparty.node_id == prev.get_our_node_id()
1095+
}
1096+
1097+
fn check_claimed_htlcs_match_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: &[&[&Node<'a, 'b, 'c>]], htlcs: &[ClaimedHTLC]) {
1098+
assert_eq!(route.len(), htlcs.len());
1099+
for path in route {
1100+
let mut found_matching_htlc = false;
1101+
for htlc in htlcs {
1102+
if claimed_htlc_matches_path(origin_node, path, htlc) {
1103+
found_matching_htlc = true;
1104+
break;
1105+
}
1106+
}
1107+
assert!(found_matching_htlc);
1108+
}
10991109
}
11001110

11011111
pub fn _reload_node<'a, 'b, 'c>(node: &'a Node<'a, 'b, 'c>, default_config: UserConfig, chanman_encoded: &[u8], monitors_encoded: &[&[u8]]) -> TestChannelManager<'b, 'c> {
@@ -2832,7 +2842,7 @@ pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
28322842
assert_eq!(htlcs.len(), expected_paths.len()); // One per path.
28332843
assert_eq!(htlcs.iter().map(|h| h.value_msat).sum::<u64>(), amount_msat);
28342844
assert_eq!(onion_fields.as_ref().unwrap().custom_tlvs, custom_tlvs);
2835-
expected_paths.iter().zip(htlcs).for_each(|(path, htlc)| check_claimed_htlc_channel(origin_node, path, htlc));
2845+
check_claimed_htlcs_match_route(origin_node, expected_paths, htlcs);
28362846
fwd_amt_msat = amount_msat;
28372847
},
28382848
Event::PaymentClaimed {
@@ -2849,7 +2859,7 @@ pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
28492859
assert_eq!(htlcs.len(), expected_paths.len()); // One per path.
28502860
assert_eq!(htlcs.iter().map(|h| h.value_msat).sum::<u64>(), amount_msat);
28512861
assert_eq!(onion_fields.as_ref().unwrap().custom_tlvs, custom_tlvs);
2852-
expected_paths.iter().zip(htlcs).for_each(|(path, htlc)| check_claimed_htlc_channel(origin_node, path, htlc));
2862+
check_claimed_htlcs_match_route(origin_node, expected_paths, htlcs);
28532863
fwd_amt_msat = amount_msat;
28542864
}
28552865
_ => panic!(),

0 commit comments

Comments
 (0)