ln/test: test_channel_common zero fee commitment anchor handling
What changed, and why it matters
This commit only changes a test file inside the Lightning Dev Kit codebase. It updates how a test macro calculates signature types and output indexes for different channel feature combinations. There is no change to production code, no bug fix, and no security-relevant behavior change.
No action required. This is a test-only change and does not affect production security posture.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies a macro inside lightning/src/ln/channel.rs test module. It introduces a tuple (htlc_sighashtype, num_anchors) based on three channel type feature branches: supports_anchor_zero_fee_commitments (1 anchor, SIGHASH_SINGLE|ANYONECANPAY), supports_anchors_zero_fee_htlc_tx (2 anchors, same sighash), and otherwise (SIGHASH_ALL, 0 anchors). Previously the code only distinguished anchors vs non-anchors and used a single anchor count of 2. This is a test-only refinement to cover the zero-fee commitment anchor variant correctly.
Changed components
lightning/src/ln/channel.rs test module macroInspect captured patch +8 / −2
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index e4cee16..8548cda 100644
--- a/lightning/src/ln/channel.rs
+++ b/lightning/src/ln/channel.rs
@@ -16532,6 +16532,14 @@ mod tests {
let mut htlc_counterparty_sig_iter = holder_commitment_tx.counterparty_htlc_sigs.iter();
$({
+ let (htlc_sighashtype, num_anchors) = if $channel_type_features.supports_anchor_zero_fee_commitments() {
+ (EcdsaSighashType::SinglePlusAnyoneCanPay, 1)
+ } else if $channel_type_features.supports_anchors_zero_fee_htlc_tx() {
+ (EcdsaSighashType::SinglePlusAnyoneCanPay, 2)
+ } else {
+ (EcdsaSighashType::All, 0)
+ };
+
log_trace!($logger, "verifying htlc {}", $htlc_idx);
let remote_signature = Signature::from_der(&<Vec<u8>>::from_hex($counterparty_htlc_sig_hex).unwrap()[..]).unwrap();
@@ -16541,7 +16549,6 @@ mod tests {
$chan.funding.get_counterparty_selected_contest_delay().unwrap(),
&htlc, $channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, $channel_type_features, &keys);
- let htlc_sighashtype = if $channel_type_features.supports_anchors_zero_fee_htlc_tx() { EcdsaSighashType::SinglePlusAnyoneCanPay } else { EcdsaSighashType::All };
let htlc_sighash = Message::from_digest(sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.to_bitcoin_amount(), htlc_sighashtype).unwrap().as_raw_hash().to_byte_array());
assert!($secp_ctx.verify_ecdsa(&htlc_sighash, &remote_signature, &keys.countersignatory_htlc_key.to_public_key()).is_ok(), "verify counterparty htlc sig");
@@ -16572,7 +16579,6 @@ mod tests {
preimage: preimage.clone(),
counterparty_sig: *htlc_counterparty_sig,
}, &$secp_ctx).unwrap();
- let num_anchors = if $channel_type_features.supports_anchors_zero_fee_htlc_tx() { 2 } else { 0 };
assert_eq!(htlc.transaction_output_index, Some($htlc_idx + num_anchors), "output index");
let signature = Signature::from_der(&<Vec<u8>>::from_hex($htlc_sig_hex).unwrap()[..]).unwrap();
Why this scored 13/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.