Skip to content

Commit 6cd3256

Browse files
committed
f even moar test
1 parent 0d39ef6 commit 6cd3256

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

lightning/src/ln/payment_tests.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! serialization ordering between ChannelManager/ChannelMonitors and ensuring we can still retry
1212
//! payments thereafter.
1313
14-
use chain::Watch;
14+
use chain::{Confirm, Watch};
1515
use chain::channelmonitor::ChannelMonitor;
1616
use ln::{PaymentPreimage, PaymentHash};
1717
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, PaymentId, PaymentSendFailure};
@@ -273,8 +273,7 @@ fn no_pending_leak_on_initial_send_failure() {
273273
assert!(!nodes[0].node.has_pending_payments());
274274
}
275275

276-
#[test]
277-
fn retry_with_no_persist() {
276+
fn do_retry_with_no_persist(confirm_before_reload: bool) {
278277
// If we send a pending payment and `send_payment` returns success, we should always either
279278
// return a payment failure event or a payment success event, and on failure the payment should
280279
// be retryable.
@@ -321,6 +320,12 @@ fn retry_with_no_persist() {
321320

322321
reconnect_nodes(&nodes[1], &nodes[2], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
323322

323+
let as_commitment_tx = get_local_commitment_txn!(nodes[0], chan_id)[0].clone();
324+
if confirm_before_reload {
325+
mine_transaction(&nodes[0], &as_commitment_tx);
326+
nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().clear();
327+
}
328+
324329
// The ChannelMonitor should always be the latest version, as we're required to persist it
325330
// during the `commitment_signed_dance!()`.
326331
let mut chan_0_monitor_serialized = test_utils::TestVecWriter(Vec::new());
@@ -361,8 +366,9 @@ fn retry_with_no_persist() {
361366
check_closed_event!(nodes[0], 1, ClosureReason::OutdatedChannelManager);
362367
assert!(nodes[0].node.list_channels().is_empty());
363368
assert!(nodes[0].node.has_pending_payments());
364-
let as_commitment_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
365-
assert_eq!(as_commitment_tx.len(), 1);
369+
let as_broadcasted_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
370+
assert_eq!(as_broadcasted_txn.len(), 1);
371+
assert_eq!(as_broadcasted_txn[0], as_commitment_tx);
366372

367373
nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
368374
nodes[0].node.peer_connected(&nodes[1].node.get_our_node_id(), &msgs::Init { features: InitFeatures::known()});
@@ -396,26 +402,31 @@ fn retry_with_no_persist() {
396402
check_added_monitors!(nodes[1], 1);
397403
commitment_signed_dance!(nodes[1], nodes[2], htlc_fulfill_updates.commitment_signed, false);
398404

405+
if confirm_before_reload {
406+
let best_block = nodes[0].blocks.lock().unwrap().last().unwrap().clone();
407+
nodes[0].node.best_block_updated(&best_block.0, best_block.1);
408+
}
409+
399410
// Create a new channel on which to retry the payment before we fail the payment via the
400411
// HTLC-Timeout transaction. This avoids ChannelManager timing out the payment due to us
401412
// connecting several blocks while creating the channel (implying time has passed).
402413
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
403414
assert_eq!(nodes[0].node.list_usable_channels().len(), 1);
404415

405-
mine_transaction(&nodes[1], &as_commitment_tx[0]);
416+
mine_transaction(&nodes[1], &as_commitment_tx);
406417
let bs_htlc_claim_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
407418
assert_eq!(bs_htlc_claim_txn.len(), 1);
408-
check_spends!(bs_htlc_claim_txn[0], as_commitment_tx[0]);
419+
check_spends!(bs_htlc_claim_txn[0], as_commitment_tx);
409420
expect_payment_forwarded!(nodes[1], None, false);
410421

411-
mine_transaction(&nodes[0], &as_commitment_tx[0]);
422+
mine_transaction(&nodes[0], &as_commitment_tx);
412423
mine_transaction(&nodes[0], &bs_htlc_claim_txn[0]);
413424
expect_payment_sent!(nodes[0], payment_preimage_1);
414425
connect_blocks(&nodes[0], TEST_FINAL_CLTV*4 + 20);
415426
let as_htlc_timeout_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
416427
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]);
428+
check_spends!(as_htlc_timeout_txn[0], as_commitment_tx);
429+
check_spends!(as_htlc_timeout_txn[1], as_commitment_tx);
419430
assert_eq!(as_htlc_timeout_txn.len(), 3);
420431
if as_htlc_timeout_txn[0].input[0].previous_output == bs_htlc_claim_txn[0].input[0].previous_output {
421432
confirm_transaction(&nodes[0], &as_htlc_timeout_txn[1]);
@@ -437,3 +448,9 @@ fn retry_with_no_persist() {
437448
pass_along_path(&nodes[0], &[&nodes[1], &nodes[2]], 1_000_000, payment_hash, Some(payment_secret), events.pop().unwrap(), true, None);
438449
claim_payment_along_route(&nodes[0], &[&[&nodes[1], &nodes[2]]], false, payment_preimage);
439450
}
451+
452+
#[test]
453+
fn retry_with_no_persist() {
454+
do_retry_with_no_persist(true);
455+
do_retry_with_no_persist(false);
456+
}

0 commit comments

Comments
 (0)