Skip to content

refactor: align genesis construction with Ethereum's decodePrealloc pattern#69

Merged
0xmhha merged 5 commits intodevfrom
feat/sync-genesis-with-ethereum
Apr 3, 2026
Merged

refactor: align genesis construction with Ethereum's decodePrealloc pattern#69
0xmhha merged 5 commits intodevfrom
feat/sync-genesis-with-ethereum

Conversation

@0xmhha
Copy link
Copy Markdown
Member

@0xmhha 0xmhha commented Mar 30, 2026

Background

StableNet's genesis block construction had diverged from upstream Ethereum's approach. The mainnet and testnet genesis functions used json.NewDecoder to parse JSON at runtime, which differs from Ethereum's compile-time decodePrealloc pattern. 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)

  • Replace JSON-based genesis decoding with Ethereum's decodePrealloc pattern in DefaultStableNetMainnetGenesisBlock() and DefaultStableNetTestnetGenesisBlock().
  • Eliminates runtime JSON parsing and removes panic-on-decode-failure paths.

2. Genesis alloc consistency test

  • Add a test that verifies JSON genesis data and decodePrealloc output produce identical alloc results.
  • Catches alloc mismatches between the two approaches early.

3. Extract genesis JSON into standalone files

  • Move embedded genesis JSON data from Go source into standalone files (genesis_mainnet.json, genesis_testnet.json).
  • Improves readability, maintainability, and produces cleaner diffs when genesis data changes.

Commits

  • refactor: use decodePrealloc for StableNet genesis block construction
  • test: add genesis alloc consistency test for JSON vs decodePrealloc
  • refactor: extract genesis JSON from Go source into standalone files

Test plan

  • core/genesis_test.go — JSON vs decodePrealloc alloc consistency test
  • Verify devp2p ethtest suite passes with updated genesis
  • Verify node syncs correctly on testnet with updated genesis

@0xmhha 0xmhha changed the title feat: sync genesis construction with Ethereum and unify hardfork upgrade system [WIP] feat: sync genesis construction with Ethereum and unify hardfork upgrade system Mar 30, 2026
@0xmhha 0xmhha marked this pull request as draft March 30, 2026 05:40
@0xmhha 0xmhha self-assigned this Mar 30, 2026
@0xmhha 0xmhha added the enhancement New feature or request label Mar 30, 2026
Copy link
Copy Markdown
Collaborator

@hominlee-wemade hominlee-wemade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

0xmhha added 3 commits April 2, 2026 17:22
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.
@0xmhha 0xmhha force-pushed the feat/sync-genesis-with-ethereum branch from 731e2fd to 878442f Compare April 2, 2026 08:23
@0xmhha 0xmhha changed the title [WIP] feat: sync genesis construction with Ethereum and unify hardfork upgrade system refactor: align genesis construction with Ethereum's decodePrealloc pattern Apr 2, 2026
@0xmhha 0xmhha requested review from colinkim and eomti-wm April 2, 2026 08:55
@0xmhha 0xmhha marked this pull request as ready for review April 2, 2026 08:55
Copy link
Copy Markdown
Contributor

@eomti-wm eomti-wm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@colinkim colinkim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@0xmhha 0xmhha merged commit aa28927 into dev Apr 3, 2026
3 checks passed
@hominlee-wemade hominlee-wemade deleted the feat/sync-genesis-with-ethereum branch April 9, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants