@@ -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 ) ,
@@ -1553,16 +1561,21 @@ fn test_overshoot_final_cltv() {
1553
1561
commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , & update_0. commitment_signed, false , true ) ;
1554
1562
1555
1563
assert ! ( nodes[ 1 ] . node. get_and_clear_pending_msg_events( ) . is_empty( ) ) ;
1556
- for ( _, pending_forwards) in nodes[ 1 ] . node . forward_htlcs . lock ( ) . unwrap ( ) . iter_mut ( ) {
1557
- for f in pending_forwards. iter_mut ( ) {
1558
- match f {
1559
- & mut HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
1560
- ref mut forward_info, ..
1561
- } ) => forward_info. outgoing_cltv_value += 1 ,
1562
- _ => { } ,
1563
- }
1564
+ nodes[ 1 ] . node . process_pending_update_add_htlcs ( ) ;
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" ) ,
1564
1575
}
1565
- }
1576
+ } else {
1577
+ panic ! ( "Expected pending forwards!" ) ;
1578
+ } ;
1566
1579
expect_and_process_pending_htlcs ( & nodes[ 1 ] , false ) ;
1567
1580
1568
1581
check_added_monitors ! ( & nodes[ 1 ] , 1 ) ;
@@ -2614,19 +2627,22 @@ fn test_phantom_final_incorrect_cltv_expiry() {
2614
2627
nodes[ 1 ] . node . process_pending_update_add_htlcs ( ) ;
2615
2628
2616
2629
// Modify the payload so the phantom hop's HMAC is bogus.
2617
- for ( _, pending_forwards) in nodes[ 1 ] . node . forward_htlcs . lock ( ) . unwrap ( ) . iter_mut ( ) {
2618
- for f in pending_forwards. iter_mut ( ) {
2619
- match f {
2620
- & mut HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
2621
- forward_info : PendingHTLCInfo { ref mut outgoing_cltv_value, .. } ,
2622
- ..
2623
- } ) => {
2624
- * outgoing_cltv_value -= 1 ;
2625
- } ,
2626
- _ => panic ! ( "Unexpected forward" ) ,
2627
- }
2630
+ if let Some ( ( _, pending_forwards) ) =
2631
+ nodes[ 1 ] . node . forward_htlcs . lock ( ) . unwrap ( ) . iter_mut ( ) . next ( )
2632
+ {
2633
+ assert_eq ! ( pending_forwards. len( ) , 1 ) ;
2634
+ match pending_forwards. get_mut ( 0 ) . unwrap ( ) {
2635
+ & mut HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
2636
+ forward_info : PendingHTLCInfo { ref mut outgoing_cltv_value, .. } ,
2637
+ ..
2638
+ } ) => {
2639
+ * outgoing_cltv_value -= 1 ;
2640
+ } ,
2641
+ _ => panic ! ( "Unexpected HTLCForwardInfo" ) ,
2628
2642
}
2629
- }
2643
+ } else {
2644
+ panic ! ( "Expected pending forwards!" ) ;
2645
+ } ;
2630
2646
nodes[ 1 ] . node . process_pending_htlc_forwards ( ) ;
2631
2647
expect_htlc_failure_conditions (
2632
2648
nodes[ 1 ] . node . get_and_clear_pending_events ( ) ,
0 commit comments