-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ethereum-forks): remove total difficulty for hardfork check #13362
Conversation
aroralanuk
commented
Dec 12, 2024
•
edited
Loading
edited
- fixes Remove extra Total difficulty argument for execution #13174
@mattsse, is this how you were thinking of removing total difficulty and relying solely on the block number (given Paris is always the merge fork)? |
/// The fork is activated after a total difficulty has been reached. | ||
TTD { | ||
/// The block number at which TTD is reached, if it is known. | ||
/// | ||
/// This should **NOT** be set unless you want this block advertised as [EIP-2124][eip2124] | ||
/// `FORK_NEXT`. This is currently only the case for Sepolia and Holesky. | ||
/// | ||
/// [eip2124]: https://eips.ethereum.org/EIPS/eip-2124 | ||
fork_block: Option<BlockNumber>, | ||
/// The total difficulty after which the fork is activated. | ||
total_difficulty: U256, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, this has implications on the forkid.
I think the way we should go about this is keeping this variant but requiring that it knows the block number
@Rjected @joshieDo I can't remember what the implications of the fork_block
field are because we set this.
I think we can't just set the fork_block
field because this messes with the forkid, for example for mainnet we must set this to none,
so to enforce a block number for ttd we should add a new field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we need to keep one eip-2124 fork block at least. We would want another blocknum field, that is used for checking if the merge is active, but not for the forkid.
@aroralanuk so the way we should solve this is, we keep the |
crates/chainspec/src/spec.rs
Outdated
@@ -607,6 +607,7 @@ impl From<Genesis> for ChainSpec { | |||
hardforks.push(( | |||
EthereumHardfork::Paris.boxed(), | |||
ForkCondition::TTD { | |||
activation_block_number: genesis.config.merge_netsplit_block.expect("Merge netsplit block is required"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crates/consensus/common/src/calc.rs
Outdated
) -> Option<u128> { | ||
if chain_spec.fork(EthereumHardfork::Paris).active_at_ttd(total_difficulty, block_difficulty) { | ||
if chain_spec.fork(EthereumHardfork::Paris).active_at_ttd(block_number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should I keep the active_at_ttd function as it is and add a new active_at_merge method instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep this for now to keept changes small
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, this looks good overall,
just need some additional time to take a closer look
if !self | ||
.externals | ||
.provider_factory | ||
.chain_spec() | ||
.fork(EthereumHardfork::Paris) | ||
.active_at_ttd(parent_td, U256::ZERO) | ||
.active_at_ttd(block.number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should use the parent block number
crates/consensus/common/src/calc.rs
Outdated
) -> Option<u128> { | ||
if chain_spec.fork(EthereumHardfork::Paris).active_at_ttd(total_difficulty, block_difficulty) { | ||
if chain_spec.fork(EthereumHardfork::Paris).active_at_ttd(block_number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep this for now to keept changes small
not sure how much is related but would be great to remove ttd from the response in the block looks like execution api ratified that and geth recently implemented (seen some slow rollout these days by rpc providers) |
thanks @Rjected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amazing, this also unlocks a few nice followups
/// The activation block number for the fork. | ||
activation_block_number: BlockNumber, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a one liner that this is mandatory because we expect that all difficulty hardforks are finalized and total difficulty is deprecated?
&Head { | ||
number: header.number, | ||
timestamp: header.timestamp, | ||
difficulty: header.difficulty, | ||
total_difficulty, | ||
// NOTE: this does nothing within revm_spec | ||
total_difficulty: U256::MIN, | ||
hash: Default::default(), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can simplify this a lot in a followup because we only need number+timstamp now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so much better lol
@@ -27,8 +26,6 @@ where | |||
if let Some(base_block_reward) = calc::base_block_reward( | |||
chain_spec, | |||
block.header().number(), | |||
block.header().difficulty(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
@@ -110,8 +110,8 @@ where | |||
/// Configures a new evm configuration and block environment for the given block. | |||
/// | |||
/// Caution: this does not initialize the tx environment. | |||
fn evm_env_for_block(&self, header: &Header, total_difficulty: U256) -> EnvWithHandlerCfg { | |||
let (cfg, block_env) = self.evm_config.cfg_and_block_env(header, total_difficulty); | |||
fn evm_env_for_block(&self, header: &Header) -> EnvWithHandlerCfg { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so good
.header_td_by_number(header.number())? | ||
.ok_or_else(|| ProviderError::HeaderNotFound(header.number().into()))?; | ||
Ok(evm_config.cfg_and_block_env(header, total_difficulty)) | ||
Ok(evm_config.cfg_and_block_env(header)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can also get rid of this provider trait entirely now
note that we will have a bit of redundancy in:
So we can probably simplify even more things w.r.t our hardfork traits / structs |
51b6ad5
to
171537d
Compare
1898bba
to
0650773
Compare
CodSpeed Performance ReportMerging #13362 will degrade performances by 10.82%Comparing Summary
Benchmarks breakdown
|