refactor(node): flatten genesis package and tidy config loader#1105
Merged
Conversation
The genesis package held a single module, so flatten it to node/genesis.py beside its consumer node/anchor.py. The chain package stays focused on consensus timing. Tidy the loader itself: - load the file with Path.read_text instead of an explicit handle - derive the hex pad width from the key length instead of a magic literal - bound the validator set before decoding keys (mode="before"), matching the memory-safety rationale the check claims - trim the documentation to the leanest form the rules allow Co-Authored-By: Claude Opus 4.8 (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
node/genesis/package held a single module (config.py) plus a re-export-only__init__.py— over-modularization for one small class. This flattens it to a flatnode/genesis.py, placed beside its actual consumernode/anchor.py. Thenode/chain/package stays focused purely on consensus timing (SlotClock,ChainService); a load-once config loader does not belong there.Because
lean_spec.node.genesisremains a valid import path, no import sites change. The test moves totests/node/test_genesis.pyto keep the test tree mirroring the source tree.Changes
src/lean_spec/node/genesis.py; delete the emptynode/genesis/andtests/node/genesis/packages.from_yaml_file: read the file withPath.read_text(...)instead of an explicit handle + context manager._yaml_int_to_hex: derive the hex pad width from the key length (Bytes52.LENGTH * 2) instead of a magic0104literal; rename the single-letter parameter._reject_oversized_validator_set: move tomode="before"so the bound is enforced before every XMSS key is decoded — the old post-validator ran after the decode, so it never delivered the memory-safety guarantee its docstring claimed.Raises:block → dropped, field/validator docstrings reduced to the single non-obvious fact each). Also align theproposal_public_keywording with the canonicalValidator("signs the block root").Testing
tests/node/test_genesis.py,test_anchor.py,tests/cli/test_run.py,tests/node/test_node.py).ruff check,ruff format --check, andty checkall pass.🤖 Generated with Claude Code