Skip to content

Commit 9c1c432

Browse files
committed
Clean up test_bump_penalty_txn_on_revoked_htlcs
Add a few comments to make it clear whats going on a bit more and assert the basic structure of more transactions. Further, point out where transactions are double-spends and don't confirm double-spends.
1 parent ebb8d2d commit 9c1c432

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7786,12 +7786,14 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
77867786
check_spends!(revoked_htlc_txn[0], revoked_local_txn[0]);
77877787
assert_eq!(revoked_htlc_txn[1].input.len(), 1);
77887788
assert_eq!(revoked_htlc_txn[1].input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
7789+
assert_eq!(revoked_htlc_txn[1].output.len(), 1);
77897790
check_spends!(revoked_htlc_txn[1], revoked_local_txn[0]);
77907791
} else if revoked_htlc_txn[1].input[0].witness.last().unwrap().len() == ACCEPTED_HTLC_SCRIPT_WEIGHT {
77917792
assert_eq!(revoked_htlc_txn[1].input.len(), 1);
77927793
check_spends!(revoked_htlc_txn[1], revoked_local_txn[0]);
77937794
assert_eq!(revoked_htlc_txn[0].input.len(), 1);
77947795
assert_eq!(revoked_htlc_txn[0].input[0].witness.last().unwrap().len(), OFFERED_HTLC_SCRIPT_WEIGHT);
7796+
assert_eq!(revoked_htlc_txn[0].output.len(), 1);
77957797
check_spends!(revoked_htlc_txn[0], revoked_local_txn[0]);
77967798
}
77977799

@@ -7808,18 +7810,47 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
78087810
let mut node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
78097811
assert_eq!(node_txn.len(), 5); // 3 penalty txn on revoked commitment tx + A commitment tx + 1 penalty tnx on revoked HTLC txn
78107812
// Verify claim tx are spending revoked HTLC txn
7813+
7814+
// node_txn 0-2 each spend a separate revoked output from revoked_local_txn[0]
7815+
// Note that node_txn[0] and node_txn[1] are bogus - they double spend the revoked_htlc_txn
7816+
// which are included in the same block (they are broadcasted because we scan the
7817+
// transactions linearly and generate claims as we go, they likely should be removed in the
7818+
// future).
7819+
assert_eq!(node_txn[0].input.len(), 1);
7820+
check_spends!(node_txn[0], revoked_local_txn[0]);
7821+
assert_eq!(node_txn[1].input.len(), 1);
7822+
check_spends!(node_txn[1], revoked_local_txn[0]);
7823+
assert_eq!(node_txn[2].input.len(), 1);
7824+
check_spends!(node_txn[2], revoked_local_txn[0]);
7825+
7826+
// Each of the three justice transactions claim a separate (single) output of the three
7827+
// available, which we check here:
7828+
assert_ne!(node_txn[0].input[0].previous_output, node_txn[1].input[0].previous_output);
7829+
assert_ne!(node_txn[0].input[0].previous_output, node_txn[2].input[0].previous_output);
7830+
assert_ne!(node_txn[1].input[0].previous_output, node_txn[2].input[0].previous_output);
7831+
7832+
assert_eq!(node_txn[0].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output);
7833+
assert_eq!(node_txn[1].input[0].previous_output, revoked_htlc_txn[1].input[0].previous_output);
7834+
7835+
// node_txn[3] is the local commitment tx broadcast just because (and somewhat in case of
7836+
// reorgs, though its not clear its ever worth broadcasting conflicting txn like this when
7837+
// a remote commitment tx has already been confirmed).
7838+
check_spends!(node_txn[3], chan.3);
7839+
7840+
// node_txn[4] spends the revoked outputs from the revoked_htlc_txn (which only have one
7841+
// output, checked above).
78117842
assert_eq!(node_txn[4].input.len(), 2);
78127843
assert_eq!(node_txn[4].output.len(), 1);
78137844
check_spends!(node_txn[4], revoked_htlc_txn[0], revoked_htlc_txn[1]);
78147845
first = node_txn[4].txid();
78157846
// Store both feerates for later comparison
78167847
let fee_1 = revoked_htlc_txn[0].output[0].value + revoked_htlc_txn[1].output[0].value - node_txn[4].output[0].value;
78177848
feerate_1 = fee_1 * 1000 / node_txn[4].get_weight() as u64;
7818-
penalty_txn = vec![node_txn[0].clone(), node_txn[1].clone(), node_txn[2].clone()];
7849+
penalty_txn = vec![node_txn[2].clone()];
78197850
node_txn.clear();
78207851
}
78217852

7822-
// Connect three more block to see if bumped penalty are issued for HTLC txn
7853+
// Connect one more block to see if bumped penalty are issued for HTLC txn
78237854
let header_130 = BlockHeader { version: 0x20000000, prev_blockhash: header_129.block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
78247855
nodes[0].block_notifier.block_connected(&Block { header: header_130, txdata: penalty_txn }, 130);
78257856
{
@@ -7828,6 +7859,13 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
78287859

78297860
check_spends!(node_txn[0], revoked_local_txn[0]);
78307861
check_spends!(node_txn[1], revoked_local_txn[0]);
7862+
// Note that these are both bogus - they spend outputs already claimed in block 129:
7863+
if node_txn[0].input[0].previous_output == revoked_htlc_txn[0].input[0].previous_output {
7864+
assert_eq!(node_txn[1].input[0].previous_output, revoked_htlc_txn[1].input[0].previous_output);
7865+
} else {
7866+
assert_eq!(node_txn[0].input[0].previous_output, revoked_htlc_txn[1].input[0].previous_output);
7867+
assert_eq!(node_txn[1].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output);
7868+
}
78317869

78327870
node_txn.clear();
78337871
};

0 commit comments

Comments
 (0)