From 550f60630ecd3ed61e8c30ebaa6af51c6b9412a0 Mon Sep 17 00:00:00 2001 From: Andrei Silviu Dragnea Date: Tue, 13 Feb 2024 17:32:02 +0200 Subject: [PATCH] NDEV-2620: Move Tracer trait to neon-lib crate --- evm_loader/lib/src/commands/emulate.rs | 2 +- evm_loader/lib/src/tracing/tracers/mod.rs | 6 +++++- .../lib/src/tracing/tracers/struct_logger.rs | 3 ++- evm_loader/program/Cargo.toml | 2 +- evm_loader/program/src/evm/tracing.rs | 14 +------------- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/evm_loader/lib/src/commands/emulate.rs b/evm_loader/lib/src/commands/emulate.rs index cf56d2943..05de4cd0c 100644 --- a/evm_loader/lib/src/commands/emulate.rs +++ b/evm_loader/lib/src/commands/emulate.rs @@ -9,13 +9,13 @@ use solana_sdk::pubkey::Pubkey; use crate::commands::get_config::BuildConfigSimulator; use crate::rpc::Rpc; use crate::syscall_stubs::setup_emulator_syscall_stubs; +use crate::tracing::tracers::Tracer; use crate::types::{EmulateRequest, TxParams}; use crate::{ account_storage::{EmulatorAccountStorage, SolanaAccount}, errors::NeonError, NeonResult, }; -use evm_loader::evm::tracing::Tracer; use evm_loader::{ config::{EVM_STEPS_MIN, PAYMENT_TO_TREASURE}, evm::{ExitStatus, Machine}, diff --git a/evm_loader/lib/src/tracing/tracers/mod.rs b/evm_loader/lib/src/tracing/tracers/mod.rs index 69f2ab0ce..0f54f6391 100644 --- a/evm_loader/lib/src/tracing/tracers/mod.rs +++ b/evm_loader/lib/src/tracing/tracers/mod.rs @@ -1,7 +1,7 @@ use crate::tracing::tracers::struct_logger::StructLogger; use crate::tracing::TraceConfig; use evm_loader::evm::database::Database; -use evm_loader::evm::tracing::{Event, EventListener, Tracer}; +use evm_loader::evm::tracing::{Event, EventListener}; use serde_json::Value; pub mod struct_logger; @@ -20,6 +20,10 @@ impl EventListener for TracerTypeEnum { } } +pub trait Tracer: EventListener { + fn into_traces(self) -> Value; +} + impl Tracer for TracerTypeEnum { fn into_traces(self) -> Value { match self { diff --git a/evm_loader/lib/src/tracing/tracers/struct_logger.rs b/evm_loader/lib/src/tracing/tracers/struct_logger.rs index 79a65cb3f..e8d23c922 100644 --- a/evm_loader/lib/src/tracing/tracers/struct_logger.rs +++ b/evm_loader/lib/src/tracing/tracers/struct_logger.rs @@ -7,9 +7,10 @@ use serde::Serialize; use serde_json::Value; use web3::types::Bytes; +use crate::tracing::tracers::Tracer; use crate::tracing::TraceConfig; use evm_loader::evm::opcode_table::OPNAMES; -use evm_loader::evm::tracing::{Event, EventListener, Tracer}; +use evm_loader::evm::tracing::{Event, EventListener}; /// `StructLoggerResult` groups all structured logs emitted by the EVM /// while replaying a transaction in debug mode as well as transaction diff --git a/evm_loader/program/Cargo.toml b/evm_loader/program/Cargo.toml index 56c1aa37e..2cb4e8486 100644 --- a/evm_loader/program/Cargo.toml +++ b/evm_loader/program/Cargo.toml @@ -51,7 +51,6 @@ borsh = "0.9" bincode = "1" serde_bytes = "0.11.12" serde = { version = "1.0.186", default-features = false, features = ["derive", "rc"] } -serde_json = { version = "1.0.107", features = ["preserve_order"] } ethnum = { version = "1.4", default-features = false, features = ["serde"] } cfg-if = { version = "1.0" } log = { version = "0.4", default-features = false, optional = true } @@ -64,6 +63,7 @@ features = ["is_sync"] [dev-dependencies] tokio = { version = "1.0", features = ["full"] } +serde_json = { version = "1.0.107", features = ["preserve_order"] } [lib] crate-type = ["cdylib", "lib"] diff --git a/evm_loader/program/src/evm/tracing.rs b/evm_loader/program/src/evm/tracing.rs index 59431c150..8f7776206 100644 --- a/evm_loader/program/src/evm/tracing.rs +++ b/evm_loader/program/src/evm/tracing.rs @@ -1,8 +1,6 @@ +use super::{Context, ExitStatus}; use crate::evm::database::Database; use ethnum::U256; -use serde_json::Value; - -use super::{Context, ExitStatus}; pub struct NoopEventListener; @@ -10,20 +8,10 @@ pub trait EventListener { fn event(&mut self, executor_state: &impl Database, event: Event); } -pub trait Tracer: EventListener { - fn into_traces(self) -> Value; -} - impl EventListener for NoopEventListener { fn event(&mut self, _executor_state: &impl Database, _event: Event) {} } -impl Tracer for NoopEventListener { - fn into_traces(self) -> Value { - Value::Null - } -} - /// Trace event pub enum Event { BeginVM {