Skip to content

fuzz: add force-close support to chanmon_consistency#4381

Draft
joostjager wants to merge 17 commits into
lightningdevkit:mainfrom
joostjager:fuzz-force-close
Draft

fuzz: add force-close support to chanmon_consistency#4381
joostjager wants to merge 17 commits into
lightningdevkit:mainfrom
joostjager:fuzz-force-close

Conversation

@joostjager
Copy link
Copy Markdown
Contributor

@joostjager joostjager commented Feb 4, 2026

Add force-close coverage to the chanmon_consistency fuzzer. Previously, the fuzzer only exercised cooperative channel flows. This PR enables the fuzzer to force-close channels and verify that on-chain resolution, HTLC timeouts, and payment preimage propagation all work correctly under channel monitor consistency
constraints.

Based on #4583, #4657, #4660

@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented Feb 4, 2026

👋 I see @wpaulino was un-assigned.
If you'd like another reviewer assignment, please click here.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.68%. Comparing base (1743b99) to head (9a3dc7c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4381      +/-   ##
==========================================
+ Coverage   86.58%   86.68%   +0.10%     
==========================================
  Files         159      159              
  Lines      110498   110827     +329     
  Branches   110498   110827     +329     
==========================================
+ Hits        95678    96075     +397     
+ Misses      12281    12221      -60     
+ Partials     2539     2531       -8     
Flag Coverage Δ
fuzzing-fake-hashes 6.60% <ø> (-0.02%) ⬇️
fuzzing-real-hashes 28.99% <ø> (+5.84%) ⬆️
tests 86.26% <ø> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread fuzz/src/chanmon_consistency.rs Outdated
},
events::Event::SplicePending { .. } => {},
events::Event::SpliceFailed { .. } => {},
events::Event::ChannelClosed { .. } => {},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably open a new channel to replace the force closed one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My plan is to start with closing only, but indeed, re-opening is interesting too perhapas.

Comment thread fuzz/src/chanmon_consistency.rs Outdated
@TheBlueMatt
Copy link
Copy Markdown
Collaborator

Needs rebase. Is this stalled waiting on fixes that were discovered by the fuzzer?

@joostjager
Copy link
Copy Markdown
Contributor Author

I was working on my local branch only for a while. Just pushed what I have. But indeed, the mixed mode failure is also showing up in different ways with fc fuzzing.

@joostjager joostjager force-pushed the fuzz-force-close branch 2 times, most recently from a1b1367 to ba6cbfa Compare April 16, 2026 13:33
@joostjager joostjager force-pushed the fuzz-force-close branch 2 times, most recently from f3cbd42 to 88ee2b7 Compare April 21, 2026 08:23
@joostjager
Copy link
Copy Markdown
Contributor Author

Rebased onto #4571, because compile times became unworkable with the many macros.

@joostjager joostjager force-pushed the fuzz-force-close branch 6 times, most recently from 5e7af7c to 2667e5e Compare April 29, 2026 10:09
joostjager added 16 commits June 2, 2026 13:14
Have ChannelMonitor hand singular ClaimRequests to OnchainTxHandler.

Convert them to PackageTemplates only after duplicate filtering.

This makes the single-outpoint invariant explicit at that boundary.
Clarify ChannelMonitor comments around on-chain event thresholds.
Some events only wait for anti-reorg finality, while CSV-delayed
outputs wait until spendable through the same threshold queue.
Move repeated OnchainTxHandler setup into shared test helpers so the
claim-replay coverage can focus on the behavior under test.
Add a monitor test for an inbound HTLC claimed by preimage from a
holder commitment. Confirm that the claimable balance remains unchanged
after the HTLC-success spend reaches anti-reorg finality but before the
CSV-delayed output is spendable.
Treat HTLCSpendConfirmation entries as irrevocably resolved once
the commitment HTLC output spend reaches anti-reorg finality. Do
not wait for CSV maturity of any delayed output created by that
spend.

Delayed outputs remain tracked separately as MaturingOutput entries,
keeping claimable balances alive until they are CSV-mature and can be
surfaced as SpendableOutputs.
Check that any HTLCSpendConfirmation carrying a local-output CSV
has a matching delayed MaturingOutput. Scan spendable outputs before
recording HTLC spend confirmations so the invariant is present when
the assertion runs.
A replayed holder HTLC claim may arrive as a single-outpoint
request after earlier requests were merged into a delayed package.
Check whether an existing delayed package already covers the new
request instead of requiring exact outpoint-set equality.

Add focused OnchainTxHandler coverage and a ChannelMonitor regression
through claim_funds for both current anchor variants.
When a transaction spends one outpoint from a delayed package, the
split outpoint is tracked as a ContentiousOutpoint until the spend
reaches anti-reorg finality. Reject replayed claim requests for those
pending-spent outpoints so they are not added back before the spend
reaches anti-reorg finality or reorgs out.

Add an OnchainTxHandler regression that replays a holder claim during
that pending-spent window and verifies reorg resurrection still works.
Classify duplicate outpoint state in one helper.

Preserve existing filter ordering and timelock logging.
Filter regenerated HTLC claim requests once ChannelMonitor has persisted
anti-reorg finality for the commitment HTLC output spend.

This keeps replayed preimage updates from recreating claims after
OnchainTxHandler has cleaned up its active retry state, relying on the
monitor's persisted HTLC resolution state.
Log when a replayed preimage claim is skipped because the
HTLC output reached anti-reorg finality without that preimage.
Hash HTLC claim outpoints in canonical order so the same logical HTLC
set produces the same ClaimId regardless of descriptor order.

Add a unit test covering reversed descriptor order.
Restore cfg(splicing) to the fuzz check-cfg allow list and gate
chanmon consistency splice opcodes on that cfg again. Without the
cfg, those inputs stop before executing splice-specific operations.
Route chanmon broadcasts through an explicit harness mempool.

Relay, mining, wallet updates, and chain delivery share one path.

This lets splice, anchor, and claim txs enter the mempool before mining.
Allow chanmon consistency inputs to block and later unblock
holder-side signing operations. This lets focused force-close
fuzzing reuse the signer-op machinery without carrying the larger
mining and settlement model.
Replace repeated per-node setup and event-processing calls with loops.

Keep the existing assertions and early-continue behavior intact.
@joostjager
Copy link
Copy Markdown
Contributor Author

Splitting functionality out of this final destination PR is still ongoing. The biggest chunk at the moment is the mempool modeling, which now has its own PR #4657.

I’ve also expanded the fuzzing concept from covering only explicit user-triggered force closes to covering organic force closes as well, where LDK naturally force-closes because HTLCs time out. The latter requires more bookkeeping to keep stable invariants: we should only allow force closes when the harness expects them.

Side note: payment tracking is another area that becomes more complex, because dust may impact what the final outcome is for the sender.

Fold the mempool follow-up into the force-close fuzzing layer so
this branch has one commit for settlement coverage.

Keep relay and mining opcodes from the mempool model while adding
explicit and timeout-driven close tracking, holder signer unblocks,
and cleanup that drives on-chain claims.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants