@@ -7758,22 +7758,29 @@ fn test_bump_penalty_txn_on_remote_commitment() {
7758
7758
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
7759
7759
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
7760
7760
7761
- let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
7762
- let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], 3_000_000);
7763
- route_payment(&nodes[1], &vec!(&nodes[0])[..], 3000000).0;
7764
-
7765
- // Remote commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
7766
- let remote_txn = get_local_commitment_txn!(nodes[0], chan.2);
7767
- assert_eq!(remote_txn[0].output.len(), 4);
7768
- assert_eq!(remote_txn[0].input.len(), 1);
7769
- assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.compute_txid());
7770
-
7771
- // Claim a HTLC without revocation (provide B monitor with preimage)
7772
- nodes[1].node.claim_funds(payment_preimage);
7773
- expect_payment_claimed!(nodes[1], payment_hash, 3_000_000);
7774
- mine_transaction(&nodes[1], &remote_txn[0]);
7775
- check_added_monitors!(nodes[1], 2);
7776
- connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
7761
+ let remote_txn = {
7762
+ let htlc_value_a_msats = 847_000;
7763
+ let htlc_value_b_msats = 546_000;
7764
+
7765
+ let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
7766
+ let (payment_preimage, payment_hash, ..) = route_payment(&nodes[0], &[&nodes[1]], htlc_value_a_msats);
7767
+ route_payment(&nodes[1], &vec!(&nodes[0])[..], htlc_value_b_msats).0;
7768
+
7769
+ // Remote commitment txn with 4 outputs : to_local, to_remote, 1 outgoing HTLC, 1 incoming HTLC
7770
+ let remote_txn = get_local_commitment_txn!(nodes[0], chan.2);
7771
+ assert_eq!(remote_txn[0].output.len(), 4);
7772
+ assert_eq!(remote_txn[0].input.len(), 1);
7773
+ assert_eq!(remote_txn[0].input[0].previous_output.txid, chan.3.compute_txid());
7774
+
7775
+ // Claim a HTLC without revocation (provide B monitor with preimage)
7776
+ nodes[1].node.claim_funds(payment_preimage);
7777
+ expect_payment_claimed!(nodes[1], payment_hash, htlc_value_a_msats);
7778
+ mine_transaction(&nodes[1], &remote_txn[0]);
7779
+ check_added_monitors!(nodes[1], 2);
7780
+ connect_blocks(&nodes[1], TEST_FINAL_CLTV); // Confirm blocks until the HTLC expires
7781
+
7782
+ remote_txn
7783
+ };
7777
7784
7778
7785
// One or more claim tx should have been broadcast, check it
7779
7786
let timeout;
@@ -7783,9 +7790,11 @@ fn test_bump_penalty_txn_on_remote_commitment() {
7783
7790
let feerate_preimage;
7784
7791
{
7785
7792
let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
7786
- // 3 transactions including:
7793
+ // 3-6 transactions including:
7787
7794
// preimage and timeout sweeps from remote commitment + preimage sweep bump
7788
- assert_eq!(node_txn.len(), 3);
7795
+ // plus, depending on the block connection style, two further bumps
7796
+ assert!(node_txn.len() >= 3);
7797
+ assert!(node_txn.len() <= 6);
7789
7798
assert_eq!(node_txn[0].input.len(), 1);
7790
7799
assert_eq!(node_txn[1].input.len(), 1);
7791
7800
assert_eq!(node_txn[2].input.len(), 1);
@@ -7798,11 +7807,9 @@ fn test_bump_penalty_txn_on_remote_commitment() {
7798
7807
let fee = remote_txn[0].output[index as usize].value.to_sat() - node_txn[0].output[0].value.to_sat();
7799
7808
feerate_preimage = fee * 1000 / node_txn[0].weight().to_wu();
7800
7809
7801
- let (preimage_bump_tx, timeout_tx) = if node_txn[2].input[0].previous_output == node_txn[0].input[0].previous_output {
7802
- (node_txn[2].clone(), node_txn[1].clone())
7803
- } else {
7804
- (node_txn[1].clone(), node_txn[2].clone())
7805
- };
7810
+ let preimage_tx = &node_txn[0];
7811
+ let timeout_tx = node_txn.iter().skip(1).find(|t| t.input[0].previous_output != preimage_tx.input[0].previous_output).unwrap().clone();
7812
+ let preimage_bump_tx = node_txn.iter().skip(1).find(|t| t.input[0].previous_output == preimage_tx.input[0].previous_output).unwrap().clone();
7806
7813
7807
7814
preimage_bump = preimage_bump_tx;
7808
7815
check_spends!(preimage_bump, remote_txn[0]);
@@ -7822,7 +7829,8 @@ fn test_bump_penalty_txn_on_remote_commitment() {
7822
7829
connect_blocks(&nodes[1], crate::chain::package::LOW_FREQUENCY_BUMP_INTERVAL);
7823
7830
{
7824
7831
let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
7825
- assert_eq!(node_txn.len(), 1);
7832
+ assert!(node_txn.len() >= 1);
7833
+ assert!(node_txn.len() <= 2);
7826
7834
assert_eq!(node_txn[0].input.len(), 1);
7827
7835
assert_eq!(preimage_bump.input.len(), 1);
7828
7836
check_spends!(node_txn[0], remote_txn[0]);
0 commit comments