refactor: align genesis construction with Ethereum's decodePrealloc pattern#69
Merged
refactor: align genesis construction with Ethereum's decodePrealloc pattern#69
Conversation
Replace JSON-based genesis decoding with Ethereum's decodePrealloc pattern for mainnet and testnet genesis blocks. Regenerate devp2p ethtest testdata to reflect the updated genesis configuration.
Add TestStableNetGenesisAllocConsistency to verify that the decodePrealloc-based genesis construction (with InjectContracts) produces the same alloc as the canonical JSON literals in stablenet_genesis.go. This keeps the JSON reference in use and prevents unused variable lint errors.
Move stableNetMainnetGenesisJson and stableNetTestnetGenesisJson from core/stablenet_genesis.go into core/genesis_mainnet.json and core/genesis_testnet.json. This allows direct use with mkalloc.go and removes large string literals from the compiled binary. Update TestStableNetGenesisAllocConsistency to read from the JSON files via os.ReadFile.
731e2fd to
878442f
Compare
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.
Background
StableNet's genesis block construction had diverged from upstream Ethereum's approach. The mainnet and testnet genesis functions used
json.NewDecoderto parse JSON at runtime, which differs from Ethereum's compile-timedecodePreallocpattern. This divergence made it harder to track upstream changes, introduced runtime overhead, and created unnecessary panic-on-decode-failure paths.What this PR does
1. Align genesis construction with Ethereum (
decodePrealloc)decodePreallocpattern inDefaultStableNetMainnetGenesisBlock()andDefaultStableNetTestnetGenesisBlock().2. Genesis alloc consistency test
decodePreallocoutput produce identical alloc results.3. Extract genesis JSON into standalone files
genesis_mainnet.json,genesis_testnet.json).Commits
refactor: use decodePrealloc for StableNet genesis block constructiontest: add genesis alloc consistency test for JSON vs decodePreallocrefactor: extract genesis JSON from Go source into standalone filesTest plan
core/genesis_test.go— JSON vs decodePrealloc alloc consistency test