Skip to content

Commit

Permalink
chore: EVM transact, make output generic for POSTEXEC (#1931)
Browse files Browse the repository at this point in the history
* fix: clear JournalState and set first journal vec

* chore: EVM transact make output generic for  POSTEXEC

* Make ExecCommit generic on HaltReason
  • Loading branch information
rakita authored and royvardhan committed Dec 20, 2024
1 parent c1d3c74 commit 3192ffd
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions crates/revm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use context_interface::{
block::BlockSetter,
journaled_state::JournaledState,
result::{
EVMError, ExecutionResult, HaltReason, InvalidHeader, InvalidTransaction, ResultAndState,
EVMError, ExecutionResult, HaltReasonTrait, InvalidHeader, InvalidTransaction,
ResultAndState,
},
transaction::TransactionSetter,
BlockGetter, CfgGetter, DatabaseGetter, ErrorGetter, JournalStateGetter,
Expand Down Expand Up @@ -39,7 +40,7 @@ impl<ERROR, CTX, HANDLER> Evm<ERROR, CTX, HANDLER> {
}
}

impl<ERROR, CTX, VAL, PREEXEC, EXEC, POSTEXEC> EvmCommit
impl<ERROR, CTX, VAL, PREEXEC, EXEC, POSTEXEC, HALT> EvmCommit
for Evm<ERROR, CTX, EthHandler<CTX, ERROR, VAL, PREEXEC, EXEC, POSTEXEC>>
where
CTX: TransactionSetter
Expand Down Expand Up @@ -70,11 +71,12 @@ where
Context = CTX,
Error = ERROR,
ExecResult = FrameResult,
// TODO make output generics
Output = ResultAndState<HaltReason>,
// TODO make output more generics
Output = ResultAndState<HALT>,
>,
HALT: HaltReasonTrait,
{
type CommitOutput = Result<ExecutionResult<HaltReason>, ERROR>;
type CommitOutput = Result<ExecutionResult<HALT>, ERROR>;

fn exec_commit(&mut self) -> Self::CommitOutput {
let res = self.transact();
Expand Down Expand Up @@ -112,19 +114,13 @@ where
ExecResult = FrameResult,
Frame: Frame<FrameResult = FrameResult>,
>,
POSTEXEC: PostExecutionHandler<
Context = CTX,
Error = ERROR,
ExecResult = FrameResult,
// TODO make output generics
Output = ResultAndState<HaltReason>,
>,
POSTEXEC: PostExecutionHandler<Context = CTX, Error = ERROR, ExecResult = FrameResult>,
{
type Transaction = <CTX as TransactionGetter>::Transaction;

type Block = <CTX as BlockGetter>::Block;

type Output = Result<ResultAndState<HaltReason>, ERROR>;
type Output = Result<<POSTEXEC as PostExecutionHandler>::Output, ERROR>;

fn set_block(&mut self, block: Self::Block) {
self.context.set_block(block);
Expand Down Expand Up @@ -176,12 +172,7 @@ where
ExecResult = FrameResult,
Frame: Frame<FrameResult = FrameResult>,
>,
POSTEXEC: PostExecutionHandler<
Context = CTX,
Error = ERROR,
ExecResult = FrameResult,
Output = ResultAndState<HaltReason>,
>,
POSTEXEC: PostExecutionHandler<Context = CTX, Error = ERROR, ExecResult = FrameResult>,
{
/// Pre verify transaction by checking Environment, initial gas spend and if caller
/// has enough balance to pay for the gas.
Expand All @@ -201,7 +192,9 @@ where
///
/// This function will not validate the transaction.
#[inline]
pub fn transact_preverified(&mut self) -> Result<ResultAndState<HaltReason>, ERROR> {
pub fn transact_preverified(
&mut self,
) -> Result<<POSTEXEC as PostExecutionHandler>::Output, ERROR> {
let initial_gas_spend = self
.handler
.validation()
Expand Down Expand Up @@ -233,7 +226,7 @@ where
///
/// This function will validate the transaction.
#[inline]
pub fn transact(&mut self) -> Result<ResultAndState<HaltReason>, ERROR> {
pub fn transact(&mut self) -> Result<<POSTEXEC as PostExecutionHandler>::Output, ERROR> {
let initial_gas_spend = self.preverify_transaction_inner().inspect_err(|_| {
self.clear();
})?;
Expand All @@ -248,7 +241,7 @@ where
fn transact_preverified_inner(
&mut self,
initial_gas_spend: u64,
) -> Result<ResultAndState<HaltReason>, ERROR> {
) -> Result<<POSTEXEC as PostExecutionHandler>::Output, ERROR> {
let context = &mut self.context;
let pre_exec = self.handler.pre_execution();

Expand Down

0 comments on commit 3192ffd

Please sign in to comment.