perf(consensus): skip fsync for unsigned internal messages (block parts)#28
Open
JayT106 wants to merge 2 commits intocrypto-org-chain:v0.38.xfrom
Open
perf(consensus): skip fsync for unsigned internal messages (block parts)#28JayT106 wants to merge 2 commits intocrypto-org-chain:v0.38.xfrom
JayT106 wants to merge 2 commits intocrypto-org-chain:v0.38.xfrom
Conversation
Only signed messages (votes, proposals) need WriteSync (fsync) in the WAL for double-signing prevention. Block parts are unsigned data where losing them on crash just causes a round timeout, not a safety violation. Replace the blanket WriteSync in receiveRoutine with an explicit type switch: WriteSync for VoteMessage/ProposalMessage, buffered Write for BlockPartMessage. Unknown message types panic to prevent future signed types from silently bypassing fsync. The pre-sign FlushAndSync calls (before SignVote and SignProposal) ensure buffered block parts reach disk before any signature is produced. Benchmark (50 block parts/round, Apple M1 Max): AllWriteSync: ~240ms/round SelectiveFsync: ~10.6ms/round (~23x faster) Backport of cometbft#5695. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fsync(WriteSync) forBlockPartMessagein the consensus WAL'sreceiveRoutine, using bufferedWriteinsteadVoteMessage,ProposalMessage) retainWriteSyncfor double-signing preventiondefault: panicprevents future signed message types from silently bypassing fsyncBackport of cometbft#5695 to
v0.38.x.Motivation
In
receiveRoutine, every message frominternalMsgQueuecalledWriteSync(Write + fsync). For a proposer with N block parts per round, this meant N+2 fsyncs per round (N can be 10–100+). Each fsync costs ~1–10ms on typical hardware, and up to 10–50ms on cloud storage (e.g., AWS EBS).Block parts are unsigned data — losing them on crash causes a round timeout (liveness), not double-signing (safety). The existing
FlushAndSynccalls beforeSignVoteandSignProposalalready flush all buffered writes to disk before any signature is produced, maintaining the critical safety invariant.Safety analysis
Why signed messages MUST keep
WriteSync:FlushAndSyncensures WAL replay reaches the same deterministic stateWriteSyncensures the signed message is durable beforehandleMsgprocesses/broadcasts itWhy
BlockPartMessagecan safely useWrite:processFlushTicks) eventually flushes themWriteSync(vote) orFlushAndSync(pre-sign) also flushes buffered block partsEndHeightMessageusesWriteSync, which flushes ALL buffered writes before the end markerBenchmark results (Apple M1 Max SSD)
Test plan
go build ./consensus/— compiles cleanlygo vet ./consensus/— no issuesTestWALSelectiveFsync— new test verifying dispatch logicTestWALCrash— existing crash/replay tests passTestWALTruncate,TestWALEncoderDecoder,TestWALWrite,TestWALSearchForEndHeight,TestWALPeriodicSync— all passBenchmarkWALWrite,BenchmarkWALWriteSync,BenchmarkWALRoundSimulation— benchmarks pass🤖 Generated with Claude Code