Skip to content

refactor(all): cleanup the APIs for initializing genesis #25473 #26747#2017

Merged
AnilChinchawale merged 2 commits intoXinFinOrg:dev-upgradefrom
gzliudan:rework-genesis
Feb 6, 2026
Merged

refactor(all): cleanup the APIs for initializing genesis #25473 #26747#2017
AnilChinchawale merged 2 commits intoXinFinOrg:dev-upgradefrom
gzliudan:rework-genesis

Conversation

@gzliudan
Copy link
Collaborator

@gzliudan gzliudan commented Jan 29, 2026

Proposed changes

Ref:

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Regular KTLO or any of the maintaince work. e.g code style
  • CICD Improvement

Impacted Components

Which part of the codebase this PR will touch base on,

Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

Copilot AI review requested due to automatic review settings January 29, 2026 18:39
@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request refactors the genesis initialization APIs to improve clarity and consistency. The main changes involve:

  1. Removing the database parameter from Genesis.ToBlock() method - it now only computes the block without persisting state
  2. Adding new helper functions deriveHash and flush to separate state root computation from state persistence
  3. Removing the deprecated GenesisBlockForTesting function
  4. Updating all test files to use the new APIs

Changes:

  • Refactored Genesis.ToBlock() to remove database parameter and only compute the genesis block
  • Added deriveHash() and flush() helper functions for state computation and persistence
  • Updated all test files to use MustCommit() instead of deprecated GenesisBlockForTesting()

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
core/genesis.go Core refactoring: added deriveHash/flush functions, updated ToBlock/Commit methods, removed GenesisBlockForTesting
core/rawdb/accessors_metadata.go Added WriteGenesisStateSpec function for persisting genesis state
tests/state_test_util.go Updated ToBlock() call to remove nil parameter
eth/tracers/api_test.go Reorganized Genesis struct field order
eth/helper_test.go Reorganized Genesis struct field order
eth/gasprice/gasprice_test.go Changed Commit to MustCommit
eth/filters/filter_test.go Replaced GenesisBlockForTesting with Genesis struct and MustCommit
eth/filters/filter_system_test.go Refactored genesis initialization pattern
eth/fetcher/fetcher_test.go Replaced GenesisBlockForTesting with Genesis struct and MustCommit
eth/downloader/testchain_test.go Replaced GenesisBlockForTesting with Genesis struct and MustCommit, added init function
eth/downloader/queue_test.go Removed duplicate variables, now using testDB and testGenesis from testchain_test.go
core/genesis_test.go Updated ToBlock() calls to remove nil parameter
core/dao_test.go Updated GenerateChain to use gspec.Config instead of hardcoded params.TestChainConfig
core/chain_makers.go Updated ToBlock() call in GenerateChainWithGenesis
core/blockchain_test.go Multiple updates: Genesis struct field reordering and Config usage
core/block_validator_test.go Updated GenerateChain and NewBlockChain to use gspec.Config
core/bench_test.go Removed Config field from Genesis initialization
cmd/evm/runner.go Changed ToBlock to MustCommit for proper state persistence
Comments suppressed due to low confidence (1)

eth/filters/filter_system_test.go:801

  • The Genesis struct is missing the Config field. Although Commit() will default to params.TestChainConfig internally, the genesis.Config field itself remains nil. When this genesis is passed to GenerateChainWithGenesis(), it will access genesis.Config on line 275 of chain_makers.go, which will be nil, causing issues. The Config field should be explicitly set to params.TestChainConfig.
		genesis = &core.Genesis{
			Alloc: types.GenesisAlloc{
				addr: {Balance: big.NewInt(params.Ether)},
			},
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gzliudan gzliudan changed the title all: cleanup the APIs for initializing genesis #25473 all: cleanup the APIs for initializing genesis #25473 #26747 Jan 30, 2026
@gzliudan gzliudan requested a review from Copilot January 30, 2026 01:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gzliudan gzliudan force-pushed the rework-genesis branch 4 times, most recently from e72a6bf to 97f1ec2 Compare January 30, 2026 08:51
@gzliudan gzliudan requested a review from Copilot January 30, 2026 08:52
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gzliudan gzliudan changed the title all: cleanup the APIs for initializing genesis #25473 #26747 refactor(all): cleanup the APIs for initializing genesis #25473 #26747 Feb 5, 2026
@AnilChinchawale AnilChinchawale merged commit e39a523 into XinFinOrg:dev-upgrade Feb 6, 2026
13 checks passed
@gzliudan gzliudan deleted the rework-genesis branch February 6, 2026 21:33
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.

5 participants