Skip to content

Commit 0d39ef6

Browse files
committed
f test multiple payments reloaded since it was broken
1 parent 90872a4 commit 0d39ef6

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

lightning/src/ln/payment_tests.rs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ fn retry_with_no_persist() {
278278
// If we send a pending payment and `send_payment` returns success, we should always either
279279
// return a payment failure event or a payment success event, and on failure the payment should
280280
// be retryable.
281+
//
281282
// In order to do so when the ChannelManager isn't immediately persisted (which is normal - its
282283
// always persisted asynchronously), the ChannelManager has to reload some payment data from
283284
// ChannelMonitor(s) in some cases. This tests that reloading.
@@ -289,13 +290,16 @@ fn retry_with_no_persist() {
289290
let nodes_0_deserialized: ChannelManager<EnforcingSigner, &test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>;
290291
let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs);
291292

292-
let chan_id = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known()).2;
293+
let (_, _, chan_id, funding_tx) = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
293294
create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::known(), InitFeatures::known());
294295

295-
// Serialize the ChannelManager prior to sending the payment
296+
// Serialize the ChannelManager prior to sending payments
296297
let nodes_0_serialized = nodes[0].node.encode();
297298

298-
let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 100_000);
299+
// Send two payments - one which will get to nodes[2] and will be claimed, one which we'll time
300+
// out and retry.
301+
let payment_preimage_1 = route_payment(&nodes[0], &[&nodes[1], &nodes[2]], 1_000_000).0;
302+
let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 1_000_000);
299303
let payment_id = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)).unwrap();
300304
check_added_monitors!(nodes[0], 1);
301305

@@ -315,7 +319,7 @@ fn retry_with_no_persist() {
315319
// nodes[1] now immediately fails the HTLC as the next-hop channel is disconnected
316320
let _ = get_htlc_update_msgs!(nodes[1], nodes[0].node.get_our_node_id());
317321

318-
reconnect_nodes(&nodes[1], &nodes[2], (true, true), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
322+
reconnect_nodes(&nodes[1], &nodes[2], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
319323

320324
// The ChannelMonitor should always be the latest version, as we're required to persist it
321325
// during the `commitment_signed_dance!()`.
@@ -383,29 +387,53 @@ fn retry_with_no_persist() {
383387
}
384388
check_closed_broadcast!(nodes[1], false);
385389

390+
// Now claim the first payment, which should allow nodes[1] to claim the payment on-chain when
391+
// we close in a moment.
392+
nodes[2].node.claim_funds(payment_preimage_1);
393+
check_added_monitors!(nodes[2], 1);
394+
let htlc_fulfill_updates = get_htlc_update_msgs!(nodes[2], nodes[1].node.get_our_node_id());
395+
nodes[1].node.handle_update_fulfill_htlc(&nodes[2].node.get_our_node_id(), &htlc_fulfill_updates.update_fulfill_htlcs[0]);
396+
check_added_monitors!(nodes[1], 1);
397+
commitment_signed_dance!(nodes[1], nodes[2], htlc_fulfill_updates.commitment_signed, false);
398+
386399
// Create a new channel on which to retry the payment before we fail the payment via the
387400
// HTLC-Timeout transaction. This avoids ChannelManager timing out the payment due to us
388401
// connecting several blocks while creating the channel (implying time has passed).
389402
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
390403
assert_eq!(nodes[0].node.list_usable_channels().len(), 1);
391404

405+
mine_transaction(&nodes[1], &as_commitment_tx[0]);
406+
let bs_htlc_claim_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
407+
assert_eq!(bs_htlc_claim_txn.len(), 1);
408+
check_spends!(bs_htlc_claim_txn[0], as_commitment_tx[0]);
409+
expect_payment_forwarded!(nodes[1], None, false);
410+
392411
mine_transaction(&nodes[0], &as_commitment_tx[0]);
412+
mine_transaction(&nodes[0], &bs_htlc_claim_txn[0]);
413+
expect_payment_sent!(nodes[0], payment_preimage_1);
393414
connect_blocks(&nodes[0], TEST_FINAL_CLTV*4 + 20);
394-
let as_htlc_timeout_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
395-
assert_eq!(as_htlc_timeout_tx.len(), 1);
396-
confirm_transaction(&nodes[0], &as_htlc_timeout_tx[0]);
415+
let as_htlc_timeout_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
416+
check_spends!(as_htlc_timeout_txn[2], funding_tx);
417+
check_spends!(as_htlc_timeout_txn[0], as_commitment_tx[0]);
418+
check_spends!(as_htlc_timeout_txn[1], as_commitment_tx[0]);
419+
assert_eq!(as_htlc_timeout_txn.len(), 3);
420+
if as_htlc_timeout_txn[0].input[0].previous_output == bs_htlc_claim_txn[0].input[0].previous_output {
421+
confirm_transaction(&nodes[0], &as_htlc_timeout_txn[1]);
422+
} else {
423+
confirm_transaction(&nodes[0], &as_htlc_timeout_txn[0]);
424+
}
397425
nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clear();
398426
expect_payment_failed!(nodes[0], payment_hash, false);
399427

400428
// Finally, retry the payment (which was reloaded from the ChannelMonitor when nodes[0] was
401429
// reloaded) via a route over the new channel, which work without issue and eventually be
402430
// received and claimed at the recipient just like any other payment.
403-
let (new_route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[2], 100_000);
431+
let (new_route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[2], 1_000_000);
404432

405433
nodes[0].node.retry_payment(&new_route, payment_id).unwrap();
406434
check_added_monitors!(nodes[0], 1);
407435
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
408436
assert_eq!(events.len(), 1);
409-
pass_along_path(&nodes[0], &[&nodes[1], &nodes[2]], 100_000, payment_hash, Some(payment_secret), events.pop().unwrap(), true, None);
437+
pass_along_path(&nodes[0], &[&nodes[1], &nodes[2]], 1_000_000, payment_hash, Some(payment_secret), events.pop().unwrap(), true, None);
410438
claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage);
411439
}

0 commit comments

Comments
 (0)