Skip to content

Commit e234dc4

Browse files
committed
f Additional verification of timeout_htlc_txn
1 parent d05e94c commit e234dc4

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

lightning/src/ln/monitor_tests.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,10 +909,33 @@ fn do_test_balances_on_local_commitment_htlcs(anchors: bool) {
909909
// Aggregated HTLC timeouts.
910910
assert_eq!(timeout_htlc_txn.len(), 1);
911911
check_spends!(timeout_htlc_txn[0], commitment_tx, coinbase_tx);
912+
// One input from the commitment transaction for each HTLC, and one input to provide fees.
913+
assert_eq!(timeout_htlc_txn[0].input.len(), 3);
914+
// HTLC timeout witnesses for anchor channels contain at most 288 bytes.
915+
// DER-encoded ECDSA signatures vary in size.
916+
// https://github.com/lightning/bolts/blob/master/03-transactions.md#expected-weight-of-htlc-timeout-and-htlc-success-transactions
917+
assert!(
918+
timeout_htlc_txn[0].input[0].witness.size() >= 284 &&
919+
timeout_htlc_txn[0].input[0].witness.size() <= 288
920+
);
921+
assert!(
922+
timeout_htlc_txn[0].input[1].witness.size() >= 284 &&
923+
timeout_htlc_txn[0].input[1].witness.size() <= 288
924+
);
912925
} else {
913926
assert_eq!(timeout_htlc_txn.len(), 2);
914-
check_spends!(timeout_htlc_txn[0], commitment_tx, coinbase_tx);
915-
check_spends!(timeout_htlc_txn[1], commitment_tx, coinbase_tx);
927+
check_spends!(timeout_htlc_txn[0], commitment_tx);
928+
check_spends!(timeout_htlc_txn[1], commitment_tx);
929+
// HTLC timeout witnesses for non-anchor channels contain at most 285 bytes.
930+
// DER-encoded ECDSA signatures vary in size.
931+
assert!(
932+
timeout_htlc_txn[0].input[0].witness.size() >= 281 &&
933+
timeout_htlc_txn[0].input[0].witness.size() <= 285
934+
);
935+
assert!(
936+
timeout_htlc_txn[1].input[0].witness.size() >= 281 &&
937+
timeout_htlc_txn[1].input[0].witness.size() <= 285
938+
);
916939
}
917940

918941
// Now confirm nodes[1]'s HTLC claim, giving nodes[0] the preimage. Note that the "maybe
@@ -931,6 +954,16 @@ fn do_test_balances_on_local_commitment_htlcs(anchors: bool) {
931954
// aggregated package.
932955
handle_bump_htlc_event(&nodes[0], 1);
933956
timeout_htlc_txn = nodes[0].tx_broadcaster.unique_txn_broadcast();
957+
assert_eq!(timeout_htlc_txn.len(), 1);
958+
check_spends!(timeout_htlc_txn[0], commitment_tx, coinbase_tx);
959+
// One input from the commitment transaction for the HTLC, and one input to provide fees.
960+
assert_eq!(timeout_htlc_txn[0].input.len(), 2);
961+
// HTLC timeout witnesses for anchor channels contain at most 288 bytes.
962+
// DER-encoded ECDSA signatures vary in size.
963+
assert!(
964+
timeout_htlc_txn[0].input[0].witness.size() >= 284 &&
965+
timeout_htlc_txn[0].input[0].witness.size() <= 288
966+
);
934967
}
935968

936969
// Now confirm nodes[0]'s HTLC-Timeout transaction, which changes the claimable balance to an

0 commit comments

Comments
 (0)