@@ -2222,7 +2222,7 @@ enum HTLCStatusAtDupClaim {
2222
2222
HoldingCell ,
2223
2223
Cleared ,
2224
2224
}
2225
- fn do_test_reconnect_dup_htlc_claims ( htlc_status : HTLCStatusAtDupClaim ) {
2225
+ fn do_test_reconnect_dup_htlc_claims ( htlc_status : HTLCStatusAtDupClaim , second_fails : bool ) {
2226
2226
// When receiving an update_fulfill_htlc message, we immediately forward the claim backwards
2227
2227
// along the payment path before waiting for a full commitment_signed dance. This is great, but
2228
2228
// can cause duplicative claims if a node sends an update_fulfill_htlc message, disconnects,
@@ -2235,9 +2235,9 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim) {
2235
2235
let mut nodes = create_network ( 3 , & node_cfgs, & node_chanmgrs) ;
2236
2236
2237
2237
create_announced_chan_between_nodes ( & nodes, 0 , 1 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
2238
- create_announced_chan_between_nodes ( & nodes, 1 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
2238
+ let chan_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) . 2 ;
2239
2239
2240
- let preimage = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 100_000 ) . 0 ;
2240
+ let ( payment_preimage , payment_hash , _ ) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] , & nodes[ 2 ] ] , 100_000 ) ;
2241
2241
2242
2242
let mut as_raa = None ;
2243
2243
if htlc_status == HTLCStatusAtDupClaim :: HoldingCell {
@@ -2263,19 +2263,33 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim) {
2263
2263
as_raa = Some ( get_event_msg ! ( nodes[ 0 ] , MessageSendEvent :: SendRevokeAndACK , nodes[ 1 ] . node. get_our_node_id( ) ) ) ;
2264
2264
}
2265
2265
2266
- assert ! ( nodes[ 2 ] . node. claim_funds( preimage) ) ;
2267
- check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
2268
- let cs_updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
2269
- assert_eq ! ( cs_updates. update_fulfill_htlcs. len( ) , 1 ) ;
2270
- nodes[ 1 ] . node . handle_update_fulfill_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & cs_updates. update_fulfill_htlcs [ 0 ] ) ;
2266
+ let fulfill_msg = msgs:: UpdateFulfillHTLC {
2267
+ channel_id : chan_2,
2268
+ htlc_id : 0 ,
2269
+ payment_preimage,
2270
+ } ;
2271
+ if second_fails {
2272
+ assert ! ( nodes[ 2 ] . node. fail_htlc_backwards( & payment_hash) ) ;
2273
+ expect_pending_htlcs_forwardable ! ( nodes[ 2 ] ) ;
2274
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
2275
+ get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
2276
+ } else {
2277
+ assert ! ( nodes[ 2 ] . node. claim_funds( payment_preimage) ) ;
2278
+ check_added_monitors ! ( nodes[ 2 ] , 1 ) ;
2279
+ let cs_updates = get_htlc_update_msgs ! ( nodes[ 2 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
2280
+ assert_eq ! ( cs_updates. update_fulfill_htlcs. len( ) , 1 ) ;
2281
+ // Check that the message we're about to deliver matches the one generated:
2282
+ assert_eq ! ( fulfill_msg, cs_updates. update_fulfill_htlcs[ 0 ] ) ;
2283
+ }
2284
+ nodes[ 1 ] . node . handle_update_fulfill_htlc ( & nodes[ 2 ] . node . get_our_node_id ( ) , & fulfill_msg) ;
2271
2285
check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
2272
2286
2273
2287
let mut bs_updates = None ;
2274
2288
if htlc_status != HTLCStatusAtDupClaim :: HoldingCell {
2275
2289
bs_updates = Some ( get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ) ;
2276
2290
assert_eq ! ( bs_updates. as_ref( ) . unwrap( ) . update_fulfill_htlcs. len( ) , 1 ) ;
2277
2291
nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_updates. as_ref ( ) . unwrap ( ) . update_fulfill_htlcs [ 0 ] ) ;
2278
- expect_payment_sent ! ( nodes[ 0 ] , preimage ) ;
2292
+ expect_payment_sent ! ( nodes[ 0 ] , payment_preimage ) ;
2279
2293
if htlc_status == HTLCStatusAtDupClaim :: Cleared {
2280
2294
commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , & bs_updates. as_ref( ) . unwrap( ) . commitment_signed, false ) ;
2281
2295
}
@@ -2286,7 +2300,12 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim) {
2286
2300
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 2 ] . node . get_our_node_id ( ) , false ) ;
2287
2301
nodes[ 2 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
2288
2302
2289
- reconnect_nodes ( & nodes[ 1 ] , & nodes[ 2 ] , ( false , false ) , ( 0 , 0 ) , ( 1 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
2303
+ if second_fails {
2304
+ reconnect_nodes ( & nodes[ 1 ] , & nodes[ 2 ] , ( false , false ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 1 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
2305
+ expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
2306
+ } else {
2307
+ reconnect_nodes ( & nodes[ 1 ] , & nodes[ 2 ] , ( false , false ) , ( 0 , 0 ) , ( 1 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
2308
+ }
2290
2309
2291
2310
if htlc_status == HTLCStatusAtDupClaim :: HoldingCell {
2292
2311
nodes[ 1 ] . node . handle_revoke_and_ack ( & nodes[ 0 ] . node . get_our_node_id ( ) , & as_raa. unwrap ( ) ) ;
@@ -2296,7 +2315,7 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim) {
2296
2315
bs_updates = Some ( get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ) ;
2297
2316
assert_eq ! ( bs_updates. as_ref( ) . unwrap( ) . update_fulfill_htlcs. len( ) , 1 ) ;
2298
2317
nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_updates. as_ref ( ) . unwrap ( ) . update_fulfill_htlcs [ 0 ] ) ;
2299
- expect_payment_sent ! ( nodes[ 0 ] , preimage ) ;
2318
+ expect_payment_sent ! ( nodes[ 0 ] , payment_preimage ) ;
2300
2319
}
2301
2320
if htlc_status != HTLCStatusAtDupClaim :: Cleared {
2302
2321
commitment_signed_dance ! ( nodes[ 0 ] , nodes[ 1 ] , & bs_updates. as_ref( ) . unwrap( ) . commitment_signed, false ) ;
@@ -2305,7 +2324,10 @@ fn do_test_reconnect_dup_htlc_claims(htlc_status: HTLCStatusAtDupClaim) {
2305
2324
2306
2325
#[ test]
2307
2326
fn test_reconnect_dup_htlc_claims ( ) {
2308
- do_test_reconnect_dup_htlc_claims ( HTLCStatusAtDupClaim :: Received ) ;
2309
- do_test_reconnect_dup_htlc_claims ( HTLCStatusAtDupClaim :: HoldingCell ) ;
2310
- do_test_reconnect_dup_htlc_claims ( HTLCStatusAtDupClaim :: Cleared ) ;
2327
+ do_test_reconnect_dup_htlc_claims ( HTLCStatusAtDupClaim :: Received , false ) ;
2328
+ do_test_reconnect_dup_htlc_claims ( HTLCStatusAtDupClaim :: HoldingCell , false ) ;
2329
+ do_test_reconnect_dup_htlc_claims ( HTLCStatusAtDupClaim :: Cleared , false ) ;
2330
+ do_test_reconnect_dup_htlc_claims ( HTLCStatusAtDupClaim :: Received , true ) ;
2331
+ do_test_reconnect_dup_htlc_claims ( HTLCStatusAtDupClaim :: HoldingCell , true ) ;
2332
+ do_test_reconnect_dup_htlc_claims ( HTLCStatusAtDupClaim :: Cleared , true ) ;
2311
2333
}
0 commit comments