Skip to content

Commit

Permalink
chore: small Requests clean up (#13374)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Dec 13, 2024
1 parent 008cb25 commit fb64997
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 43 deletions.
4 changes: 2 additions & 2 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use alloy_consensus::Transaction as _;
use alloy_eips::eip7685::Requests;
use alloy_eips::{eip6110, eip7685::Requests};
use core::fmt::Display;
use reth_chainspec::{ChainSpec, EthereumHardfork, EthereumHardforks, MAINNET};
use reth_consensus::ConsensusError;
Expand Down Expand Up @@ -246,7 +246,7 @@ where
let mut requests = Requests::default();

if !deposit_requests.is_empty() {
requests.push_request(core::iter::once(0).chain(deposit_requests).collect());
requests.push_request_with_type(eip6110::DEPOSIT_REQUEST_TYPE, deposit_requests);
}

requests.extend(self.system_caller.apply_post_execution_changes(&mut evm)?);
Expand Down
46 changes: 13 additions & 33 deletions crates/ethereum/payload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

use alloy_consensus::{Header, EMPTY_OMMER_ROOT_HASH};
use alloy_eips::{
eip4844::MAX_DATA_GAS_PER_BLOCK, eip7002::WITHDRAWAL_REQUEST_TYPE,
eip7251::CONSOLIDATION_REQUEST_TYPE, eip7685::Requests, merge::BEACON_NONCE,
eip4844::MAX_DATA_GAS_PER_BLOCK, eip6110, eip7685::Requests, merge::BEACON_NONCE,
};
use alloy_primitives::U256;
use reth_basic_payload_builder::{
Expand Down Expand Up @@ -357,11 +356,11 @@ where
executed_txs.push(tx.into_signed());
}

// Release db
drop(evm);

// check if we have a better block
if !is_better_payload(best_payload.as_ref(), total_fees) {
// Release db
drop(evm);

// can skip building the block
return Ok(BuildOutcome::Aborted { fees: total_fees, cached_reads })
}
Expand All @@ -370,46 +369,27 @@ where
let requests = if chain_spec.is_prague_active_at_timestamp(attributes.timestamp) {
let deposit_requests = parse_deposits_from_receipts(&chain_spec, receipts.iter().flatten())
.map_err(|err| PayloadBuilderError::Internal(RethError::Execution(err.into())))?;
let withdrawal_requests = system_caller
.post_block_withdrawal_requests_contract_call(
&mut db,
&initialized_cfg,
&initialized_block_env,
)
.map_err(|err| PayloadBuilderError::Internal(err.into()))?;
let consolidation_requests = system_caller
.post_block_consolidation_requests_contract_call(
&mut db,
&initialized_cfg,
&initialized_block_env,
)
.map_err(|err| PayloadBuilderError::Internal(err.into()))?;

let mut requests = Requests::default();

if !deposit_requests.is_empty() {
requests.push_request(core::iter::once(0).chain(deposit_requests).collect());
requests.push_request_with_type(eip6110::DEPOSIT_REQUEST_TYPE, deposit_requests);
}

if !withdrawal_requests.is_empty() {
requests.push_request(
core::iter::once(WITHDRAWAL_REQUEST_TYPE).chain(withdrawal_requests).collect(),
);
}

if !consolidation_requests.is_empty() {
requests.push_request(
core::iter::once(CONSOLIDATION_REQUEST_TYPE)
.chain(consolidation_requests)
.collect(),
);
}
requests.extend(
system_caller
.apply_post_execution_changes(&mut evm)
.map_err(|err| PayloadBuilderError::Internal(err.into()))?,
);

Some(requests)
} else {
None
};

// Release db
drop(evm);

let withdrawals_root =
commit_withdrawals(&mut db, &chain_spec, attributes.timestamp, &attributes.withdrawals)?;

Expand Down
10 changes: 2 additions & 8 deletions crates/evm/src/system_calls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,13 @@ where
// Collect all EIP-7685 requests
let withdrawal_requests = self.apply_withdrawal_requests_contract_call(evm)?;
if !withdrawal_requests.is_empty() {
requests.push_request(
core::iter::once(WITHDRAWAL_REQUEST_TYPE).chain(withdrawal_requests).collect(),
);
requests.push_request_with_type(WITHDRAWAL_REQUEST_TYPE, withdrawal_requests);
}

// Collect all EIP-7251 requests
let consolidation_requests = self.apply_consolidation_requests_contract_call(evm)?;
if !consolidation_requests.is_empty() {
requests.push_request(
core::iter::once(CONSOLIDATION_REQUEST_TYPE)
.chain(consolidation_requests)
.collect(),
);
requests.push_request_with_type(CONSOLIDATION_REQUEST_TYPE, consolidation_requests);
}

Ok(requests)
Expand Down

0 comments on commit fb64997

Please sign in to comment.