Skip to content

refactor(testing): hoist codec dispatch tables out of run() - #911

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/hoist-codec-dispatch-dicts
Jun 10, 2026
Merged

refactor(testing): hoist codec dispatch tables out of run()#911
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:refactor/hoist-codec-dispatch-dicts

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

Motivation

Two networking-codec fixtures rebuilt a constant lookup table on every run() / attempt_decode() call:

  • PeerIdentifierDerivation rebuilt a {str: KeyType} map each call — doubly redundant, since the key_type literal values already match the KeyType enum member names once upper-cased.
  • DecodeFailure rebuilt its {str: decoder} table each call.

What this does

  • Drops the peer-id map entirely: KeyType[self.key_type.upper()] looks the member up by name ("ed25519"KeyType.ED25519, etc.).
  • Hoists the decoder table to a module-level Final constant (_DECODERS_BY_NAME), built once at import.

Byte-equivalence

The KeyType enum lookup yields the same members as the old map, and the decoder table holds the same callables. Verified by filling the networking suite before and after:

141 passed
diff -rq <golden> <new>  ->  IDENTICAL: no vector churn

Testing

  • just check passes (lint, format, ty, codespell, mdformat).
  • All 141 tests/consensus/lstar/networking vectors are byte-identical to the pre-change output.

🤖 Generated with Claude Code

Two codec fixtures rebuilt a constant lookup table on every call.

The peer-identifier fixture rebuilt a string-to-enum map each run, even
though the literal key-type values already match the enum member names.
Look the member up directly by name instead, dropping the map.

The decode-failure fixture rebuilt its decoder table each call.
Hoist it to a module-level constant so it is built once.

Both fixtures emit byte-identical vectors: the enum lookup yields the same
members as the map, and the decoder table holds the same callables.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tcoratger
tcoratger merged commit d85d9e5 into leanEthereum:main Jun 10, 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