Rename `CommitmentTransaction.feerate_per_kw()`
What changed, and why it matters
This commit is a simple rename of a method from `feerate_per_kw()` to `negotiated_feerate_per_kw()` across the codebase, plus an update to its documentation. The goal is to make it clearer that the returned value is the fee rate agreed with the peer, not necessarily the actual fee rate used on-chain. There are no logic changes and no security fix.
No action required; this is a non-functional documentation and naming refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is a pure refactor: CommitmentTransaction::feerate_per_kw() is renamed to negotiated_feerate_per_kw() and all call sites are updated. The documentation now explicitly notes that the actual commitment transaction feerate may be higher than the negotiated one. No arithmetic, control flow, or protocol behavior is altered.
Changed components
lightning/src/ln/chan_utils.rslightning/src/chain/channelmonitor.rslightning/src/chain/onchaintx.rslightning/src/chain/package.rslightning/src/ln/channel.rslightning/src/sign/mod.rsInspect captured patch +22 / −17
diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs
index ee36c40..6a9a88a 100644
--- a/lightning/src/chain/channelmonitor.rs
+++ b/lightning/src/chain/channelmonitor.rs
@@ -367,7 +367,7 @@ fn write_legacy_holder_commitment_data<W: Writer>(
let txid = trusted_tx.txid();
let to_self_value_sat = commitment_tx.to_broadcaster_value_sat();
- let feerate_per_kw = trusted_tx.feerate_per_kw();
+ let feerate_per_kw = trusted_tx.negotiated_feerate_per_kw();
let revocation_key = &tx_keys.revocation_key;
let a_htlc_key = &tx_keys.broadcaster_htlc_key;
let b_htlc_key = &tx_keys.countersignatory_htlc_key;
@@ -3455,7 +3455,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
) {
// We populate this field for downgrades
self.initial_counterparty_commitment_info = Some((commitment_tx.per_commitment_point(),
- commitment_tx.feerate_per_kw(), commitment_tx.to_broadcaster_value_sat(), commitment_tx.to_countersignatory_value_sat()));
+ commitment_tx.negotiated_feerate_per_kw(), commitment_tx.to_broadcaster_value_sat(), commitment_tx.to_countersignatory_value_sat()));
#[cfg(debug_assertions)] {
let rebuilt_commitment_tx = self.initial_counterparty_commitment_tx().unwrap();
@@ -3661,7 +3661,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
{
return Err("Per-commitment-point mismatch");
}
- if commitment_tx.feerate_per_kw() != other_commitment_tx.feerate_per_kw() {
+ if commitment_tx.negotiated_feerate_per_kw()
+ != other_commitment_tx.negotiated_feerate_per_kw()
+ {
return Err("Commitment fee rate mismatch");
}
let nondust_htlcs = commitment_tx.nondust_htlcs();
@@ -4823,7 +4825,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
commitment_txid: tx.txid(),
per_commitment_number: tx.commitment_number(),
per_commitment_point: tx.per_commitment_point(),
- feerate_per_kw: tx.feerate_per_kw(),
+ feerate_per_kw: tx.negotiated_feerate_per_kw(),
htlc: htlc.clone(),
preimage,
counterparty_sig: *counterparty_sig,
diff --git a/lightning/src/chain/onchaintx.rs b/lightning/src/chain/onchaintx.rs
index deb1282..3f7dd5a 100644
--- a/lightning/src/chain/onchaintx.rs
+++ b/lightning/src/chain/onchaintx.rs
@@ -1397,7 +1397,7 @@ mod tests {
commitment_txid: holder_commit_txid,
per_commitment_number: holder_commit.commitment_number(),
per_commitment_point: holder_commit.per_commitment_point(),
- feerate_per_kw: holder_commit.feerate_per_kw(),
+ feerate_per_kw: holder_commit.negotiated_feerate_per_kw(),
htlc: htlc.clone(),
preimage: None,
counterparty_sig: *counterparty_sig,
diff --git a/lightning/src/chain/package.rs b/lightning/src/chain/package.rs
index bdc5774..5b509fa 100644
--- a/lightning/src/chain/package.rs
+++ b/lightning/src/chain/package.rs
@@ -528,7 +528,7 @@ impl HolderHTLCOutput {
commitment_txid: trusted_tx.txid(),
per_commitment_number: trusted_tx.commitment_number(),
per_commitment_point: trusted_tx.per_commitment_point(),
- feerate_per_kw: trusted_tx.feerate_per_kw(),
+ feerate_per_kw: trusted_tx.negotiated_feerate_per_kw(),
htlc: htlc.clone(),
preimage: self.preimage.clone(),
counterparty_sig: *counterparty_sig,
@@ -1893,7 +1893,7 @@ mod tests {
commitment_txid: trusted_tx.txid(),
per_commitment_number: trusted_tx.commitment_number(),
per_commitment_point: trusted_tx.per_commitment_point(),
- feerate_per_kw: trusted_tx.feerate_per_kw(),
+ feerate_per_kw: trusted_tx.negotiated_feerate_per_kw(),
htlc,
preimage: Some(preimage),
counterparty_sig: commitment_tx.counterparty_htlc_sigs[0].clone(),
@@ -1930,7 +1930,7 @@ mod tests {
commitment_txid: trusted_tx.txid(),
per_commitment_number: trusted_tx.commitment_number(),
per_commitment_point: trusted_tx.per_commitment_point(),
- feerate_per_kw: trusted_tx.feerate_per_kw(),
+ feerate_per_kw: trusted_tx.negotiated_feerate_per_kw(),
htlc,
preimage: None,
counterparty_sig: commitment_tx.counterparty_htlc_sigs[0].clone(),
diff --git a/lightning/src/ln/chan_utils.rs b/lightning/src/ln/chan_utils.rs
index dfd2db9..8dc5c7b 100644
--- a/lightning/src/ln/chan_utils.rs
+++ b/lightning/src/ln/chan_utils.rs
@@ -1980,8 +1980,11 @@ impl CommitmentTransaction {
self.to_countersignatory_value_sat.to_sat()
}
- /// The feerate paid per 1000-weight-unit in this commitment transaction.
- pub fn feerate_per_kw(&self) -> u32 {
+ /// The feerate paid per 1000-weight-unit we negotiated with our
+ /// peer for this commitment transaction. Note that the actual
+ /// feerate of the commitment transaction may be higher than the
+ /// negotiated feerate.
+ pub fn negotiated_feerate_per_kw(&self) -> u32 {
self.feerate_per_kw
}
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 783e1e1..3ce23d0 100644
--- a/lightning/src/ln/channel.rs
+++ b/lightning/src/ln/channel.rs
@@ -4611,7 +4611,7 @@ where
#[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.feerate_per_kw() && predicted_nondust_htlc_count == commitment_data.tx.nondust_htlcs().len() {
+ 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);
}
}
@@ -4623,7 +4623,7 @@ where
let holder_keys = commitment_data.tx.trust().keys();
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.feerate_per_kw(),
+ 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);
@@ -11875,7 +11875,7 @@ where
htlc_outputs,
commitment_number: self.context.counterparty_next_commitment_transaction_number,
their_per_commitment_point: self.context.counterparty_next_commitment_point.unwrap(),
- feerate_per_kw: Some(counterparty_commitment_tx.feerate_per_kw()),
+ feerate_per_kw: Some(counterparty_commitment_tx.negotiated_feerate_per_kw()),
to_broadcaster_value_sat: Some(counterparty_commitment_tx.to_broadcaster_value_sat()),
to_countersignatory_value_sat: Some(counterparty_commitment_tx.to_countersignatory_value_sat()),
}
@@ -11938,7 +11938,7 @@ where
#[cfg(any(test, fuzzing))]
{
let PredictedNextFee { predicted_feerate, predicted_nondust_htlc_count, predicted_fee_sat } = *funding.next_remote_fee.lock().unwrap();
- if predicted_feerate == counterparty_commitment_tx.feerate_per_kw() && predicted_nondust_htlc_count == counterparty_commitment_tx.nondust_htlcs().len() {
+ if predicted_feerate == counterparty_commitment_tx.negotiated_feerate_per_kw() && predicted_nondust_htlc_count == counterparty_commitment_tx.nondust_htlcs().len() {
assert_eq!(predicted_fee_sat, commitment_data.stats.commit_tx_fee_sat);
}
}
@@ -12002,7 +12002,7 @@ where
debug_assert_eq!(htlc_signatures.len(), trusted_tx.nondust_htlcs().len());
for (ref htlc_sig, ref htlc) in htlc_signatures.iter().zip(trusted_tx.nondust_htlcs()) {
log_trace!(logger, "Signed remote HTLC tx {} with redeemscript {} with pubkey {} -> {} in channel {}",
- encode::serialize_hex(&chan_utils::build_htlc_transaction(&trusted_tx.txid(), trusted_tx.feerate_per_kw(), funding.get_holder_selected_contest_delay(), htlc, funding.get_channel_type(), &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
+ encode::serialize_hex(&chan_utils::build_htlc_transaction(&trusted_tx.txid(), trusted_tx.negotiated_feerate_per_kw(), funding.get_holder_selected_contest_delay(), htlc, funding.get_channel_type(), &counterparty_keys.broadcaster_delayed_payment_key, &counterparty_keys.revocation_key)),
encode::serialize_hex(&chan_utils::get_htlc_redeemscript(&htlc, funding.get_channel_type(), &counterparty_keys)),
log_bytes!(counterparty_keys.broadcaster_htlc_key.to_public_key().serialize()),
log_bytes!(htlc_sig.serialize_compact()[..]), &self.context.channel_id());
@@ -15784,7 +15784,7 @@ mod tests {
commitment_txid: trusted_tx.txid(),
per_commitment_number: trusted_tx.commitment_number(),
per_commitment_point: trusted_tx.per_commitment_point(),
- feerate_per_kw: trusted_tx.feerate_per_kw(),
+ feerate_per_kw: trusted_tx.negotiated_feerate_per_kw(),
htlc: htlc.clone(),
preimage: preimage.clone(),
counterparty_sig: *htlc_counterparty_sig,
diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs
index 5795c0e..6d6b819 100644
--- a/lightning/src/sign/mod.rs
+++ b/lightning/src/sign/mod.rs
@@ -1464,7 +1464,7 @@ impl EcdsaChannelSigner for InMemorySigner {
let chan_type = &channel_parameters.channel_type_features;
let htlc_tx = chan_utils::build_htlc_transaction(
&commitment_txid,
- commitment_tx.feerate_per_kw(),
+ commitment_tx.negotiated_feerate_per_kw(),
holder_selected_contest_delay,
htlc,
chan_type,
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.