mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add constants for total paris difficulty (#2901)
This commit is contained in:
@ -20,6 +20,11 @@ pub static MAINNET: Lazy<ChainSpec> = Lazy::new(|| ChainSpec {
|
||||
genesis_hash: Some(H256(hex!(
|
||||
"d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
|
||||
))),
|
||||
// <https://etherscan.io/block/15537394>
|
||||
paris_block_and_final_difficulty: Some((
|
||||
15537394,
|
||||
U256::from(58_750_003_716_598_352_816_469u128),
|
||||
)),
|
||||
fork_timestamps: ForkTimestamps::default().shanghai(1681338455),
|
||||
hardforks: BTreeMap::from([
|
||||
(Hardfork::Frontier, ForkCondition::Block(0)),
|
||||
@ -55,6 +60,8 @@ pub static GOERLI: Lazy<ChainSpec> = Lazy::new(|| ChainSpec {
|
||||
genesis_hash: Some(H256(hex!(
|
||||
"bf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a"
|
||||
))),
|
||||
// <https://goerli.etherscan.io/block/7382818>
|
||||
paris_block_and_final_difficulty: Some((7382818, U256::from(10_790_000))),
|
||||
fork_timestamps: ForkTimestamps::default().shanghai(1678832736),
|
||||
hardforks: BTreeMap::from([
|
||||
(Hardfork::Frontier, ForkCondition::Block(0)),
|
||||
@ -84,6 +91,8 @@ pub static SEPOLIA: Lazy<ChainSpec> = Lazy::new(|| ChainSpec {
|
||||
genesis_hash: Some(H256(hex!(
|
||||
"25a5cc106eea7138acab33231d7160d69cb777ee0c2c553fcddf5138993e6dd9"
|
||||
))),
|
||||
// <https://sepolia.etherscan.io/block/1450409>
|
||||
paris_block_and_final_difficulty: Some((1450409, U256::from(17_000_018_015_853_232u128))),
|
||||
fork_timestamps: ForkTimestamps::default().shanghai(1677557088),
|
||||
hardforks: BTreeMap::from([
|
||||
(Hardfork::Frontier, ForkCondition::Block(0)),
|
||||
@ -131,6 +140,10 @@ pub struct ChainSpec {
|
||||
/// The genesis block
|
||||
pub genesis: Genesis,
|
||||
|
||||
/// The block at which [Hardfork::Paris] was activated and the final difficulty at this block.
|
||||
#[serde(skip, default)]
|
||||
pub paris_block_and_final_difficulty: Option<(u64, U256)>,
|
||||
|
||||
/// Timestamps of various hardforks
|
||||
///
|
||||
/// This caches entries in `hardforks` map
|
||||
@ -195,6 +208,20 @@ impl ChainSpec {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the final difficulty if the given block number is after the Paris hardfork.
|
||||
///
|
||||
/// Note: technically this would also be valid for the block before the paris upgrade, but this
|
||||
/// edge case is omitted here.
|
||||
pub fn final_paris_difficulty(&self, block_number: u64) -> Option<U256> {
|
||||
self.paris_block_and_final_difficulty.and_then(|(activated_at, final_difficulty)| {
|
||||
if block_number >= activated_at {
|
||||
Some(final_difficulty)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the forks in this specification and their activation conditions.
|
||||
pub fn hardforks(&self) -> &BTreeMap<Hardfork, ForkCondition> {
|
||||
&self.hardforks
|
||||
@ -339,6 +366,7 @@ impl From<EthersGenesis> for ChainSpec {
|
||||
genesis_hash: None,
|
||||
fork_timestamps: ForkTimestamps::from_hardforks(&hardforks),
|
||||
hardforks,
|
||||
paris_block_and_final_difficulty: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -536,6 +564,7 @@ impl ChainSpecBuilder {
|
||||
genesis_hash: None,
|
||||
fork_timestamps: ForkTimestamps::from_hardforks(&self.hardforks),
|
||||
hardforks: self.hardforks,
|
||||
paris_block_and_final_difficulty: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,6 +159,7 @@ mod tests {
|
||||
genesis_hash: None,
|
||||
hardforks: BTreeMap::from([(Hardfork::Frontier, ForkCondition::Never)]),
|
||||
fork_timestamps: Default::default(),
|
||||
paris_block_and_final_difficulty: None,
|
||||
};
|
||||
|
||||
assert_eq!(Hardfork::Frontier.fork_id(&spec), None);
|
||||
@ -172,6 +173,7 @@ mod tests {
|
||||
genesis_hash: None,
|
||||
hardforks: BTreeMap::from([(Hardfork::Shanghai, ForkCondition::Never)]),
|
||||
fork_timestamps: Default::default(),
|
||||
paris_block_and_final_difficulty: None,
|
||||
};
|
||||
|
||||
assert_eq!(Hardfork::Shanghai.fork_filter(&spec), None);
|
||||
|
||||
Reference in New Issue
Block a user