@@ -1173,17 +1173,21 @@ fn test_onion_failure() {
1173
1173
|_| { } ,
1174
1174
|| {
1175
1175
nodes[ 1 ] . node . process_pending_update_add_htlcs ( ) ;
1176
- for ( _, pending_forwards) in nodes[ 1 ] . node . forward_htlcs . lock ( ) . unwrap ( ) . iter_mut ( ) {
1177
- for f in pending_forwards. iter_mut ( ) {
1178
- match f {
1179
- & mut HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
1180
- ref mut forward_info,
1181
- ..
1182
- } ) => forward_info. outgoing_cltv_value -= 1 ,
1183
- _ => { } ,
1184
- }
1176
+ assert_eq ! ( nodes[ 1 ] . node. forward_htlcs. lock( ) . unwrap( ) . len( ) , 1 ) ;
1177
+ if let Some ( ( _, pending_forwards) ) =
1178
+ nodes[ 1 ] . node . forward_htlcs . lock ( ) . unwrap ( ) . iter_mut ( ) . next ( )
1179
+ {
1180
+ assert_eq ! ( pending_forwards. len( ) , 1 ) ;
1181
+ match pending_forwards. get_mut ( 0 ) . unwrap ( ) {
1182
+ & mut HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
1183
+ ref mut forward_info,
1184
+ ..
1185
+ } ) => forward_info. outgoing_cltv_value -= 1 ,
1186
+ _ => panic ! ( "Unexpected HTLCForwardInfo" ) ,
1185
1187
}
1186
- }
1188
+ } else {
1189
+ panic ! ( "Expected pending forwards!" ) ;
1190
+ } ;
1187
1191
} ,
1188
1192
true ,
1189
1193
Some ( LocalHTLCFailureReason :: FinalIncorrectCLTVExpiry ) ,
@@ -1203,17 +1207,21 @@ fn test_onion_failure() {
1203
1207
|| {
1204
1208
nodes[ 1 ] . node . process_pending_update_add_htlcs ( ) ;
1205
1209
// violate amt_to_forward > msg.amount_msat
1206
- for ( _, pending_forwards) in nodes[ 1 ] . node . forward_htlcs . lock ( ) . unwrap ( ) . iter_mut ( ) {
1207
- for f in pending_forwards. iter_mut ( ) {
1208
- match f {
1209
- & mut HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
1210
- ref mut forward_info,
1211
- ..
1212
- } ) => forward_info. outgoing_amt_msat -= 1 ,
1213
- _ => { } ,
1214
- }
1210
+ assert_eq ! ( nodes[ 1 ] . node. forward_htlcs. lock( ) . unwrap( ) . len( ) , 1 ) ;
1211
+ if let Some ( ( _, pending_forwards) ) =
1212
+ nodes[ 1 ] . node . forward_htlcs . lock ( ) . unwrap ( ) . iter_mut ( ) . next ( )
1213
+ {
1214
+ assert_eq ! ( pending_forwards. len( ) , 1 ) ;
1215
+ match pending_forwards. get_mut ( 0 ) . unwrap ( ) {
1216
+ & mut HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
1217
+ ref mut forward_info,
1218
+ ..
1219
+ } ) => forward_info. outgoing_amt_msat -= 1 ,
1220
+ _ => panic ! ( "Unexpected HTLCForwardInfo" ) ,
1215
1221
}
1216
- }
1222
+ } else {
1223
+ panic ! ( "Expected pending forwards!" ) ;
1224
+ } ;
1217
1225
} ,
1218
1226
true ,
1219
1227
Some ( LocalHTLCFailureReason :: FinalIncorrectHTLCAmount ) ,
@@ -1554,16 +1562,20 @@ fn test_overshoot_final_cltv() {
1554
1562
1555
1563
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
1556
1564
nodes[ 1 ] . node . process_pending_update_add_htlcs ( ) ;
1557
- for ( _, pending_forwards) in nodes[ 1 ] . node . forward_htlcs . lock ( ) . unwrap ( ) . iter_mut ( ) {
1558
- for f in pending_forwards. iter_mut ( ) {
1559
- match f {
1560
- & mut HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
1561
- ref mut forward_info, ..
1562
- } ) => forward_info. outgoing_cltv_value += 1 ,
1563
- _ => { } ,
1564
- }
1565
+ assert_eq ! ( nodes[ 1 ] . node. forward_htlcs. lock( ) . unwrap( ) . len( ) , 1 ) ;
1566
+ if let Some ( ( _, pending_forwards) ) =
1567
+ nodes[ 1 ] . node . forward_htlcs . lock ( ) . unwrap ( ) . iter_mut ( ) . next ( )
1568
+ {
1569
+ assert_eq ! ( pending_forwards. len( ) , 1 ) ;
1570
+ match pending_forwards. get_mut ( 0 ) . unwrap ( ) {
1571
+ & mut HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo { ref mut forward_info, .. } ) => {
1572
+ forward_info. outgoing_cltv_value += 1
1573
+ } ,
1574
+ _ => panic ! ( "Unexpected HTLCForwardInfo" ) ,
1565
1575
}
1566
- }
1576
+ } else {
1577
+ panic ! ( "Expected pending forwards!" ) ;
1578
+ } ;
1567
1579
expect_and_process_pending_htlcs ( & nodes[ 1 ] , false ) ;
1568
1580
1569
1581
check_added_monitors ! ( & nodes[ 1 ] , 1 ) ;
@@ -2615,19 +2627,23 @@ fn test_phantom_final_incorrect_cltv_expiry() {
2615
2627
nodes[ 1 ] . node . process_pending_update_add_htlcs ( ) ;
2616
2628
2617
2629
// Modify the payload so the phantom hop's HMAC is bogus.
2618
- for ( _, pending_forwards) in nodes[ 1 ] . node . forward_htlcs . lock ( ) . unwrap ( ) . iter_mut ( ) {
2619
- for f in pending_forwards. iter_mut ( ) {
2620
- match f {
2621
- & mut HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
2622
- forward_info : PendingHTLCInfo { ref mut outgoing_cltv_value, .. } ,
2623
- ..
2624
- } ) => {
2625
- * outgoing_cltv_value -= 1 ;
2626
- } ,
2627
- _ => panic ! ( "Unexpected forward" ) ,
2628
- }
2630
+ assert_eq ! ( nodes[ 1 ] . node. forward_htlcs. lock( ) . unwrap( ) . len( ) , 1 ) ;
2631
+ if let Some ( ( _, pending_forwards) ) =
2632
+ nodes[ 1 ] . node . forward_htlcs . lock ( ) . unwrap ( ) . iter_mut ( ) . next ( )
2633
+ {
2634
+ assert_eq ! ( pending_forwards. len( ) , 1 ) ;
2635
+ match pending_forwards. get_mut ( 0 ) . unwrap ( ) {
2636
+ & mut HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
2637
+ forward_info : PendingHTLCInfo { ref mut outgoing_cltv_value, .. } ,
2638
+ ..
2639
+ } ) => {
2640
+ * outgoing_cltv_value -= 1 ;
2641
+ } ,
2642
+ _ => panic ! ( "Unexpected HTLCForwardInfo" ) ,
2629
2643
}
2630
- }
2644
+ } else {
2645
+ panic ! ( "Expected pending forwards!" ) ;
2646
+ } ;
2631
2647
nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
2632
2648
expect_htlc_failure_conditions (
2633
2649
nodes[ 1 ] . node . get_and_clear_pending_events ( ) ,
0 commit comments