Skip to content

fuzz: chanmon peer message delivery through normal queues#4619

Closed
joostjager wants to merge 19 commits into
lightningdevkit:mainfrom
joostjager:fuzz-messages
Closed

fuzz: chanmon peer message delivery through normal queues#4619
joostjager wants to merge 19 commits into
lightningdevkit:mainfrom
joostjager:fuzz-messages

Conversation

@joostjager
Copy link
Copy Markdown
Contributor

@joostjager joostjager commented May 19, 2026

Make the chanmon consistency harness route delayed peer messages by source and destination, then deliver reconnect/setup control messages through the same queue path used during fuzz actions. This removes several special-case setup paths while keeping funding-lock assertions narrow to the messages required for channel readiness and announcements.

Preparatory commits for #4381

Based on #4465 and #4583

joostjager added 19 commits May 15, 2026 13:33
Replace the chanmon consistency harness' Watch wrapper with a Persist
implementation backed by HarnessPersister. Monitor writes now flow
through the real ChainMonitor persistence hooks.

Track restart candidates separately from monitor completion callbacks. A
monitor can stop being a valid reload candidate once a newer baseline is
durable, while its callback may still be needed to unblock the live
ChainMonitor.

On reload, choose the durable baseline, first pending snapshot, or last
pending snapshot. Startup monitor registration completes immediately
before the configured persistence style is restored.
Treat HTLC-forward processing and monitor completion as real progress
in the chanmon harness.

This keeps the settle loop running after passes that only unblock
follow-up work instead of stopping before the next event or message
batch.
Build the replacement persister with the configured monitor update
status during reload.

This keeps non-deferred restart behavior aligned with the active
persistence-style matrix.
Track deferred monitor writes in the harness and checkpoint the
ChannelManager state before flushing them to the persister.

This extends setup, reload, and settle paths to model deferred
ChainMonitor persistence ordering.
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.
Queue delayed peer messages by their source and destination link.
Handle control messages that can be produced by delayed peers.
Use the normal message queue while keeping setup assertions strict.
@ldk-reviews-bot
Copy link
Copy Markdown

👋 Hi! I see this is a draft PR.
I'll wait to assign reviewers until you mark it as ready for review.
Just convert it out of draft status when you're ready for review!

@codecov
Copy link
Copy Markdown

codecov Bot commented May 19, 2026

Codecov Report

❌ Patch coverage is 94.66019% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.56%. Comparing base (b8118e3) to head (cf4dab7).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/chain/channelmonitor.rs 79.00% 20 Missing and 1 partial ⚠️
lightning/src/chain/onchaintx.rs 99.58% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4619      +/-   ##
==========================================
+ Coverage   86.40%   86.56%   +0.15%     
==========================================
  Files         158      159       +1     
  Lines      109293   110159     +866     
  Branches   109293   110159     +866     
==========================================
+ Hits        94439    95363     +924     
+ Misses      12309    12268      -41     
+ Partials     2545     2528      -17     
Flag Coverage Δ
fuzzing-fake-hashes 5.75% <0.00%> (+0.67%) ⬆️
fuzzing-real-hashes 23.40% <0.00%> (+0.61%) ⬆️
tests 86.22% <94.66%> (+0.08%) ⬆️

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.

@joostjager joostjager closed this May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants