refactor(sync): inline make_default_block_processor as method#731
Merged
tcoratger merged 1 commit intoMay 18, 2026
Merged
Conversation
The factory existed only to capture `spec` in a closure for the SyncService.process_block field. SyncService already has self.spec, so the closure is unnecessary indirection. Inlines the body as _default_process_block(self, store, block) and binds it as the default in __post_init__. The process_block field stays as a legitimate test-injection point. Tests use it to substitute mock processors that exercise the metrics and database-persistence wrapper without requiring a full spec or state transition. Net: -8 lines, zero behavior change, no test updates needed. A reader of SyncService now finds the block-processing logic as a method on the class instead of a module-level factory closure. Co-Authored-By: Claude Opus 4.7 (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
The
make_default_block_processor(spec)factory existed only tocapture
specin a closure for theSyncService.process_blockfield.
SyncServicealready hasself.spec, so the closure isunnecessary indirection. Inlines the body as
_default_process_block(self, store, block)and binds it as thedefault in
__post_init__.Net: -8 lines, zero behavior change, no test updates needed.
What changed
service.pyRemoved the module-level
make_default_block_processorfactory(~32 lines with docstring).
Added
_default_process_blockmethod onSyncService(~22lines, same body). Reads
self.specdirectly instead of acaptured closure variable.
Updated
__post_init__:What stayed the same
process_block: Callable | Nonefield stays. It is areal test-injection point used by two paths in the test suite:
create_mock_sync_servicepasseslambda s, b: s.on_block(b)so tests run againstMockForkchoiceStore.on_blockrather than a real spec._persist_process_block(...)inTestBlockPersistencesubstitutes a custom processor that exercises the
database-persistence wrapper without needing a real spec or
state transition.
computation, same
_process_block_wrapperflow.Correction on the original estimate
The earlier scan claimed "every call site uses the default" — that
was wrong. Tests genuinely override
process_block. The factoryitself is still worth removing (a closure capturing
self.specwhenthe method has
selfis pure indirection), but the metrics body hasto live somewhere, so savings are modest (~8 lines instead of ~30).
The architectural win is small but real:
_default_process_blockand
_process_block_wrappernow sit next to each other onSyncService, both readingself.specandself.database. Oneindirection layer fewer for a reader tracing the block-processing
path.
Test plan
ruff check,ruff format --check,ty checkall passpytest tests/lean_spec/subspecs/sync-> 156 passedOut of scope
The last queued item from the sync-layer review:
SyncServicemarketing-tone docstring rewrite (Reactive/Simple/Resilient/Observable)🤖 Generated with Claude Code