Skip to content

Commit ebb8d2d

Browse files
committed
Clean up static_spendable_outputs_justice_tx_revoked_htlc_success_tx
Add a few comments to make it clear whats going on a bit more and don't test/confirm a double-spend transaction.
1 parent 07a0ad7 commit ebb8d2d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5081,6 +5081,9 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() {
50815081
assert_eq!(revoked_local_txn[0].input.len(), 1);
50825082
assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid());
50835083

5084+
// The to-be-revoked commitment tx should have one HTLC and one to_remote output
5085+
assert_eq!(revoked_local_txn[0].output.len(), 2);
5086+
50845087
claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage, 3_000_000);
50855088

50865089
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
@@ -5095,28 +5098,45 @@ fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() {
50955098
assert_eq!(revoked_htlc_txn[0].input[0].witness.last().unwrap().len(), ACCEPTED_HTLC_SCRIPT_WEIGHT);
50965099
check_spends!(revoked_htlc_txn[0], revoked_local_txn[0]);
50975100

5101+
// Check that the unspent (of two) outputs on revoked_local_txn[0] is a P2WPKH:
5102+
let unspent_local_txn_output = revoked_htlc_txn[0].input[0].previous_output.vout as usize ^ 1;
5103+
assert_eq!(revoked_local_txn[0].output[unspent_local_txn_output].script_pubkey.len(), 2 + 20); // P2WPKH
5104+
50985105
// A will generate justice tx from B's revoked commitment/HTLC tx
50995106
nodes[0].block_notifier.block_connected(&Block { header, txdata: vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()] }, 1);
51005107
check_closed_broadcast!(nodes[0], false);
51015108
check_added_monitors!(nodes[0], 1);
51025109

51035110
let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
51045111
assert_eq!(node_txn.len(), 3); // ChannelMonitor: justice tx on revoked commitment, justice tx on revoked HTLC-success, ChannelManager: local commitment tx
5112+
5113+
// The first transaction generated is just in case of a reorg - it double-spends
5114+
// revoked_htlc_txn[0], spending the HTLC output on revoked_local_txn[0] directly.
5115+
assert_eq!(node_txn[0].input.len(), 1);
5116+
check_spends!(node_txn[0], revoked_local_txn[0]);
5117+
assert_eq!(node_txn[0].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output);
5118+
51055119
assert_eq!(node_txn[2].input.len(), 1);
51065120
check_spends!(node_txn[2], revoked_htlc_txn[0]);
51075121

5122+
check_spends!(node_txn[1], chan_1.3);
5123+
51085124
let header_1 = BlockHeader { version: 0x20000000, prev_blockhash: header.block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
5109-
nodes[0].block_notifier.block_connected(&Block { header: header_1, txdata: vec![node_txn[0].clone(), node_txn[2].clone()] }, 1);
5125+
nodes[0].block_notifier.block_connected(&Block { header: header_1, txdata: vec![node_txn[2].clone()] }, 1);
51105126
connect_blocks(&nodes[0].block_notifier, ANTI_REORG_DELAY - 1, 1, true, header.block_hash());
51115127

5128+
// Note that nodes[0]'s tx_broadcaster is still locked, so if we get here the channelmonitor
5129+
// didn't try to generate any new transactions.
5130+
51125131
// Check A's ChannelMonitor was able to generate the right spendable output descriptor
51135132
let spend_txn = check_spendable_outputs!(nodes[0], 1, node_cfgs[0].keys_manager, 100000);
5114-
assert_eq!(spend_txn.len(), 5); // Duplicated SpendableOutput due to block rescan after revoked htlc output tracking
5133+
assert_eq!(spend_txn.len(), 4); // Duplicated SpendableOutput due to block rescan after revoked htlc output tracking
51155134
assert_eq!(spend_txn[0], spend_txn[1]);
51165135
assert_eq!(spend_txn[0], spend_txn[2]);
5136+
assert_eq!(spend_txn[0].input.len(), 1);
51175137
check_spends!(spend_txn[0], revoked_local_txn[0]); // spending to_remote output from revoked local tx
5118-
check_spends!(spend_txn[3], node_txn[0]); // spending justice tx output from revoked local tx htlc received output
5119-
check_spends!(spend_txn[4], node_txn[2]); // spending justice tx output on htlc success tx
5138+
assert_ne!(spend_txn[0].input[0].previous_output, revoked_htlc_txn[0].input[0].previous_output);
5139+
check_spends!(spend_txn[3], node_txn[2]); // spending justice tx output on the htlc success tx
51205140
}
51215141

51225142
#[test]

0 commit comments

Comments
 (0)