Skip to content

Commit

Permalink
refactor: decouple Logger and Provider generics (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann authored Aug 16, 2024
1 parent 0167f7f commit f0ebfd0
Show file tree
Hide file tree
Showing 36 changed files with 420 additions and 599 deletions.
22 changes: 12 additions & 10 deletions crates/edr_napi/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ impl Logger {
impl edr_provider::Logger<L1ChainSpec> for Logger {
type BlockchainError = BlockchainError<L1ChainSpec>;

type LoggerError = LoggerError;

fn is_enabled(&self) -> bool {
self.collector.is_enabled
}
Expand All @@ -143,7 +141,7 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
spec_id: edr_eth::SpecId,
transaction: &transaction::Signed,
result: &edr_provider::CallResult,
) -> Result<(), Self::LoggerError> {
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.collector.log_call(spec_id, transaction, result);

Ok(())
Expand All @@ -154,7 +152,7 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
spec_id: edr_eth::SpecId,
transaction: &transaction::Signed,
failure: &edr_provider::EstimateGasFailure,
) -> Result<(), Self::LoggerError> {
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.collector
.log_estimate_gas(spec_id, transaction, failure);

Expand All @@ -165,15 +163,19 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
&mut self,
spec_id: edr_eth::SpecId,
mining_result: &edr_provider::DebugMineBlockResult<L1ChainSpec, Self::BlockchainError>,
) -> Result<(), Self::LoggerError> {
self.collector.log_interval_mined(spec_id, mining_result)
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.collector
.log_interval_mined(spec_id, mining_result)
.map_err(Box::new)?;

Ok(())
}

fn log_mined_block(
&mut self,
spec_id: edr_eth::SpecId,
mining_results: &[edr_provider::DebugMineBlockResult<L1ChainSpec, Self::BlockchainError>],
) -> Result<(), Self::LoggerError> {
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.collector.log_mined_blocks(spec_id, mining_results);

Ok(())
Expand All @@ -184,7 +186,7 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
spec_id: edr_eth::SpecId,
transaction: &edr_evm::transaction::Signed,
mining_results: &[edr_provider::DebugMineBlockResult<L1ChainSpec, Self::BlockchainError>],
) -> Result<(), Self::LoggerError> {
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.collector
.log_send_transaction(spec_id, transaction, mining_results);

Expand All @@ -194,8 +196,8 @@ impl edr_provider::Logger<L1ChainSpec> for Logger {
fn print_method_logs(
&mut self,
method: &str,
error: Option<&ProviderError<LoggerError>>,
) -> Result<(), Self::LoggerError> {
error: Option<&ProviderError>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
if let Some(error) = error {
self.collector.state = LoggingState::Empty;

Expand Down
4 changes: 2 additions & 2 deletions crates/edr_napi/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ use self::config::ProviderConfig;
use crate::{
call_override::CallOverrideCallback,
context::EdrContext,
logger::{Logger, LoggerConfig, LoggerError},
logger::{Logger, LoggerConfig},
subscribe::SubscriberCallback,
trace::RawTrace,
};

/// A JSON-RPC provider for Ethereum.
#[napi]
pub struct Provider {
provider: Arc<edr_provider::Provider<LoggerError>>,
provider: Arc<edr_provider::Provider>,
runtime: runtime::Handle,
#[cfg(feature = "scenarios")]
scenario_file: Option<napi::tokio::sync::Mutex<napi::tokio::fs::File>>,
Expand Down
8 changes: 2 additions & 6 deletions crates/edr_provider/src/console_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl ConsoleLogCollector {

#[cfg(test)]
pub(crate) mod tests {
use core::fmt::Debug;

use anyhow::Context;
use edr_eth::{
Expand All @@ -65,11 +64,8 @@ pub(crate) mod tests {
pub expected_call_data: Bytes,
}

pub fn deploy_console_log_contract<
LoggerErrorT: Debug + Send + Sync + 'static,
TimerT: Clone + TimeSinceEpoch,
>(
provider_data: &mut ProviderData<LoggerErrorT, TimerT>,
pub fn deploy_console_log_contract<TimerT: Clone + TimeSinceEpoch>(
provider_data: &mut ProviderData<TimerT>,
) -> anyhow::Result<ConsoleLogTransaction> {
// Compiled with solc 0.8.17, without optimizations
/*
Expand Down
Loading

0 comments on commit f0ebfd0

Please sign in to comment.