fuzz: factor chanmon finish cleanup helper
What changed, and why it matters
This commit is a simple code cleanup inside a fuzz testing harness. It moves an existing loop that relays and mines transactions into a new helper function, then calls that helper from the existing 'finish' method. No behavior changes are visible in the diff, and the code is not part of the production Lightning library that real users would run.
No security action needed. This is a benign test-only refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors Harness::finish in fuzz/src/chanmon_consistency.rs. The body of the finish-time relay/mining loop is extracted into a new private method mine_relayed_txs_until_quiet, and finish now just calls that helper followed by assert_test_invariants. The loop logic, constants (MAX_FINISH_RELAY_MINE_ROUNDS, ANTI_REORG_DELAY), assertions, and comments are preserved verbatim. This is purely a test-code maintainability refactor.
Changed components
fuzz/src/chanmon_consistency.rsInspect captured patch +25 / −24
diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs
index c65e86d..9bcd975 100644
--- a/fuzz/src/chanmon_consistency.rs
+++ b/fuzz/src/chanmon_consistency.rs
@@ -2609,30 +2609,7 @@ impl<'a, Out: Output + MaybeSend + MaybeSync> Harness<'a, Out> {
// Final invariants should not depend on the input ending with explicit relay
// and mining bytes.
fn finish(&mut self) {
- for _ in 0..MAX_FINISH_RELAY_MINE_ROUNDS {
- let mut txs = Vec::new();
- for node in &self.nodes {
- txs.extend(node.broadcaster.txn_broadcasted.borrow_mut().drain(..));
- }
- self.chain_state.relay_transactions(txs);
- if self.chain_state.pending_txs.is_empty() {
- assert_test_invariants(&self.nodes);
- return;
- }
- if self.mine_blocks(ANTI_REORG_DELAY) == 0 {
- // The input ended with pending mempool transactions but no safe
- // block left before an HTLC fail-back window. Leave them
- // unconfirmed rather than forcing finish cleanup to advance
- // the chain past that boundary.
- assert_test_invariants(&self.nodes);
- return;
- }
- }
- assert!(
- !self.nodes.iter().any(|node| !node.broadcaster.txn_broadcasted.borrow().is_empty())
- && self.chain_state.pending_txs.is_empty(),
- "finish tx mining loop failed to quiesce",
- );
+ self.mine_relayed_txs_until_quiet();
assert_test_invariants(&self.nodes);
}
@@ -3451,6 +3428,30 @@ impl<'a, Out: Output + MaybeSend + MaybeSync> Harness<'a, Out> {
}
count
}
+
+ fn mine_relayed_txs_until_quiet(&mut self) {
+ for _ in 0..MAX_FINISH_RELAY_MINE_ROUNDS {
+ let mut txs = Vec::new();
+ for node in &self.nodes {
+ txs.extend(node.broadcaster.txn_broadcasted.borrow_mut().drain(..));
+ }
+ self.chain_state.relay_transactions(txs);
+ if self.chain_state.pending_txs.is_empty() {
+ return;
+ }
+ if self.mine_blocks(ANTI_REORG_DELAY) == 0 {
+ // Pending mempool transactions remain, but no safe block is
+ // left before an HTLC fail-back window. Leave them unconfirmed
+ // rather than advancing the chain past that boundary.
+ return;
+ }
+ }
+ assert!(
+ !self.nodes.iter().any(|node| !node.broadcaster.txn_broadcasted.borrow().is_empty())
+ && self.chain_state.pending_txs.is_empty(),
+ "tx mining loop failed to quiesce",
+ );
+ }
}
#[inline]
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.