Run fmt on `ChannelContext::validate_commitment_signed`
What changed, and why it matters
This commit is purely a code-formatting cleanup. It removes two `#[rustfmt::skip]` attributes and lets Rust's automatic formatter reformat two functions. No logic, behavior, or security checks were changed.
No security action needed; this is a cosmetic/style-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff removes #[rustfmt::skip] from build_htlc_input_witness in chan_utils.rs and from ChannelContext::validate_commitment_signed in channel.rs, then applies rustfmt. The result is whitespace, line-wrapping, and formatting changes only. All function signatures, variable names, control flow, arithmetic, signature verification calls, and error handling remain identical.
Changed components
lightning/src/ln/chan_utils.rslightning/src/ln/channel.rsInspect captured patch +101 / −28
diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs
index 8dc5c7b..cb01318 100644
--- a/lightning/src/ln/chan_utils.rs
+++ b/lightning/src/ln/chan_utils.rs
@@ -865,7 +865,6 @@ pub(crate) fn build_htlc_output(
}
/// Returns the witness required to satisfy and spend a HTLC input.
-#[rustfmt::skip]
pub fn build_htlc_input_witness(
local_sig: &Signature, remote_sig: &Signature, preimage: &Option<PaymentPreimage>,
redeem_script: &Script, channel_type_features: &ChannelTypeFeatures,
@@ -879,7 +878,10 @@ pub fn build_htlc_input_witness(
let mut witness = Witness::new();
// First push the multisig dummy, note that due to BIP147 (NULLDUMMY) it must be a zero-length element.
witness.push(vec![]);
- witness.push_ecdsa_signature(&BitcoinSignature { signature: *remote_sig, sighash_type: remote_sighash_type });
+ witness.push_ecdsa_signature(&BitcoinSignature {
+ signature: *remote_sig,
+ sighash_type: remote_sighash_type,
+ });
witness.push_ecdsa_signature(&BitcoinSignature::sighash_all(*local_sig));
if let Some(preimage) = preimage {
witness.push(preimage.0.to_vec());
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 3ce23d0..6d8c310 100644
--- a/lightning/src/ln/channel.rs
+++ b/lightning/src/ln/channel.rs
@@ -4568,18 +4568,25 @@ where
Ok(())
}
- #[rustfmt::skip]
fn validate_commitment_signed<L: Deref>(
&self, funding: &FundingScope, transaction_number: u64, commitment_point: PublicKey,
msg: &msgs::CommitmentSigned, logger: &L,
- ) -> Result<(HolderCommitmentTransaction, Vec<(HTLCOutputInCommitment, Option<&HTLCSource>)>), ChannelError>
+ ) -> Result<
+ (HolderCommitmentTransaction, Vec<(HTLCOutputInCommitment, Option<&HTLCSource>)>),
+ ChannelError,
+ >
where
L::Target: Logger,
{
let funding_script = funding.get_funding_redeemscript();
let commitment_data = self.build_commitment_transaction(
- funding, transaction_number, &commitment_point, true, false, logger,
+ funding,
+ transaction_number,
+ &commitment_point,
+ true,
+ false,
+ logger,
);
let commitment_txid = {
let trusted_tx = commitment_data.tx.trust();
@@ -4588,10 +4595,19 @@ where
log_trace!(logger, "Checking commitment tx signature {} by key {} against tx {} (sighash {}) with redeemscript {} in channel {}",
log_bytes!(msg.signature.serialize_compact()[..]),
- log_bytes!(funding.counterparty_funding_pubkey().serialize()), encode::serialize_hex(&bitcoin_tx.transaction),
- log_bytes!(sighash[..]), encode::serialize_hex(&funding_script), &self.channel_id());
- if let Err(_) = self.secp_ctx.verify_ecdsa(&sighash, &msg.signature, &funding.counterparty_funding_pubkey()) {
- return Err(ChannelError::close("Invalid commitment tx signature from peer".to_owned()));
+ log_bytes!(funding.counterparty_funding_pubkey().serialize()),
+ encode::serialize_hex(&bitcoin_tx.transaction),
+ log_bytes!(sighash[..]), encode::serialize_hex(&funding_script),
+ &self.channel_id(),
+ );
+ if let Err(_) = self.secp_ctx.verify_ecdsa(
+ &sighash,
+ &msg.signature,
+ &funding.counterparty_funding_pubkey(),
+ ) {
+ return Err(ChannelError::close(
+ "Invalid commitment tx signature from peer".to_owned(),
+ ));
}
bitcoin_tx.txid
};
@@ -4600,40 +4616,90 @@ where
// they can actually afford the new fee now.
let update_fee = if let Some((_, update_state)) = self.pending_update_fee {
update_state == FeeUpdateState::RemoteAnnounced
- } else { false };
+ } else {
+ false
+ };
if update_fee {
debug_assert!(!funding.is_outbound());
- let counterparty_reserve_we_require_msat = funding.holder_selected_channel_reserve_satoshis * 1000;
- if commitment_data.stats.remote_balance_before_fee_msat < commitment_data.stats.commit_tx_fee_sat * 1000 + counterparty_reserve_we_require_msat {
- return Err(ChannelError::close("Funding remote cannot afford proposed new fee".to_owned()));
+ let counterparty_reserve_we_require_msat =
+ funding.holder_selected_channel_reserve_satoshis * 1000;
+ if commitment_data.stats.remote_balance_before_fee_msat
+ < commitment_data.stats.commit_tx_fee_sat * 1000
+ + counterparty_reserve_we_require_msat
+ {
+ return Err(ChannelError::close(
+ "Funding remote cannot afford proposed new fee".to_owned(),
+ ));
}
}
#[cfg(any(test, fuzzing))]
{
- let PredictedNextFee { predicted_feerate, predicted_nondust_htlc_count, predicted_fee_sat } = *funding.next_local_fee.lock().unwrap();
- if predicted_feerate == commitment_data.tx.negotiated_feerate_per_kw() && predicted_nondust_htlc_count == commitment_data.tx.nondust_htlcs().len() {
+ let PredictedNextFee {
+ predicted_feerate,
+ predicted_nondust_htlc_count,
+ predicted_fee_sat,
+ } = *funding.next_local_fee.lock().unwrap();
+ if predicted_feerate == commitment_data.tx.negotiated_feerate_per_kw()
+ && predicted_nondust_htlc_count == commitment_data.tx.nondust_htlcs().len()
+ {
assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
}
}
if msg.htlc_signatures.len() != commitment_data.tx.nondust_htlcs().len() {
- return Err(ChannelError::close(format!("Got wrong number of HTLC signatures ({}) from remote. It must be {}", msg.htlc_signatures.len(), commitment_data.tx.nondust_htlcs().len())));
+ return Err(ChannelError::close(format!(
+ "Got wrong number of HTLC signatures ({}) from remote. It must be {}",
+ msg.htlc_signatures.len(),
+ commitment_data.tx.nondust_htlcs().len()
+ )));
}
let holder_keys = commitment_data.tx.trust().keys();
- for (htlc, counterparty_sig) in commitment_data.tx.nondust_htlcs().iter().zip(msg.htlc_signatures.iter()) {
+ for (htlc, counterparty_sig) in
+ commitment_data.tx.nondust_htlcs().iter().zip(msg.htlc_signatures.iter())
+ {
assert!(htlc.transaction_output_index.is_some());
- let htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_data.tx.negotiated_feerate_per_kw(),
- funding.get_counterparty_selected_contest_delay().unwrap(), &htlc, funding.get_channel_type(),
- &holder_keys.broadcaster_delayed_payment_key, &holder_keys.revocation_key);
+ let htlc_tx = chan_utils::build_htlc_transaction(
+ &commitment_txid,
+ commitment_data.tx.negotiated_feerate_per_kw(),
+ funding.get_counterparty_selected_contest_delay().unwrap(),
+ &htlc,
+ funding.get_channel_type(),
+ &holder_keys.broadcaster_delayed_payment_key,
+ &holder_keys.revocation_key,
+ );
- let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, funding.get_channel_type(), &holder_keys);
- let htlc_sighashtype = if funding.get_channel_type().supports_anchors_zero_fee_htlc_tx() { EcdsaSighashType::SinglePlusAnyoneCanPay } else { EcdsaSighashType::All };
- let htlc_sighash = hash_to_message!(&sighash::SighashCache::new(&htlc_tx).p2wsh_signature_hash(0, &htlc_redeemscript, htlc.to_bitcoin_amount(), htlc_sighashtype).unwrap()[..]);
+ let htlc_redeemscript =
+ chan_utils::get_htlc_redeemscript(&htlc, funding.get_channel_type(), &holder_keys);
+ let htlc_sighashtype = if funding.get_channel_type().supports_anchors_zero_fee_htlc_tx()
+ {
+ EcdsaSighashType::SinglePlusAnyoneCanPay
+ } else {
+ EcdsaSighashType::All
+ };
+ let htlc_sighash = hash_to_message!(
+ &sighash::SighashCache::new(&htlc_tx)
+ .p2wsh_signature_hash(
+ 0,
+ &htlc_redeemscript,
+ htlc.to_bitcoin_amount(),
+ htlc_sighashtype
+ )
+ .unwrap()[..]
+ );
log_trace!(logger, "Checking HTLC tx signature {} by key {} against tx {} (sighash {}) with redeemscript {} in channel {}.",
- log_bytes!(counterparty_sig.serialize_compact()[..]), log_bytes!(holder_keys.countersignatory_htlc_key.to_public_key().serialize()),
- encode::serialize_hex(&htlc_tx), log_bytes!(htlc_sighash[..]), encode::serialize_hex(&htlc_redeemscript), &self.channel_id());
- if let Err(_) = self.secp_ctx.verify_ecdsa(&htlc_sighash, &counterparty_sig, &holder_keys.countersignatory_htlc_key.to_public_key()) {
+ log_bytes!(counterparty_sig.serialize_compact()[..]),
+ log_bytes!(holder_keys.countersignatory_htlc_key.to_public_key().serialize()),
+ encode::serialize_hex(&htlc_tx),
+ log_bytes!(htlc_sighash[..]),
+ encode::serialize_hex(&htlc_redeemscript),
+ &self.channel_id(),
+ );
+ if let Err(_) = self.secp_ctx.verify_ecdsa(
+ &htlc_sighash,
+ &counterparty_sig,
+ &holder_keys.countersignatory_htlc_key.to_public_key(),
+ ) {
return Err(ChannelError::close("Invalid HTLC tx signature from peer".to_owned()));
}
}
@@ -4643,10 +4709,15 @@ where
msg.signature,
msg.htlc_signatures.clone(),
&funding.get_holder_pubkeys().funding_pubkey,
- funding.counterparty_funding_pubkey()
+ funding.counterparty_funding_pubkey(),
);
- self.holder_signer.as_ref().validate_holder_commitment(&holder_commitment_tx, commitment_data.outbound_htlc_preimages)
+ self.holder_signer
+ .as_ref()
+ .validate_holder_commitment(
+ &holder_commitment_tx,
+ commitment_data.outbound_htlc_preimages,
+ )
.map_err(|_| ChannelError::close("Failed to validate our commitment".to_owned()))?;
Ok((holder_commitment_tx, commitment_data.htlcs_included))
Why this scored 15/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.