Skip to content
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

split validate_block_pre_execution into hardfork specific functions #10568

Closed
mattsse opened this issue Aug 27, 2024 · 1 comment · Fixed by #10576
Closed

split validate_block_pre_execution into hardfork specific functions #10568

mattsse opened this issue Aug 27, 2024 · 1 comment · Fixed by #10576
Assignees
Labels
C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started

Comments

@mattsse
Copy link
Collaborator

mattsse commented Aug 27, 2024

Describe the feature

we currently apply all checks in a single function

/// Validate a block without regard for state:
///
/// - Compares the ommer hash in the block header to the block body
/// - Compares the transactions root in the block header to the block body
/// - Pre-execution transaction validation
/// - (Optionally) Compares the receipts root in the block header to the block body
pub fn validate_block_pre_execution(
block: &SealedBlock,
chain_spec: &ChainSpec,
) -> Result<(), ConsensusError> {

ideally all those hardfork checks are available as function and validate_block_pre_execution would then call all of them

TODO

  • extract hardfork checks into separate functions:

// EIP-4895: Beacon chain push withdrawals as operations
if chain_spec.is_shanghai_active_at_timestamp(block.timestamp) {
let withdrawals =
block.withdrawals.as_ref().ok_or(ConsensusError::BodyWithdrawalsMissing)?;
let withdrawals_root = reth_primitives::proofs::calculate_withdrawals_root(withdrawals);
let header_withdrawals_root =
block.withdrawals_root.as_ref().ok_or(ConsensusError::WithdrawalsRootMissing)?;
if withdrawals_root != *header_withdrawals_root {
return Err(ConsensusError::BodyWithdrawalsRootDiff(
GotExpected { got: withdrawals_root, expected: *header_withdrawals_root }.into(),
))
}
}
// EIP-4844: Shard Blob Transactions
if chain_spec.is_cancun_active_at_timestamp(block.timestamp) {
// Check that the blob gas used in the header matches the sum of the blob gas used by each
// blob tx
let header_blob_gas_used = block.blob_gas_used.ok_or(ConsensusError::BlobGasUsedMissing)?;
let total_blob_gas = block.blob_gas_used();
if total_blob_gas != header_blob_gas_used {
return Err(ConsensusError::BlobGasUsedDiff(GotExpected {
got: header_blob_gas_used,
expected: total_blob_gas,
}))
}
}
// EIP-7685: General purpose execution layer requests
if chain_spec.is_prague_active_at_timestamp(block.timestamp) {
let requests = block.requests.as_ref().ok_or(ConsensusError::BodyRequestsMissing)?;
let requests_root = reth_primitives::proofs::calculate_requests_root(&requests.0);
let header_requests_root =
block.requests_root.as_ref().ok_or(ConsensusError::RequestsRootMissing)?;
if requests_root != *header_requests_root {
return Err(ConsensusError::BodyRequestsRootDiff(
GotExpected { got: requests_root, expected: *header_requests_root }.into(),
))
}
}

Additional context

No response

@mattsse mattsse added C-enhancement New feature or request S-needs-triage This issue needs to be labelled D-good-first-issue Nice and easy! A great choice to get started and removed S-needs-triage This issue needs to be labelled labels Aug 27, 2024
@willco-1
Copy link
Contributor

feel free to assign this to me!

willco-1 added a commit to willco-1/reth that referenced this issue Aug 27, 2024
willco-1 added a commit to willco-1/reth that referenced this issue Aug 27, 2024
willco-1 added a commit to willco-1/reth that referenced this issue Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants