reth_ethereum_forks/hardforks/
ethereum.rs

1use alloy_primitives::U256;
2
3use crate::{hardforks::Hardforks, EthereumHardfork, ForkCondition};
4
5/// Helper methods for Ethereum forks.
6#[auto_impl::auto_impl(&, Arc)]
7pub trait EthereumHardforks: Hardforks {
8    /// Convenience method to check if [`EthereumHardfork::Shanghai`] is active at a given
9    /// timestamp.
10    fn is_shanghai_active_at_timestamp(&self, timestamp: u64) -> bool {
11        self.is_fork_active_at_timestamp(EthereumHardfork::Shanghai, timestamp)
12    }
13
14    /// Convenience method to check if [`EthereumHardfork::Cancun`] is active at a given timestamp.
15    fn is_cancun_active_at_timestamp(&self, timestamp: u64) -> bool {
16        self.is_fork_active_at_timestamp(EthereumHardfork::Cancun, timestamp)
17    }
18
19    /// Convenience method to check if [`EthereumHardfork::Prague`] is active at a given timestamp.
20    fn is_prague_active_at_timestamp(&self, timestamp: u64) -> bool {
21        self.is_fork_active_at_timestamp(EthereumHardfork::Prague, timestamp)
22    }
23
24    /// Convenience method to check if [`EthereumHardfork::Osaka`] is active at a given timestamp.
25    fn is_osaka_active_at_timestamp(&self, timestamp: u64) -> bool {
26        self.is_fork_active_at_timestamp(EthereumHardfork::Osaka, timestamp)
27    }
28
29    /// Convenience method to check if [`EthereumHardfork::Byzantium`] is active at a given block
30    /// number.
31    fn is_byzantium_active_at_block(&self, block_number: u64) -> bool {
32        self.fork(EthereumHardfork::Byzantium).active_at_block(block_number)
33    }
34
35    /// Convenience method to check if [`EthereumHardfork::SpuriousDragon`] is active at a given
36    /// block number.
37    fn is_spurious_dragon_active_at_block(&self, block_number: u64) -> bool {
38        self.fork(EthereumHardfork::SpuriousDragon).active_at_block(block_number)
39    }
40
41    /// Convenience method to check if [`EthereumHardfork::Homestead`] is active at a given block
42    /// number.
43    fn is_homestead_active_at_block(&self, block_number: u64) -> bool {
44        self.fork(EthereumHardfork::Homestead).active_at_block(block_number)
45    }
46
47    /// The Paris hardfork (merge) is activated via block number. If we have knowledge of the block,
48    /// this function will return true if the block number is greater than or equal to the Paris
49    /// (merge) block.
50    fn is_paris_active_at_block(&self, block_number: u64) -> Option<bool> {
51        match self.fork(EthereumHardfork::Paris) {
52            ForkCondition::Block(paris_block) => Some(block_number >= paris_block),
53            ForkCondition::TTD { fork_block, .. } => {
54                fork_block.map(|paris_block| block_number >= paris_block)
55            }
56            _ => None,
57        }
58    }
59
60    /// Returns the final total difficulty if the Paris hardfork is known.
61    fn get_final_paris_total_difficulty(&self) -> Option<U256>;
62
63    /// Returns the final total difficulty if the given block number is after the Paris hardfork.
64    ///
65    /// Note: technically this would also be valid for the block before the paris upgrade, but this
66    /// edge case is omitted here.
67    fn final_paris_total_difficulty(&self, block_number: u64) -> Option<U256>;
68}