refactor(all): cleanup the APIs for initializing genesis #25473 #26747#2017
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This pull request refactors the genesis initialization APIs to improve clarity and consistency. The main changes involve:
- Removing the database parameter from
Genesis.ToBlock()method - it now only computes the block without persisting state - Adding new helper functions
deriveHashandflushto separate state root computation from state persistence - Removing the deprecated
GenesisBlockForTestingfunction - 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()andflush()helper functions for state computation and persistence - Updated all test files to use
MustCommit()instead of deprecatedGenesisBlockForTesting()
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.
a9f7160 to
a390287
Compare
There was a problem hiding this comment.
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.
a390287 to
a910062
Compare
There was a problem hiding this comment.
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.
e72a6bf to
97f1ec2
Compare
There was a problem hiding this comment.
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.
97f1ec2 to
fcaba6f
Compare
Proposed changes
Ref:
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which part of the codebase this PR will touch base on,
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that