Skip to content

Commit

Permalink
calculate state root when converting chainspec
Browse files Browse the repository at this point in the history
 * this will be unnecessary when the `state_root` field is removed from
   `Genesis` and we calculate the genesis state root from its
   `GenesisAlloc`s
  • Loading branch information
Rjected committed Jan 13, 2023
1 parent 8f4f0a1 commit 2b0e05d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions crates/tests/src/clique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ use std::collections::HashMap;
/// Converts an ethers [`Genesis`] into a reth
/// [`ChainSpecification`](reth_cli_utils::chainspec::ChainSpecification).
pub(crate) fn genesis_to_chainspec(genesis: &Genesis) -> ChainSpecification {
let alloc = genesis
.alloc
.iter()
.map(|(addr, account)| (addr.0.into(), convert_genesis_account(account)))
.collect::<HashMap<H160, _>>();

ChainSpecification {
consensus: ConsensusConfig {
chain_id: genesis.config.chain_id,
Expand All @@ -37,7 +43,7 @@ pub(crate) fn genesis_to_chainspec(genesis: &Genesis) -> ChainSpecification {
.terminal_total_difficulty
.unwrap_or_default()
.as_u128(),
..Default::default() // TODO: remove paris block as the hard fork is determined by ttd?
..Default::default() // TODO: remove paris block then remove this
},
genesis: RethGenesis {
nonce: genesis.nonce.as_u64(),
Expand All @@ -46,14 +52,9 @@ pub(crate) fn genesis_to_chainspec(genesis: &Genesis) -> ChainSpecification {
difficulty: genesis.difficulty.into(),
mix_hash: genesis.mix_hash.0.into(),
coinbase: genesis.coinbase.0.into(),
// state_root: genesis.state_root, TODO: remove state_root from genesis
alloc: genesis
.alloc
.iter()
.map(|(addr, account)| (addr.0.into(), convert_genesis_account(account)))
.collect::<HashMap<H160, _>>(),
state_root: genesis_state_root(alloc.clone()),
extra_data: genesis.extra_data.0.clone().into(),
..Default::default()
alloc,
},
}
}
Expand Down

0 comments on commit 2b0e05d

Please sign in to comment.