Skip to content
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

Merged
merged 4 commits into from Jan 18, 2023

Conversation

Rjected
Copy link
Member

@Rjected Rjected commented Jan 18, 2023

This implements From<ethers_core::utils::Genesis> for ChainSpec and updates Hardfork. The fields on ChainSpec are also documented and set as pub.

The EIP-2481 test vector in test_decode_block_header is updated to check the header's hash.

Some questions / things left TODO:

  • Add Hardfork::MergeNetsplitBlock to Hardfork. The merge netsplit block is used in sepolia as a fork block, so it is used to calculate a forkid.
  • Determine what to do if eip_155_block and eip_158_block are both set and are different. Currently we just use the value of eip_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

 * implement From<ethers_core::utils::Genesis> for ChainSpec
 * update docs on forkid and hardfork
 * set ChainSpec fields as public
@Rjected Rjected requested a review from gakonst as a code owner January 18, 2023 18:29
 * 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-commenter
Copy link

Codecov Report

Merging #921 (db4aa3d) into main (aadc21c) will decrease coverage by 0.05%.
The diff coverage is 8.69%.

@@            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     
Flag Coverage Δ
unit-tests 73.99% <8.69%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
crates/primitives/src/chain_spec.rs 73.20% <0.00%> (-14.41%) ⬇️
crates/primitives/src/hardfork.rs 36.95% <100.00%> (+8.83%) ⬆️
crates/primitives/src/header.rs 94.48% <100.00%> (+0.10%) ⬆️
crates/transaction-pool/src/test_utils/mock.rs 53.11% <0.00%> (-6.60%) ⬇️
crates/transaction-pool/src/pool/txpool.rs 58.87% <0.00%> (-0.50%) ⬇️
crates/net/network/src/peers/manager.rs 83.24% <0.00%> (-0.19%) ⬇️
bin/reth/src/db/mod.rs 0.00% <0.00%> (ø)
bin/reth/src/node/mod.rs 0.00% <0.00%> (ø)
crates/primitives/src/storage.rs 100.00% <0.00%> (ø)
crates/storage/db/src/tables/mod.rs 0.00% <0.00%> (ø)
... and 10 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Rjected Rjected added C-enhancement New feature or request A-utils Related to commonly used utilities labels Jan 18, 2023
Copy link
Member

@gakonst gakonst left a 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

Comment on lines +204 to +217
// 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
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

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

SGTM - easy followup PR

Comment on lines -75 to -76
/// **CAUTION**: This assumes the current hardfork's block number is the current head and uses
/// all known future hardforks to initialize the filter.
Copy link
Member

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?

Copy link
Member Author

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**.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah please do

@gakonst gakonst merged commit 9ab244f into main Jan 18, 2023
@gakonst gakonst deleted the dan/genesis-to-chainspec branch January 18, 2023 21:14
literallymarvellous pushed a commit to literallymarvellous/reth that referenced this pull request Feb 5, 2023
literallymarvellous pushed a commit to literallymarvellous/reth that referenced this pull request Feb 5, 2023
literallymarvellous pushed a commit to literallymarvellous/reth that referenced this pull request Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-utils Related to commonly used utilities C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants