Add debug assertions on revoked counterparty tx number fetching
What changed, and why it matters
This commit adds an internal consistency check (a debug-only assertion) to make sure two different places storing the same counterparty commitment transaction number agree. It does not change release behavior, fix a known bug, or alter how funds are secured. It is a defensive code-quality improvement.
No action required. Treat as routine defensive hardening; monitor future commits if this assertion ever fires in tests.
Security signals we found
Adds defensive debug assertion for state consistency
Touches revoked commitment transaction number logic
Evidence from the diff
The change introduces a debug_assert_eq! inside get_revoked_counterparty_commitment_transaction_number() comparing the computed value context.cur_counterparty_commitment_transaction_number + 2 with context.commitment_secrets.get_min_seen_secret(). Debug assertions are compiled out in release builds, so this has no runtime effect on production nodes. It is purely a sanity check against future state inconsistency.
Changed components
lightning/src/ln/channel.rsget_revoked_counterparty_commitment_transaction_numberInspect captured patch +3 / −1
diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs
index 115d68a..24da77f 100644
--- a/lightning/src/ln/channel.rs
+++ b/lightning/src/ln/channel.rs
@@ -9608,7 +9608,9 @@ where
}
pub fn get_revoked_counterparty_commitment_transaction_number(&self) -> u64 {
- self.context.cur_counterparty_commitment_transaction_number + 2
+ let ret = self.context.cur_counterparty_commitment_transaction_number + 2;
+ debug_assert_eq!(self.context.commitment_secrets.get_min_seen_secret(), ret);
+ ret
}
#[cfg(any(test, feature = "_externalize_tests"))]
Why this scored 16/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.