Skip to content

Commit

Permalink
Return parent header from full_validation to avoid retrieving it agai…
Browse files Browse the repository at this point in the history
…n when checking the gas limit
  • Loading branch information
ckoopmann committed Mar 25, 2024
1 parent 3b5de79 commit 58fc61f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
24 changes: 8 additions & 16 deletions src/rpc/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use reth::consensus_common::validation::{
validate_all_transaction_regarding_block_and_nonces, validate_block_regarding_chain,
validate_block_standalone, validate_header_standalone,
};
use reth::primitives::SealedHeader;
use reth::primitives::{
revm_primitives::AccountInfo, Address, BlockId, ChainSpec, Receipts, SealedBlock,
TransactionSigned, U256,
Expand Down Expand Up @@ -77,7 +78,6 @@ where
}

fn validate_inner(&self) -> RpcResult<()> {
self.trace_validation_step(self.check_gas_limit(), "Check Gas Limit")?;

self.trace_validation_step(
self.compare_message_execution_payload(),
Expand All @@ -86,7 +86,9 @@ where

let block = self.trace_validation_step(self.parse_block(), "Block parsing")?;

self.trace_validation_step(self.validate_header(&block), "Full validation")?;
let parent = self.trace_validation_step(self.validate_header(&block), "Full validation")?;

self.trace_validation_step(self.check_gas_limit(parent), "Check Gas Limit")?;

let state = self.trace_validation_step(
self.execute_and_verify_block(&block),
Expand Down Expand Up @@ -152,7 +154,7 @@ where
.to_rpc_result()
}

fn validate_header(&self, block: &SealedBlock) -> RpcResult<()> {
fn validate_header(&self, block: &SealedBlock) -> RpcResult<SealedHeader> {
full_validation(block, &self.provider, &self.provider.chain_spec()).to_rpc_result()
}

Expand Down Expand Up @@ -223,21 +225,11 @@ where
)
}

fn check_gas_limit(&self) -> RpcResult<()> {
fn check_gas_limit(&self, parent: SealedHeader) -> RpcResult<()> {
let parent_hash = &self.request_body.execution_payload.parent_hash;
let registered_gas_limit = self.request_body.registered_gas_limit;
let block_gas_limit = self.request_body.execution_payload.gas_limit;

let parent = self
.provider
.header(parent_hash)
.to_rpc_result()?
.ok_or(internal_rpc_err(format!(
"Parent block with hash {} not found",
parent_hash
)))?;
tracing::debug!(request_id=self.request_id.to_string(), parent_hash = %parent_hash, parent_gas_limit = parent.gas_limit, registered_gas_limit = registered_gas_limit, block_gas_limit = block_gas_limit, "Checking gas limit");

// Prysm has a bug where it registers validators with a desired gas limit
// of 0. Some builders treat these as desiring gas limit 30_000_000. As a
// workaround, whenever the desired gas limit is 0, we accept both the
Expand Down Expand Up @@ -346,7 +338,7 @@ pub fn full_validation<Provider: HeaderProvider + AccountReader + WithdrawalsPro
block: &SealedBlock,
provider: Provider,
chain_spec: &ChainSpec,
) -> RethResult<()> {
) -> RethResult<SealedHeader> {
validate_header_standalone(&block.header, chain_spec)?;
validate_block_standalone(block, chain_spec)?;
let parent = validate_block_regarding_chain(block, &provider)?;
Expand All @@ -372,5 +364,5 @@ pub fn full_validation<Provider: HeaderProvider + AccountReader + WithdrawalsPro
provider,
chain_spec,
)?;
Ok(())
Ok(parent)
}
2 changes: 1 addition & 1 deletion tests/integration/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async fn test_incorrect_parent() {
validation_request_body.clone(),
)
.await;
let expected_message = format!("Parent block with hash {:?} not found", new_parent_hash);
let expected_message = format!("block parent [hash={:?}] is not known", new_parent_hash);
let error_message = get_call_error_message(result.unwrap_err()).unwrap();
assert_eq!(error_message, expected_message);
}
Expand Down

0 comments on commit 58fc61f

Please sign in to comment.