@@ -1083,19 +1083,29 @@ macro_rules! check_added_monitors {
1083
1083
}
1084
1084
}
1085
1085
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 {
1091
1087
let mut nodes = path. iter ( ) . rev ( ) ;
1092
1088
let dest = nodes. next ( ) . expect ( "path should have a destination" ) . node ;
1093
1089
let prev = nodes. next ( ) . unwrap_or ( & origin_node) . node ;
1094
1090
let dest_channels = dest. list_channels ( ) ;
1095
1091
let ch = dest_channels. iter ( ) . find ( |ch| ch. channel_id == htlc. channel_id )
1096
1092
. 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
+ }
1099
1109
}
1100
1110
1101
1111
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 {
2832
2842
assert_eq ! ( htlcs. len( ) , expected_paths. len( ) ) ; // One per path.
2833
2843
assert_eq ! ( htlcs. iter( ) . map( |h| h. value_msat) . sum:: <u64 >( ) , amount_msat) ;
2834
2844
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 ) ;
2836
2846
fwd_amt_msat = amount_msat;
2837
2847
} ,
2838
2848
Event :: PaymentClaimed {
@@ -2849,7 +2859,7 @@ pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
2849
2859
assert_eq ! ( htlcs. len( ) , expected_paths. len( ) ) ; // One per path.
2850
2860
assert_eq ! ( htlcs. iter( ) . map( |h| h. value_msat) . sum:: <u64 >( ) , amount_msat) ;
2851
2861
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 ) ;
2853
2863
fwd_amt_msat = amount_msat;
2854
2864
}
2855
2865
_ => panic ! ( ) ,
0 commit comments