Skip to content

Commit

Permalink
prevent clones when calling SystemCaller::on_state
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez committed Oct 3, 2024
1 parent 4df0c34 commit ea75193
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,17 @@ where
self.evm_config.fill_tx_env(evm.tx_mut(), transaction, *sender);

// Execute transaction.
let ResultAndState { result, state } = evm.transact().map_err(move |err| {
let result_and_state = evm.transact().map_err(move |err| {
let new_err = err.map_db_err(|e| e.into());
// Ensure hash is calculated for error log, if not already done
BlockValidationError::EVM {
hash: transaction.recalculate_hash(),
error: Box::new(new_err),
}
})?;
evm.db_mut().commit(state.clone());
system_caller.on_state(&ResultAndState { result: result.clone(), state });
system_caller.on_state(&result_and_state);
let ResultAndState { result, state } = result_and_state;
evm.db_mut().commit(state);

// append gas used
cumulative_gas_used += result.gas_used();
Expand Down
8 changes: 4 additions & 4 deletions crates/optimism/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ where
self.evm_config.fill_tx_env(evm.tx_mut(), transaction, *sender);

// Execute transaction.
let ResultAndState { result, state } = evm.transact().map_err(move |err| {
let result_and_state = evm.transact().map_err(move |err| {
let new_err = err.map_db_err(|e| e.into());
// Ensure hash is calculated for error log, if not already done
BlockValidationError::EVM {
Expand All @@ -195,9 +195,9 @@ where
?transaction,
"Executed transaction"
);

evm.db_mut().commit(state.clone());
system_caller.on_state(&ResultAndState { result: result.clone(), state });
system_caller.on_state(&result_and_state);
let ResultAndState { result, state } = result_and_state;
evm.db_mut().commit(state);

// append gas used
cumulative_gas_used += result.gas_used();
Expand Down

0 comments on commit ea75193

Please sign in to comment.