refactor(node/chain): simplify the chain service loop and docs#1106
Merged
tcoratger merged 1 commit intoJun 16, 2026
Merged
Conversation
- Drop the Interval | None sentinel: _initial_tick returns the anchor interval (0) before genesis, so the run loop guard collapses to a single "wait unless a strictly-new interval is due" predicate and the post-sleep re-read disappears. - Trim the verbose docstrings and comments to the project documentation rules, keeping only the non-obvious rationale (clock can step backward, why skipping stale intervals is safe, why we yield and re-read the store, why catch-up aggregates are discarded). - Update the startup-tick test for the new return contract. Also document the concurrency invariant at the gossip-block write-back: the processed path never awaits, so a concurrent clock tick cannot advance the store between the read and the write-back. No behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <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
Clarity and documentation pass over the ChainService that drives consensus timing. No behavior change to the timing logic; the existing chain tests pass (with one test updated for a simplified return contract).
Chain service (
chain/service.py)Interval | Nonesentinel._initial_ticknow returns the anchor intervalInterval(0)before genesis instead ofNone. This collapses therun()loop guard into a single "wait unless a strictly-new interval is due" predicate and removes the post-sleep double-read of the interval. Verified safe: the clock clamps elapsed time to zero before genesis, sototal_intervals()never underflows._tick_todocstring shrinks to three lines (the skip/yield rationale already lives in the inline comments at the exact lines),stop()becomes one line, and severalrun()comment blocks lose their narration. All the genuine non-obvious rationale is preserved: the wall clock can step backward, why skipping stale intervals is safe, why we yield and re-read the store, and why catch-up aggregates are discarded.Sync service (
sync/service.py)processed=False); the comment guards the emergent safety against a future change that makes block processing await.Testing
just checkpasses (ruff, format, ty, codespell, mdformat).uv run pytest tests/node/chain tests/node/sync— all pass.🤖 Generated with Claude Code