Skip to content

refactor: drop Container.to_hex and write-only validator lag counters#760

Open
tcoratger wants to merge 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/audit-delete-batch
Open

refactor: drop Container.to_hex and write-only validator lag counters#760
tcoratger wants to merge 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/audit-delete-batch

Conversation

@tcoratger
Copy link
Copy Markdown
Collaborator

Summary

Two audit-delete items.

types/container.pyContainer.to_hex removed

Only one production caller (xmss/containers.py:162 inside the JSON field serializer). Inlined to value.encode_bytes().hex() at that site; eleven test sites in test_containers.py rewritten the same way. from_hex stays — it has two production callers in the same file.

subspecs/validator/service.py — write-only lag counters removed

_blocks_skipped_lag and _attestations_skipped_lag were incremented in the duty loop but never read in production. Their public property wrappers retired in PR #757; the audit's expose-vs-delete question lands on delete because there's no metrics surface for them. The _duty_gate_closed flag stays — it's a real state-machine reader.

Test impact:

  • test_counters_split_block_and_attestation retires with the counters (its entire purpose was the gate-doesn't-move-counters invariant).
  • The two test_run_loop_skips_* tests keep their block_calls == [] / attest_calls == [] assertions, which verify the actual behaviour; the counter-equality assertions retire.

Skipped audit items (with reasons)

# Item Reason
2 IntFieldElement + JSON branch "Fold into serializer" still requires giving Fp a Pydantic core schema with a plain serializer. Same conclusion as PR #757 — deferred.
3 _htr_bytes/bytearray/memoryview overloads Load-bearing: PR #757 fixup showed the consensus fixture pipeline traverses raw bytes fields inside containers. Deleting them broke 84 fixture tests.
4 _NullObserver + public re-export Already done in PR #757 — class is _NullObserver and no longer in subspecs/observability/__init__.py.
6 12 Spec*Type Protocols Vetoed in PR #757 — they're documentation labels distinguishing block-body from block-header from aggregated-attestations etc. Collapsing erases type intent.
7 QUIC _buffered_events Race is still real on the client path: connect() awaits the handshake event, then yields before protocol.connection = conn during which more events can arrive. The server already uses _on_handshake to assign the wrapper synchronously; the client doesn't. Removing the buffer is the architectural refactor deferred in PR #756.

Test plan

  • ruff check, ruff format --check, ty check — all clean.
  • uv run pytest tests/lean_spec/subspecs/xmss/test_containers.py tests/lean_spec/subspecs/validator/test_service.py — 71 tests pass.
  • uv run fill tests/consensus/lstar/fc/test_tick_system.py::test_tick_interval_progression_through_full_slot --fork=Lstar — 1 passed in 9.16s.

🤖 Generated with Claude Code

Two more audit deletes.

types/container.py: Container.to_hex had one production caller in
xmss/containers.py inside the JSON field serializer; that single
call inlines to value.encode_bytes().hex(). Eleven test sites in
test_containers.py rewritten the same way. from_hex stays — two
production callers depend on it.

validator/service.py: _blocks_skipped_lag and
_attestations_skipped_lag were write-only counters incremented in
the duty loop and never read in production. Their public properties
already left in an earlier pass, and the audit's expose-vs-delete
question lands on delete since there is no metrics surface for them.
The _duty_gate_closed flag stays — it is a real state-machine
reader. The dedicated test_counters_split_block_and_attestation
retires with the counters; the two run-loop tests keep their
block_calls / attest_calls assertions, which are the actual
behavioural checks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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