Skip to content

refactor(sync): drop _SyncStoreView adapter, make SyncService implement StoreView#730

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/sync-store-view-removal
May 18, 2026
Merged

refactor(sync): drop _SyncStoreView adapter, make SyncService implement StoreView#730
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/sync-store-view-removal

Conversation

@tcoratger
Copy link
Copy Markdown
Collaborator

Summary

_SyncStoreView was a dataclass wrapping a lambda wrapping a getter on
SyncService.store. Three layers of indirection to read two fields.
SyncService can satisfy the StoreView protocol structurally with
two short methods, removing the wrapper without growing the call
surface.

Net: -28 lines, zero behavior change.

What changed

service.py

  • Removed the entire _SyncStoreView dataclass.
  • Added has_root(root) and head_slot() methods on SyncService
    itself. Each is a one-liner reading self.store.
  • Changed the wiring in _initialize_subservices:
    store_view=self instead of _SyncStoreView(_get_store=lambda: self.store).
    The live store reference is observed because backfill calls back
    through self and reads self.store on demand.

backfill_sync.py

  • Removed the finalized_slot() method from the StoreView
    Protocol. It was declared on the protocol, implemented on the
    removed wrapper and on FakeStoreView, and never called from
    any production code in backfill_sync.py. Pure protocol bloat.
  • Reformatted the surviving Protocol docstring.

test_backfill_sync.py

  • Removed finalized_slot() method and the finalized: Slot
    field from FakeStoreView.
  • Removed two store_view.finalized = Slot(10) dead writes
    (lines 379 and 411). These had no effect on production code or
    assertions — they were leftover setup from when the protocol
    included finalized_slot.

Why StoreView stays

The protocol earns its 8 lines:

  • Breaks a real circular dependency. service.py imports
    BackfillSync from backfill_sync.py. Typing the field as
    SyncService would create a cycle. The Protocol sidesteps this.
  • Test seam. FakeStoreView is a 5-line dataclass. Without the
    protocol, tests would need to construct real Store instances
    (with blocks, head, latest_finalized, config, etc.) just to
    exercise backfill.
  • Documents the contract. Two methods. A reader of BackfillSync
    sees exactly what it needs from forkchoice without grepping.

Test plan

  • ruff check, ruff format --check, ty check all pass
  • pytest tests/lean_spec/subspecs/sync -> 156 passed

Out of scope

The next queued items from the sync-layer review:

  • make_default_block_processor factory -> method
  • SyncService marketing-tone docstring (Reactive/Simple/Resilient/Observable)

🤖 Generated with Claude Code

…nt StoreView

_SyncStoreView was a dataclass wrapping a lambda wrapping a getter on
SyncService.store. Three layers of indirection to read two fields.
SyncService can satisfy the StoreView protocol structurally with two
short methods, removing the wrapper without growing the call surface.

Also drops the finalized_slot method from the StoreView protocol.
It was defined on the protocol, implemented on _SyncStoreView and on
FakeStoreView, and never called from backfill_sync. Pure protocol
bloat. Two dead set-but-not-read writes in tests removed too.

The StoreView protocol itself stays. It breaks a real circular
dependency (BackfillSync is imported by SyncService, so the field
type cannot reference SyncService directly), keeps the test seam
(FakeStoreView is 5 lines, no real Store construction needed), and
documents BackfillSync's exact dependency on forkchoice state in
8 lines.

Net: -28 lines, zero behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tcoratger tcoratger merged commit d0d0422 into leanEthereum:main May 18, 2026
13 checks passed
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.

1 participant