@@ -7677,22 +7677,29 @@ fn test_bump_penalty_txn_on_remote_commitment() {
7677
7677
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
7678
7678
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
7679
7679
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
+ };
7696
7703
7697
7704
// One or more claim tx should have been broadcast, check it
7698
7705
let timeout;
@@ -7702,9 +7709,11 @@ fn test_bump_penalty_txn_on_remote_commitment() {
7702
7709
let feerate_preimage;
7703
7710
{
7704
7711
let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
7705
- // 3 transactions including:
7712
+ // 3-6 transactions including:
7706
7713
// 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);
7708
7717
assert_eq!(node_txn[0].input.len(), 1);
7709
7718
assert_eq!(node_txn[1].input.len(), 1);
7710
7719
assert_eq!(node_txn[2].input.len(), 1);
@@ -7717,11 +7726,9 @@ fn test_bump_penalty_txn_on_remote_commitment() {
7717
7726
let fee = remote_txn[0].output[index as usize].value.to_sat() - node_txn[0].output[0].value.to_sat();
7718
7727
feerate_preimage = fee * 1000 / node_txn[0].weight().to_wu();
7719
7728
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();
7725
7732
7726
7733
preimage_bump = preimage_bump_tx;
7727
7734
check_spends!(preimage_bump, remote_txn[0]);
@@ -7741,7 +7748,8 @@ fn test_bump_penalty_txn_on_remote_commitment() {
7741
7748
connect_blocks(&nodes[1], crate::chain::package::LOW_FREQUENCY_BUMP_INTERVAL);
7742
7749
{
7743
7750
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);
7745
7753
assert_eq!(node_txn[0].input.len(), 1);
7746
7754
assert_eq!(preimage_bump.input.len(), 1);
7747
7755
check_spends!(node_txn[0], remote_txn[0]);
0 commit comments