Skip to content

Commit af0ce12

Browse files
committed
Test the new RAAMonitorUpdateBlockingAction::ClaimedMPPPayment
1 parent 3d4b71a commit af0ce12

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

+116
Original file line numberDiff line numberDiff line change
@@ -3598,3 +3598,119 @@ fn test_glacial_peer_cant_hang() {
35983598
do_test_glacial_peer_cant_hang(false);
35993599
do_test_glacial_peer_cant_hang(true);
36003600
}
3601+
3602+
#[test]
3603+
fn test_partial_claim_mon_update_compl_actions() {
3604+
// Test that if we have an MPP claim that we ensure the preimage for the claim is retained in
3605+
// the all `ChannelMonitor`s until the preimage reaches every `ChannelMonitor` for a channel
3606+
// which was a part of the MPP.
3607+
let chanmon_cfgs = create_chanmon_cfgs(4);
3608+
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
3609+
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, None]);
3610+
let mut nodes = create_network(4, &node_cfgs, &node_chanmgrs);
3611+
3612+
let chan_1_scid = create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
3613+
let chan_2_scid = create_announced_chan_between_nodes(&nodes, 0, 2).0.contents.short_channel_id;
3614+
let (chan_3_update, _, chan_3_id, ..) = create_announced_chan_between_nodes(&nodes, 1, 3);
3615+
let chan_3_scid = chan_3_update.contents.short_channel_id;
3616+
let (chan_4_update, _, chan_4_id, ..) = create_announced_chan_between_nodes(&nodes, 2, 3);
3617+
let chan_4_scid = chan_4_update.contents.short_channel_id;
3618+
3619+
let (mut route, payment_hash, preimage, payment_secret) = get_route_and_payment_hash!(&nodes[0], nodes[3], 100000);
3620+
let path = route.paths[0].clone();
3621+
route.paths.push(path);
3622+
route.paths[0].hops[0].pubkey = nodes[1].node.get_our_node_id();
3623+
route.paths[0].hops[0].short_channel_id = chan_1_scid;
3624+
route.paths[0].hops[1].short_channel_id = chan_3_scid;
3625+
route.paths[1].hops[0].pubkey = nodes[2].node.get_our_node_id();
3626+
route.paths[1].hops[0].short_channel_id = chan_2_scid;
3627+
route.paths[1].hops[1].short_channel_id = chan_4_scid;
3628+
send_along_route_with_secret(&nodes[0], route, &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]], 200_000, payment_hash, payment_secret);
3629+
3630+
let ds_chan_4_mon = get_monitor!(nodes[3], chan_4_id).encode();
3631+
3632+
// Claim along both paths, but only complete one of the two monitor updates.
3633+
chanmon_cfgs[3].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
3634+
chanmon_cfgs[3].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
3635+
nodes[3].node.claim_funds(preimage);
3636+
assert_eq!(nodes[3].node.get_and_clear_pending_msg_events(), Vec::new());
3637+
assert_eq!(nodes[3].node.get_and_clear_pending_events(), Vec::new());
3638+
check_added_monitors(&nodes[3], 2);
3639+
3640+
// Complete the 1<->3 monitor update and play the commitment_signed dance forward until it
3641+
// blocks.
3642+
nodes[3].chain_monitor.complete_sole_pending_chan_update(&chan_3_id);
3643+
expect_payment_claimed!(&nodes[3], payment_hash, 200_000);
3644+
let updates = get_htlc_update_msgs(&nodes[3], &nodes[1].node.get_our_node_id());
3645+
3646+
nodes[1].node.handle_update_fulfill_htlc(&nodes[3].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]);
3647+
check_added_monitors(&nodes[1], 1);
3648+
expect_payment_forwarded!(nodes[1], nodes[0], nodes[3], Some(1000), false, false);
3649+
let _bs_updates_for_a = get_htlc_update_msgs(&nodes[1], &nodes[0].node.get_our_node_id());
3650+
3651+
nodes[1].node.handle_commitment_signed(&nodes[3].node.get_our_node_id(), &updates.commitment_signed);
3652+
check_added_monitors(&nodes[1], 1);
3653+
let (bs_raa, bs_cs) = get_revoke_commit_msgs(&nodes[1], &nodes[3].node.get_our_node_id());
3654+
3655+
nodes[3].node.handle_revoke_and_ack(&nodes[1].node.get_our_node_id(), &bs_raa);
3656+
check_added_monitors(&nodes[3], 0);
3657+
3658+
nodes[3].node.handle_commitment_signed(&nodes[1].node.get_our_node_id(), &bs_cs);
3659+
check_added_monitors(&nodes[3], 0);
3660+
assert!(nodes[3].node.get_and_clear_pending_msg_events().is_empty());
3661+
3662+
// Now double-check that the preimage is still in the 1<->3 channel and complete the pending
3663+
// monitor update, allowing node 3 to claim the payment on the 2<->3 channel. This also
3664+
// unblocks the 1<->3 channel, allowing node 3 to release the two blocked monitor updates and
3665+
// respond to the final commitment_signed.
3666+
assert!(get_monitor!(nodes[3], chan_3_id).get_stored_preimages().contains_key(&payment_hash));
3667+
3668+
nodes[3].chain_monitor.complete_sole_pending_chan_update(&chan_4_id);
3669+
let mut ds_msgs = nodes[3].node.get_and_clear_pending_msg_events();
3670+
assert_eq!(ds_msgs.len(), 2);
3671+
check_added_monitors(&nodes[3], 2);
3672+
3673+
match remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut ds_msgs) {
3674+
MessageSendEvent::SendRevokeAndACK { msg, .. } => {
3675+
nodes[1].node.handle_revoke_and_ack(&nodes[3].node.get_our_node_id(), &msg);
3676+
check_added_monitors(&nodes[1], 1);
3677+
}
3678+
_ => panic!(),
3679+
}
3680+
3681+
match remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut ds_msgs) {
3682+
MessageSendEvent::UpdateHTLCs { updates, .. } => {
3683+
nodes[2].node.handle_update_fulfill_htlc(&nodes[3].node.get_our_node_id(), &updates.update_fulfill_htlcs[0]);
3684+
check_added_monitors(&nodes[2], 1);
3685+
expect_payment_forwarded!(nodes[2], nodes[0], nodes[3], Some(1000), false, false);
3686+
let _cs_updates_for_a = get_htlc_update_msgs(&nodes[2], &nodes[0].node.get_our_node_id());
3687+
3688+
nodes[2].node.handle_commitment_signed(&nodes[3].node.get_our_node_id(), &updates.commitment_signed);
3689+
check_added_monitors(&nodes[2], 1);
3690+
},
3691+
_ => panic!(),
3692+
}
3693+
3694+
let (cs_raa, cs_cs) = get_revoke_commit_msgs(&nodes[2], &nodes[3].node.get_our_node_id());
3695+
3696+
nodes[3].node.handle_revoke_and_ack(&nodes[2].node.get_our_node_id(), &cs_raa);
3697+
check_added_monitors(&nodes[3], 1);
3698+
3699+
nodes[3].node.handle_commitment_signed(&nodes[2].node.get_our_node_id(), &cs_cs);
3700+
check_added_monitors(&nodes[3], 1);
3701+
3702+
let ds_raa = get_event_msg!(nodes[3], MessageSendEvent::SendRevokeAndACK, nodes[2].node.get_our_node_id());
3703+
nodes[2].node.handle_revoke_and_ack(&nodes[3].node.get_our_node_id(), &ds_raa);
3704+
check_added_monitors(&nodes[2], 1);
3705+
3706+
// Our current `ChannelMonitor`s store preimages one RAA longer than they need to. That's nice
3707+
// for safety, but means we have to send one more payment here to wipe the preimage.
3708+
assert!(get_monitor!(nodes[3], chan_3_id).get_stored_preimages().contains_key(&payment_hash));
3709+
assert!(get_monitor!(nodes[3], chan_4_id).get_stored_preimages().contains_key(&payment_hash));
3710+
3711+
send_payment(&nodes[1], &[&nodes[3]], 100_000);
3712+
assert!(!get_monitor!(nodes[3], chan_3_id).get_stored_preimages().contains_key(&payment_hash));
3713+
3714+
send_payment(&nodes[2], &[&nodes[3]], 100_000);
3715+
assert!(!get_monitor!(nodes[3], chan_4_id).get_stored_preimages().contains_key(&payment_hash));
3716+
}

0 commit comments

Comments
 (0)