@@ -1150,6 +1150,45 @@ fn test_phantom_failure_modified_cltv() {
1150
1150
expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false , fail_conditions) ;
1151
1151
}
1152
1152
1153
+ #[ test]
1154
+ fn test_phantom_failure_expires_too_soon ( ) {
1155
+ // Test that we fail back phantoms if the HTLC got delayed and we got blocks in between with
1156
+ // the correct error code.
1157
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1158
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1159
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
1160
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1161
+
1162
+ let channel = create_announced_chan_between_nodes ( & nodes, 0 , 1 , channelmanager:: provided_init_features ( ) , channelmanager:: provided_init_features ( ) ) ;
1163
+
1164
+ // Get the route.
1165
+ let recv_value_msat = 10_000 ;
1166
+ let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ! ( nodes[ 1 ] , Some ( recv_value_msat) ) ;
1167
+ let ( mut route, phantom_scid) = get_phantom_route ! ( nodes, recv_value_msat, channel) ;
1168
+
1169
+ // Route the HTLC through to the destination.
1170
+ nodes[ 0 ] . node . send_payment ( & route, payment_hash, & Some ( payment_secret) , PaymentId ( payment_hash. 0 ) ) . unwrap ( ) ;
1171
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
1172
+ let update_0 = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
1173
+ let mut update_add = update_0. update_add_htlcs [ 0 ] . clone ( ) ;
1174
+
1175
+ connect_blocks ( & nodes[ 1 ] , CLTV_FAR_FAR_AWAY ) ;
1176
+ nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & update_add) ;
1177
+ commitment_signed_dance ! ( nodes[ 1 ] , nodes[ 0 ] , & update_0. commitment_signed, false , true ) ;
1178
+
1179
+ let update_1 = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
1180
+ assert ! ( update_1. update_fail_htlcs. len( ) == 1 ) ;
1181
+ let fail_msg = update_1. update_fail_htlcs [ 0 ] . clone ( ) ;
1182
+ nodes[ 0 ] . node . handle_update_fail_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & fail_msg) ;
1183
+ commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , update_1. commitment_signed, false ) ;
1184
+
1185
+ // Ensure the payment fails with the expected error.
1186
+ let mut fail_conditions = PaymentFailedConditions :: new ( )
1187
+ . blamed_scid ( phantom_scid)
1188
+ . expected_htlc_error_data ( 0x2000 | 2 , & [ ] ) ;
1189
+ expect_payment_failed_conditions ( & nodes[ 0 ] , payment_hash, false , fail_conditions) ;
1190
+ }
1191
+
1153
1192
#[ test]
1154
1193
fn test_phantom_failure_too_low_recv_amt ( ) {
1155
1194
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
0 commit comments