refactor: simplify SystemCaller API (#14578)

This commit is contained in:
Arsenii Kulikov
2025-02-19 14:08:49 +04:00
committed by GitHub
parent 849c04cb34
commit e92cf35ac9
11 changed files with 81 additions and 217 deletions

View File

@ -36,7 +36,6 @@ use revm::{
result::{ExecutionResult, ResultAndState},
Block,
},
DatabaseCommit,
};
use std::time::{Duration, Instant};
use tokio::sync::Mutex;
@ -277,10 +276,11 @@ pub trait LoadPendingBlock:
let chain_spec = self.provider().chain_spec();
let mut system_caller = SystemCaller::new(self.evm_config().clone(), chain_spec.clone());
let mut system_caller = SystemCaller::new(chain_spec.clone());
let mut evm = self.evm_config().evm_with_env(&mut db, evm_env.clone());
system_caller
.pre_block_blockhashes_contract_call(&mut db, &evm_env, parent_hash)
.apply_blockhashes_contract_call(parent_hash, &mut evm)
.map_err(|err| EthApiError::Internal(err.into()))?;
let mut results = Vec::new();
@ -337,9 +337,8 @@ pub trait LoadPendingBlock:
}
let tx_env = self.evm_config().tx_env(tx.tx(), tx.signer());
let mut evm = self.evm_config().evm_with_env(&mut db, evm_env.clone());
let ResultAndState { result, state } = match evm.transact(tx_env) {
let ResultAndState { result, state: _ } = match evm.transact_commit(tx_env) {
Ok(res) => res,
Err(err) => {
if let Some(err) = err.as_invalid_tx_err() {
@ -361,10 +360,6 @@ pub trait LoadPendingBlock:
return Err(Self::Error::from_evm_err(err));
}
};
// drop evm to release db reference.
drop(evm);
// commit changes
db.commit(state);
// add to the total blob gas used if the transaction successfully executed
if let Some(tx_blob_gas) = tx.blob_gas_used() {
@ -395,6 +390,9 @@ pub trait LoadPendingBlock:
&[],
);
// release db
drop(evm);
// increment account balances for withdrawals
db.increment_balances(balance_increments).map_err(Self::Error::from_eth_err)?;

View File

@ -468,18 +468,13 @@ pub trait Trace:
db: &mut DB,
evm_env: &EvmEnv<<Self::Evm as ConfigureEvmEnv>::Spec>,
) -> Result<(), Self::Error> {
let mut system_caller =
SystemCaller::new(self.evm_config().clone(), self.provider().chain_spec());
// apply relevant system calls
system_caller
.pre_block_beacon_root_contract_call(db, evm_env, block.parent_beacon_block_root())
.map_err(|_| EthApiError::EvmCustom("failed to apply 4788 system call".to_string()))?;
let mut system_caller = SystemCaller::new(self.provider().chain_spec());
// apply relevant system calls
let mut evm = self.evm_config().evm_with_env(db, evm_env.clone());
system_caller
.pre_block_blockhashes_contract_call(db, evm_env, block.parent_hash())
.map_err(|_| {
EthApiError::EvmCustom("failed to apply blockhashes system call".to_string())
})?;
.apply_pre_execution_changes(block.header(), &mut evm)
.map_err(|_| EthApiError::EvmCustom("failed to apply 4788 system call".to_string()))?;
Ok(())
}