-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(primitives): impl From<Genesis> for ChainSpec #921
Conversation
* implement From<ethers_core::utils::Genesis> for ChainSpec * update docs on forkid and hardfork * set ChainSpec fields as public
* remove Hardfork::all_forks as it's unused
* The merge netsplit block was set by geth here: ethereum/go-ethereum#25372 because of the "block" suffix, the field is pulled to create a forkid in geth's gatherBlocks method
Codecov Report
@@ Coverage Diff @@
## main #921 +/- ##
==========================================
- Coverage 74.04% 73.99% -0.05%
==========================================
Files 288 292 +4
Lines 30783 31719 +936
==========================================
+ Hits 22792 23471 +679
- Misses 7991 8248 +257
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 Qs, but merging LGTM and can address in followup
// TODO: eip-158 was also activated when eip-155 was activated, but we don't have the | ||
// proper hardfork identifier for it. this breaks the hardfork abstraction slightly | ||
(Hardfork::SpuriousDragon, genesis.config.eip155_block), | ||
(Hardfork::Byzantium, genesis.config.byzantium_block), | ||
(Hardfork::Constantinople, genesis.config.constantinople_block), | ||
(Hardfork::Petersburg, genesis.config.petersburg_block), | ||
(Hardfork::Istanbul, genesis.config.istanbul_block), | ||
(Hardfork::Muirglacier, genesis.config.muir_glacier_block), | ||
(Hardfork::Berlin, genesis.config.berlin_block), | ||
(Hardfork::London, genesis.config.london_block), | ||
(Hardfork::ArrowGlacier, genesis.config.arrow_glacier_block), | ||
(Hardfork::GrayGlacier, genesis.config.gray_glacier_block), | ||
// TODO: similar problem as eip-158, but with the merge netsplit block. only used in | ||
// sepolia, but required for proper forkid generation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the fix here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first TODO:
Using Hardfork::Tangerine
works for mainnet because 155/158 were both activated in tangerine, to fix this for an arbitrary genesis we might want to split Hardfork::Tangerine
into:
Hardfork::Eip150,
Hardfork::Eip158,
The second TODO:
I actually added Hardfork::MergeNetsplit
, so we just need to add
(Hardfork::MergeNetsplit, genesis.config.merge_netsplit_block),
and delete the TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM - easy followup PR
/// **CAUTION**: This assumes the current hardfork's block number is the current head and uses | ||
/// all known future hardforks to initialize the filter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this no longer the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior is consistent with the comment, but the caution is probably not warranted because we are explicitly passing in a ChainSpec
. Before #747, the signature was:
pub fn fork_filter(&self) -> ForkFilter
which is not explicit as to what future fork blocks are used to initialize the ForkFilter
, hence the caution.
So maybe the comment should be added back, but without the **CAUTION**
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah please do
This implements
From<ethers_core::utils::Genesis> for ChainSpec
and updatesHardfork
. The fields onChainSpec
are also documented and set aspub
.The EIP-2481 test vector in
test_decode_block_header
is updated to check the header's hash.Some questions / things left TODO:
Hardfork::MergeNetsplitBlock
toHardfork
. The merge netsplit block is used in sepolia as a fork block, so it is used to calculate a forkid.eip_155_block
andeip_158_block
are both set and are different. Currently we just use the value ofeip_155_block
. Situations where EIP155 and EIP158 are both set, but on different fork blocks, seem rare. So maybe the current behavior is ok?Extracted from #623