mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-30 09:38:24 -05:00
fix(chain_spec): Set correct paris block and chain difficulty (#7111)
Signed-off-by: Danil <deniallugo@gmail.com>
This commit is contained in:
@@ -890,15 +890,20 @@ impl From<Genesis> for ChainSpec {
|
||||
.collect::<BTreeMap<_, _>>();
|
||||
|
||||
// Paris
|
||||
if let Some(ttd) = genesis.config.terminal_total_difficulty {
|
||||
hardforks.insert(
|
||||
Hardfork::Paris,
|
||||
ForkCondition::TTD {
|
||||
total_difficulty: ttd,
|
||||
fork_block: genesis.config.merge_netsplit_block,
|
||||
},
|
||||
);
|
||||
}
|
||||
let paris_block_and_final_difficulty =
|
||||
if let Some(ttd) = genesis.config.terminal_total_difficulty {
|
||||
hardforks.insert(
|
||||
Hardfork::Paris,
|
||||
ForkCondition::TTD {
|
||||
total_difficulty: ttd,
|
||||
fork_block: genesis.config.merge_netsplit_block,
|
||||
},
|
||||
);
|
||||
|
||||
genesis.config.merge_netsplit_block.map(|block| (block, ttd))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Time-based hardforks
|
||||
let time_hardfork_opts = [
|
||||
@@ -921,7 +926,7 @@ impl From<Genesis> for ChainSpec {
|
||||
genesis_hash: None,
|
||||
fork_timestamps: ForkTimestamps::from_hardforks(&hardforks),
|
||||
hardforks,
|
||||
paris_block_and_final_difficulty: None,
|
||||
paris_block_and_final_difficulty,
|
||||
deposit_contract: None,
|
||||
..Default::default()
|
||||
}
|
||||
@@ -1229,13 +1234,22 @@ impl ChainSpecBuilder {
|
||||
/// This function panics if the chain ID and genesis is not set ([`Self::chain`] and
|
||||
/// [`Self::genesis`])
|
||||
pub fn build(self) -> ChainSpec {
|
||||
let paris_block_and_final_difficulty = {
|
||||
self.hardforks.get(&Hardfork::Paris).and_then(|cond| {
|
||||
if let ForkCondition::TTD { fork_block, total_difficulty } = cond {
|
||||
fork_block.map(|fork_block| (fork_block, *total_difficulty))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
};
|
||||
ChainSpec {
|
||||
chain: self.chain.expect("The chain is required"),
|
||||
genesis: self.genesis.expect("The genesis is required"),
|
||||
genesis_hash: None,
|
||||
fork_timestamps: ForkTimestamps::from_hardforks(&self.hardforks),
|
||||
hardforks: self.hardforks,
|
||||
paris_block_and_final_difficulty: None,
|
||||
paris_block_and_final_difficulty,
|
||||
deposit_contract: None,
|
||||
..Default::default()
|
||||
}
|
||||
@@ -2833,6 +2847,8 @@ Post-merge hard forks (timestamp based):
|
||||
|
||||
// check that they're the same
|
||||
assert_eq!(got_forkid, expected_forkid);
|
||||
// Check that paris block and final difficulty are set correctly
|
||||
assert_eq!(chainspec.paris_block_and_final_difficulty, Some((72, U256::from(9454784))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2881,6 +2897,17 @@ Post-merge hard forks (timestamp based):
|
||||
assert_eq!(genesis.config.cancun_time, Some(4661));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_paris_block_and_total_difficulty() {
|
||||
let genesis = Genesis { gas_limit: 0x2fefd8u64, ..Default::default() };
|
||||
let paris_chainspec = ChainSpecBuilder::default()
|
||||
.chain(Chain::from_id(1337))
|
||||
.genesis(genesis)
|
||||
.paris_activated()
|
||||
.build();
|
||||
assert_eq!(paris_chainspec.paris_block_and_final_difficulty, Some((0, U256::ZERO)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_cancun_header_forkhash() {
|
||||
// set the gas limit from the hive test genesis according to the hash
|
||||
|
||||
Reference in New Issue
Block a user