Skip to content

Improve chanmon_consistency fuzz target performance#4509

Draft
joostjager wants to merge 3 commits intolightningdevkit:mainfrom
joostjager:fuzz-performance
Draft

Improve chanmon_consistency fuzz target performance#4509
joostjager wants to merge 3 commits intolightningdevkit:mainfrom
joostjager:fuzz-performance

Conversation

@joostjager
Copy link
Contributor

Reduce per-iteration overhead in the chanmon_consistency fuzz target. Together these achieve a 3-4x speedup. This target has proven crucial for finding bugs, so maximizing its iteration rate is relevant.

The searched-for log message ("Outbound update_fee HTLC buffer
overflow") no longer exists in the lightning crate, so the
from_utf8 + contains check on every log line was pure waste.

AI tools were used in preparing this commit.
Even though DevNull discards the bytes, the formatting work
(SubstringFormatter, fmt::write, from_utf8) was still being done
on every log call. Short-circuit in TestLogger::log via a TypeId
check, which monomorphization resolves at compile time.

AI tools were used in preparing this commit.
Previously, TestChainMonitor::update_channel would deserialize the
monitor from stored bytes, apply the update, and serialize it back.
This duplicated the work already done by the inner ChainMonitor,
which applies the update to its in-memory monitor and calls the
persister.

Instead, have TestPersister capture the monitor directly when the
real ChainMonitor calls persist. Serialization is deferred until
reload_node actually needs the bytes, which happens rarely (only on
specific fuzz input bytes that trigger a node restart). This
eliminates redundant deserialization and serialization on every
monitor update, replacing the expensive serialize-on-every-persist
with a cheaper clone.

AI tools were used in preparing this commit.
@ldk-reviews-bot
Copy link

👋 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

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.18%. Comparing base (ab31f99) to head (04f3894).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4509      +/-   ##
==========================================
- Coverage   86.19%   86.18%   -0.02%     
==========================================
  Files         160      160              
  Lines      107537   107537              
  Branches   107537   107537              
==========================================
- Hits        92693    92679      -14     
- Misses      12220    12230      +10     
- Partials     2624     2628       +4     
Flag Coverage Δ
tests 86.18% <ø> (-0.02%) ⬇️

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
Copy link
Contributor Author

I can now see that on CI the speed up is a bit less than on my local machine. Factor 2.5x in CI.

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