@@ -7677,22 +7677,29 @@ fn test_bump_penalty_txn_on_remote_commitment() {
76777677 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
76787678 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
76797679
7680- let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
7681- let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 3_000_000);
7682- route_payment(&nodes[1], &vec!(&nodes[0])[..], 3000000).0;
7683-
7684- // Remote commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
7685- let remote_txn = get_local_commitment_txn!(nodes[0], chan.2);
7686- assert_eq!(remote_txn[0].output.len(), 4);
7687- assert_eq!(remote_txn[0].input.len(), 1);
7688- assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.compute_txid());
7689-
7690- // Claim a HTLC without revocation (provide B monitor with preimage)
7691- nodes[1].node.claim_funds(payment_preimage);
7692- expect_payment_claimed!(nodes[1], payment_hash, 3_000_000);
7693- mine_transaction(&nodes[1], &remote_txn[0]);
7694- check_added_monitors!(nodes[1], 2);
7695- connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
7680+ let remote_txn = {
7681+ let htlc_value_a_msats = 847_000;
7682+ let htlc_value_b_msats = 546_000;
7683+
7684+ let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
7685+ let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], htlc_value_a_msats);
7686+ route_payment(&nodes[1], &vec!(&nodes[0])[..], htlc_value_b_msats).0;
7687+
7688+ // Remote commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
7689+ let remote_txn = get_local_commitment_txn!(nodes[0], chan.2);
7690+ assert_eq!(remote_txn[0].output.len(), 4);
7691+ assert_eq!(remote_txn[0].input.len(), 1);
7692+ assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.compute_txid());
7693+
7694+ // Claim a HTLC without revocation (provide B monitor with preimage)
7695+ nodes[1].node.claim_funds(payment_preimage);
7696+ expect_payment_claimed!(nodes[1], payment_hash, htlc_value_a_msats);
7697+ mine_transaction(&nodes[1], &remote_txn[0]);
7698+ check_added_monitors!(nodes[1], 2);
7699+ connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
7700+
7701+ remote_txn
7702+ };
76967703
76977704 // One or more claim tx should have been broadcast, check it
76987705 let timeout;
@@ -7702,9 +7709,11 @@ fn test_bump_penalty_txn_on_remote_commitment() {
77027709 let feerate_preimage;
77037710 {
77047711 let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
7705- // 3 transactions including:
7712+ // 3-6 transactions including:
77067713 // preimage and timeout sweeps from remote commitment + preimage sweep bump
7707- assert_eq!(node_txn.len(), 3);
7714+ // plus, depending on the block connection style, two further bumps
7715+ assert!(node_txn.len() >= 3);
7716+ assert!(node_txn.len() <= 6);
77087717 assert_eq!(node_txn[0].input.len(), 1);
77097718 assert_eq!(node_txn[1].input.len(), 1);
77107719 assert_eq!(node_txn[2].input.len(), 1);
@@ -7717,11 +7726,9 @@ fn test_bump_penalty_txn_on_remote_commitment() {
77177726 let fee = remote_txn[0].output[index as usize].value.to_sat() - node_txn[0].output[0].value.to_sat();
77187727 feerate_preimage = fee * 1000 / node_txn[0].weight().to_wu();
77197728
7720- let (preimage_bump_tx, timeout_tx) = if node_txn[2].input[0].previous_output == node_txn[0].input[0].previous_output {
7721- (node_txn[2].clone(), node_txn[1].clone())
7722- } else {
7723- (node_txn[1].clone(), node_txn[2].clone())
7724- };
7729+ let preimage_tx = &node_txn[0];
7730+ let timeout_tx = node_txn.iter().skip(1).find(|t| t.input[0].previous_output != preimage_tx.input[0].previous_output).unwrap().clone();
7731+ let preimage_bump_tx = node_txn.iter().skip(1).find(|t| t.input[0].previous_output == preimage_tx.input[0].previous_output).unwrap().clone();
77257732
77267733 preimage_bump = preimage_bump_tx;
77277734 check_spends!(preimage_bump, remote_txn[0]);
@@ -7741,7 +7748,8 @@ fn test_bump_penalty_txn_on_remote_commitment() {
77417748 connect_blocks(&nodes[1], crate::chain::package::LOW_FREQUENCY_BUMP_INTERVAL);
77427749 {
77437750 let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
7744- assert_eq!(node_txn.len(), 1);
7751+ assert!(node_txn.len() >= 1);
7752+ assert!(node_txn.len() <= 2);
77457753 assert_eq!(node_txn[0].input.len(), 1);
77467754 assert_eq!(preimage_bump.input.len(), 1);
77477755 check_spends!(node_txn[0], remote_txn[0]);
0 commit comments