Skip to content

Commit e3267bd

Browse files
authored
feat(evm): collect logs from execution result (#8231)
1 parent 91d145c commit e3267bd

File tree

5 files changed

+28
-30
lines changed

5 files changed

+28
-30
lines changed

crates/config/src/providers/remappings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<'a> RemappingsProvider<'a> {
151151
let mut all_remappings = Remappings::new_with_remappings(user_remappings);
152152

153153
// scan all library dirs and autodetect remappings
154-
// todo: if a lib specifies contexts for remappings manually, we need to figure out how to
154+
// TODO: if a lib specifies contexts for remappings manually, we need to figure out how to
155155
// resolve that
156156
if self.auto_detect_remappings {
157157
let mut lib_remappings = BTreeMap::new();

crates/evm/core/src/fork/init.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use revm::primitives::{BlockEnv, CfgEnv, Env, TxEnv};
1010

1111
/// Initializes a REVM block environment based on a forked
1212
/// ethereum provider.
13-
// todo(onbjerg): these bounds needed cus of the bounds in `Provider`, can simplify?
1413
pub async fn environment<N: Network, T: Transport + Clone, P: Provider<T, N>>(
1514
provider: &P,
1615
memory_limit: u64,

crates/evm/evm/src/executors/invariant/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<'a> InvariantExecutor<'a> {
236236
}
237237
} else {
238238
// Collect data for fuzzing from the state changeset.
239-
let mut state_changeset = call_result.state_changeset.clone().unwrap();
239+
let mut state_changeset = call_result.state_changeset.clone();
240240

241241
if !call_result.reverted {
242242
collect_data(

crates/evm/evm/src/executors/mod.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,10 @@ impl Executor {
274274
// and also the chainid, which can be set manually
275275
self.env.cfg.chain_id = res.env.cfg.chain_id;
276276

277-
if let Some(changeset) = &res.state_changeset {
278-
let success = self.is_raw_call_success(to, Cow::Borrowed(changeset), &res, false);
279-
if !success {
280-
return Err(res.into_execution_error("execution error".to_string()).into());
281-
}
277+
let success =
278+
self.is_raw_call_success(to, Cow::Borrowed(&res.state_changeset), &res, false);
279+
if !success {
280+
return Err(res.into_execution_error("execution error".to_string()).into());
282281
}
283282

284283
Ok(res)
@@ -380,9 +379,7 @@ impl Executor {
380379
/// This should not be exposed to the user, as it should be called only by `transact*`.
381380
fn commit(&mut self, result: &mut RawCallResult) {
382381
// Persist changes to db.
383-
if let Some(changes) = &result.state_changeset {
384-
self.backend.commit(changes.clone());
385-
}
382+
self.backend.commit(result.state_changeset.clone());
386383

387384
// Persist cheatcode state.
388385
self.inspector.cheatcodes = result.cheatcodes.take();
@@ -411,7 +408,7 @@ impl Executor {
411408
) -> bool {
412409
self.is_raw_call_success(
413410
address,
414-
Cow::Owned(call_result.state_changeset.take().unwrap_or_default()),
411+
Cow::Owned(std::mem::take(&mut call_result.state_changeset)),
415412
call_result,
416413
should_fail,
417414
)
@@ -667,7 +664,7 @@ pub struct RawCallResult {
667664
/// Scripted transactions generated from this call
668665
pub transactions: Option<BroadcastableTransactions>,
669666
/// The changeset of the state.
670-
pub state_changeset: Option<StateChangeset>,
667+
pub state_changeset: StateChangeset,
671668
/// The `revm::Env` after the call
672669
pub env: EnvWithHandlerCfg,
673670
/// The cheatcode states after execution
@@ -694,7 +691,7 @@ impl Default for RawCallResult {
694691
coverage: None,
695692
debug: None,
696693
transactions: None,
697-
state_changeset: None,
694+
state_changeset: HashMap::default(),
698695
env: EnvWithHandlerCfg::new_with_spec_id(Box::default(), SpecId::LATEST),
699696
cheatcodes: Default::default(),
700697
out: None,
@@ -778,19 +775,20 @@ impl std::ops::DerefMut for CallResult {
778775
fn convert_executed_result(
779776
env: EnvWithHandlerCfg,
780777
inspector: InspectorStack,
781-
result: ResultAndState,
778+
ResultAndState { result, state: state_changeset }: ResultAndState,
782779
has_snapshot_failure: bool,
783780
) -> eyre::Result<RawCallResult> {
784-
let ResultAndState { result: exec_result, state: state_changeset } = result;
785-
let (exit_reason, gas_refunded, gas_used, out) = match exec_result {
786-
ExecutionResult::Success { reason, gas_used, gas_refunded, output, .. } => {
787-
(reason.into(), gas_refunded, gas_used, Some(output))
781+
let (exit_reason, gas_refunded, gas_used, out, exec_logs) = match result {
782+
ExecutionResult::Success { reason, gas_used, gas_refunded, output, logs, .. } => {
783+
(reason.into(), gas_refunded, gas_used, Some(output), logs)
788784
}
789785
ExecutionResult::Revert { gas_used, output } => {
790786
// Need to fetch the unused gas
791-
(InstructionResult::Revert, 0_u64, gas_used, Some(Output::Call(output)))
787+
(InstructionResult::Revert, 0_u64, gas_used, Some(Output::Call(output)), vec![])
788+
}
789+
ExecutionResult::Halt { reason, gas_used } => {
790+
(reason.into(), 0_u64, gas_used, None, vec![])
792791
}
793-
ExecutionResult::Halt { reason, gas_used } => (reason.into(), 0_u64, gas_used, None),
794792
};
795793
let stipend = revm::interpreter::gas::validate_initial_tx_gas(
796794
env.spec_id(),
@@ -804,15 +802,17 @@ fn convert_executed_result(
804802
_ => Bytes::new(),
805803
};
806804

807-
let InspectorData { logs, labels, traces, coverage, debug, cheatcodes, chisel_state } =
805+
let InspectorData { mut logs, labels, traces, coverage, debug, cheatcodes, chisel_state } =
808806
inspector.collect();
809807

810-
let transactions = match cheatcodes.as_ref() {
811-
Some(cheats) if !cheats.broadcastable_transactions.is_empty() => {
812-
Some(cheats.broadcastable_transactions.clone())
813-
}
814-
_ => None,
815-
};
808+
if logs.is_empty() {
809+
logs = exec_logs;
810+
}
811+
812+
let transactions = cheatcodes
813+
.as_ref()
814+
.map(|c| c.broadcastable_transactions.clone())
815+
.filter(|txs| !txs.is_empty());
816816

817817
Ok(RawCallResult {
818818
exit_reason,
@@ -828,7 +828,7 @@ fn convert_executed_result(
828828
coverage,
829829
debug,
830830
transactions,
831-
state_changeset: Some(state_changeset),
831+
state_changeset,
832832
env,
833833
cheatcodes,
834834
out,

crates/evm/evm/src/inspectors/logs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ impl<DB: Database> Inspector<DB> for LogCollector {
4242
self.logs.push(log.clone());
4343
}
4444

45-
#[inline]
4645
fn call(
4746
&mut self,
4847
_context: &mut EvmContext<DB>,

0 commit comments

Comments
 (0)