Fix misleading comment on counterparty_commitment_txn_on_chain insert
What changed, and why it matters
This commit only changes a code comment to accurately describe why a particular data structure is populated. No program logic, data flow, or behavior was altered. It is purely a documentation fix.
No action required; this is a non-functional comment-only change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch updates an explanatory comment in lightning/src/chain/channelmonitor.rs around the insertion into counterparty_commitment_txn_on_chain. The old comment said the insert was only a safety measure for a watchtower race and “isn’t useful yet.” The new comment clarifies that the map is actively used by provide_payment_preimage to resolve a commitment number when a preimage arrives after the counterparty commitment transaction is confirmed, in addition to the watchtower race case. No executable code was changed.
Changed components
lightning/src/chain/channelmonitor.rsInspect captured patch +10 / −7
diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs
index 0173e98..810de80 100644
--- a/lightning/src/chain/channelmonitor.rs
+++ b/lightning/src/chain/channelmonitor.rs
@@ -4867,13 +4867,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
} else if let Some(per_commitment_claimable_data) = per_commitment_option {
assert_eq!(funding_spent.funding_txid(), funding_txid_spent);
- // While this isn't useful yet, there is a potential race where if a counterparty
- // revokes a state at the same time as the commitment transaction for that state is
- // confirmed, and the watchtower receives the block before the user, the user could
- // upload a new ChannelMonitor with the revocation secret but the watchtower has
- // already processed the block, resulting in the counterparty_commitment_txn_on_chain entry
- // not being generated by the above conditional. Thus, to be safe, we go ahead and
- // insert it here.
+ // Track that this counterparty commitment tx appeared on-chain. This is
+ // used by `provide_payment_preimage` to look up the commitment number
+ // when a preimage arrives after the commitment tx is already confirmed.
+ // It also handles a race where a counterparty revokes a state at the
+ // same time as the commitment transaction for that state is confirmed,
+ // and the watchtower receives the block before the user. The user could
+ // upload a new ChannelMonitor with the revocation secret but the
+ // watchtower has already processed the block, resulting in the
+ // counterparty_commitment_txn_on_chain entry not being generated by
+ // the above conditional.
self.counterparty_commitment_txn_on_chain.insert(commitment_txid, commitment_number);
log_info!(logger, "Got broadcast of non-revoked counterparty commitment transaction {}", commitment_txid);
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.