mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: calc block base reward use block number only (#8876)
Signed-off-by: jsvisa <delweng@gmail.com> Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -853,6 +853,13 @@ impl ChainSpec {
|
||||
self.fork(Hardfork::Homestead).active_at_block(block_number)
|
||||
}
|
||||
|
||||
/// The Paris hardfork (merge) is activated via ttd. If we have knowledge of the block, this
|
||||
/// function will return true if the block number is greater than or equal to the Paris
|
||||
/// (merge) block.
|
||||
pub fn is_paris_active_at_block(&self, block_number: u64) -> Option<bool> {
|
||||
self.paris_block_and_final_difficulty.map(|(paris_block, _)| block_number >= paris_block)
|
||||
}
|
||||
|
||||
/// Convenience method to check if [`Hardfork::Bedrock`] is active at a given block number.
|
||||
#[cfg(feature = "optimism")]
|
||||
#[inline]
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
use reth_chainspec::{Chain, ChainSpec, Hardfork};
|
||||
use reth_primitives::{constants::ETH_TO_WEI, BlockNumber, U256};
|
||||
|
||||
/// Calculates the base block reward.
|
||||
///
|
||||
/// The base block reward is defined as:
|
||||
@ -25,16 +26,25 @@ pub fn base_block_reward(
|
||||
block_difficulty: U256,
|
||||
total_difficulty: U256,
|
||||
) -> Option<u128> {
|
||||
if chain_spec.chain == Chain::goerli() ||
|
||||
chain_spec.fork(Hardfork::Paris).active_at_ttd(total_difficulty, block_difficulty)
|
||||
if chain_spec.fork(Hardfork::Paris).active_at_ttd(total_difficulty, block_difficulty) ||
|
||||
chain_spec.chain == Chain::goerli()
|
||||
{
|
||||
None
|
||||
} else if chain_spec.fork(Hardfork::Constantinople).active_at_block(block_number) {
|
||||
Some(ETH_TO_WEI * 2)
|
||||
} else if chain_spec.fork(Hardfork::Byzantium).active_at_block(block_number) {
|
||||
Some(ETH_TO_WEI * 3)
|
||||
} else {
|
||||
Some(ETH_TO_WEI * 5)
|
||||
Some(base_block_reward_pre_merge(chain_spec, block_number))
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculates the base block reward __before__ the merge (Paris hardfork).
|
||||
///
|
||||
/// Caution: The caller must ensure that the block number is before the merge.
|
||||
pub fn base_block_reward_pre_merge(chain_spec: &ChainSpec, block_number: BlockNumber) -> u128 {
|
||||
if chain_spec.fork(Hardfork::Constantinople).active_at_block(block_number) {
|
||||
ETH_TO_WEI * 2
|
||||
} else if chain_spec.fork(Hardfork::Byzantium).active_at_block(block_number) {
|
||||
ETH_TO_WEI * 3
|
||||
} else {
|
||||
ETH_TO_WEI * 5
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user