Skip to content

refactor: modernize batch — @override, single stop signal, struct cleanups#758

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/modernize-batch
May 22, 2026
Merged

refactor: modernize batch — @override, single stop signal, struct cleanups#758
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/modernize-batch

Conversation

@tcoratger
Copy link
Copy Markdown
Collaborator

Summary

Five modernization items from the audit, bundled. Net +193 / −239 across 13 files.

Module Change
subspecs/koalabear/field.py @override added to is_fixed_size, get_byte_length, serialize, deserialize so the SSZType contract is visible at the method site.
subspecs/networking/client/event_source/live.py + subspecs/networking/gossipsub/behavior.py After PR #743 both files carried _running (bool) and _stop_event (asyncio.Event). The event already exposes is_set/wait/set/clear, which covers every read and write the bool was doing. Dropped the bool; not self._stop_event.is_set() is the "running" predicate. The default factory stays a vanilla asyncio.Event; each file's __post_init__ forces it to set (= stopped) so fresh instances start stopped until dial/listen/start clears it. Updated __main__.py, node_runner.py, and 6 affected unit tests.
subspecs/storage/namespaces.py + sqlite.py Five @dataclass(frozen=True, slots=True) namespace classes whose only contents were string defaults collapsed to plain Final[str] module constants (BLOCKS_TABLE_NAME, BLOCKS_CREATE_TABLE, BLOCKS_CREATE_INDEX, ...). 30+ attribute accesses in sqlite.py and its import block rewritten.
subspecs/xmss/tweak_hash.py TreeTweak and ChainTweak were Pydantic StrictBaseModel instances used only as packing structs feeding the match tweak block. Converted both to typing.NamedTuple — the match patterns keep working since NamedTuple auto-populates __match_args__. The from __future__ import annotations line that the audit flagged as R1 (banned in Pydantic-defining files) goes away with the conversion; TweakHasher itself stays a StrictBaseModel.
subspecs/xmss/constants.py TWEAK_PREFIX_CHAIN/TREE/MESSAGE were Fp(value=0x00..0x02) wrappers whose every consumer immediately did .value. Inlined as plain Final[int]; dropped the unused Fp import and rewrote three call sites plus one test.

Test plan

  • ruff check — clean.
  • ruff format --check — clean.
  • ty check — clean (it caught 12 stale _running references in __main__.py and tests during iteration; all migrated).
  • pytest over koalabear, event_source, gossipsub publish, storage, xmss — 205 tests pass.
  • fill tests/consensus/lstar/fc/test_tick_system.py::test_tick_interval_progression_through_full_slot — 1 passed in 9.16s (consensus fixture pipeline still threads through after the lifecycle signal change).

🤖 Generated with Claude Code

…anups

Five modernization items from the audit, bundled.

koalabear/field: @OverRide decorator added to is_fixed_size,
get_byte_length, serialize, deserialize so the SSZType contract is
visible at the method site.

networking lifecycle: live.py and gossipsub/behavior.py carried both
_running (bool) and _stop_event (asyncio.Event) after PR leanEthereum#743. The
event already exposes is_set / wait / set / clear, which covers
every read and write the bool was doing. Dropped the bool in both
files; checks are now `not self._stop_event.is_set()` for "running"
and `self._stop_event.is_set()` for "stopped". The event default
stays a vanilla `asyncio.Event`; __post_init__ in each file forces
it to set (= stopped) so a fresh instance starts stopped until
dial/listen/start clears it. Updated __main__.py and node_runner.py
plus 6 affected unit tests.

storage/namespaces: five frozen dataclass classes whose only
contents were string defaults collapsed to plain `Final[str]`
module constants (BLOCKS_TABLE_NAME, BLOCKS_CREATE_TABLE,
BLOCKS_CREATE_INDEX, ...). 30+ attribute accesses in sqlite.py and
its import block rewritten.

xmss/tweak_hash: TreeTweak and ChainTweak were Pydantic
StrictBaseModel instances used only as packing structs feeding the
`match tweak` block in _encode_tweak. Converted both to
typing.NamedTuple. The match patterns keep working since
NamedTuple auto-populates __match_args__. The future-annotations
import that the audit flagged as R1 (banned in Pydantic-defining
files) goes away with the conversion since TreeTweak/ChainTweak
are no longer Pydantic; TweakHasher stays a StrictBaseModel.

xmss/constants: TWEAK_PREFIX_CHAIN, TWEAK_PREFIX_TREE,
TWEAK_PREFIX_MESSAGE were Fp(value=0x00..0x02) wrappers whose every
consumer immediately did `.value` to recover the int. Inlined as
plain Final[int]; dropped the unused Fp import and rewrote three
call sites plus one test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tcoratger tcoratger merged commit 6513aba into leanEthereum:main May 22, 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