Skip to content

Commit

Permalink
feat: add transact function to 7251 (#11158)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Sep 24, 2024
1 parent c0f0dd7 commit 94d1d87
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions crates/evm/src/system_calls/eip7251.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ where
///
/// If Prague is not active at the given timestamp, then this is a no-op, and an empty vector is
/// returned. Otherwise, the consolidation requests are returned.
///
/// Note: this does not commit the state changes to the database, it only transact the call.
#[inline]
pub fn apply_consolidation_requests_contract_call<EvmConfig, EXT, DB>(
pub fn transact_consolidation_requests_contract_call<EvmConfig, EXT, DB>(
evm_config: &EvmConfig,
evm: &mut Evm<'_, EXT, DB>,
) -> Result<Vec<Request>, BlockExecutionError>
) -> Result<ResultAndState, BlockExecutionError>
where
DB: Database + DatabaseCommit,
DB::Error: core::fmt::Display,
Expand All @@ -77,7 +79,7 @@ where
Bytes::new(),
);

let ResultAndState { result, mut state } = match evm.transact() {
let mut res = match evm.transact() {
Ok(res) => res,
Err(e) => {
evm.context.evm.env = previous_env;
Expand All @@ -89,13 +91,35 @@ where
};

// cleanup the state
state.remove(&alloy_eips::eip7002::SYSTEM_ADDRESS);
state.remove(&evm.block().coinbase);
evm.context.evm.db.commit(state);
res.state.remove(&alloy_eips::eip7002::SYSTEM_ADDRESS);
res.state.remove(&evm.block().coinbase);

// re-set the previous env
evm.context.evm.env = previous_env;

Ok(res)
}

/// Applies the post-block call to the EIP-7251 consolidation requests contract.
///
/// If Prague is not active at the given timestamp, then this is a no-op, and an empty vector is
/// returned. Otherwise, the consolidation requests are returned.
#[inline]
pub fn apply_consolidation_requests_contract_call<EvmConfig, EXT, DB>(
evm_config: &EvmConfig,
evm: &mut Evm<'_, EXT, DB>,
) -> Result<Vec<Request>, BlockExecutionError>
where
DB: Database + DatabaseCommit,
DB::Error: core::fmt::Display,
EvmConfig: ConfigureEvm<Header = Header>,
{
let ResultAndState { result, state } =
transact_consolidation_requests_contract_call(evm_config, evm)?;

// commit the state
evm.context.evm.db.commit(state);

let mut data = match result {
ExecutionResult::Success { output, .. } => Ok(output.into_data()),
ExecutionResult::Revert { output, .. } => {
Expand Down

0 comments on commit 94d1d87

Please sign in to comment.