fix(chainfold): manual review fixes - #24
Open
rymnc wants to merge 5 commits into
Open
Conversation
rymnc
force-pushed
the
fix/manual-review-chainfold-fixes
branch
from
August 9, 2026 19:18
0839220 to
70cce9a
Compare
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.
Note
chainfold costs ~0.33 ns per event in steady state (3.1 G events/s on my machine) effectively free next to the RPC that fetched the logs, and in exchange gives us total ordering, idempotent replay, fork detection with rollback, and crash-safe restart from a durable snapshot in 3.7 ms for a million-entry state.
This pull request refactors and simplifies core validation, checkpoint, and driver logic in the
chainfoldcrate, improving clarity, correctness, and maintainability. The most notable changes include a significant rewrite of batch validation, simplification of checkpoint ring iteration, consolidation and improvement of driver rollback and checkpoint logic, and minor cleanups in the engine. Below are the most important changes grouped by theme:Batch Validation Improvements
Batch::validatemethod was rewritten for clarity and correctness. It now uses a previous-span tracker to check for contiguous spans, simplifies bounds checks, and efficiently checks log index ordering within spans. This reduces code duplication and potential for errors.Checkpoint Ring Refactoring
oldest_firstiterator inCheckpointRingto simplify and unify slot iteration logic, which is now used incount,oldest, andbest_at_or_belowmethods. Theclearanddrop_abovemethods were also simplified to use more idiomatic Rust. [1] [2]Driver Logic Simplification and Consolidation
.is_none_or()and.is_some_and()for checkpoint and snapshot due logic. [1] [2]roll_back_tomethod, reducing code duplication and making error handling more consistent. [1] [2].zip()and.map().Engine Cleanups and Minor Fixes
configfield fromEngine, and updated methods accordingly. [1] [2]Engine::resetto clear the block ring instead of recreating it, preserving allocation.apply_span, ensuring both accepted and skipped events advance the cursor, and deduplicating code.