From a676a4876517d66e53541492d4d820cc9901cb10 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Sat, 2 Mar 2024 18:00:08 +0100 Subject: [PATCH] Don't include transaction hashes in failed calls or gas estimates --- crates/edr_napi/src/logger.rs | 12 +++++------- crates/edr_provider/src/data.rs | 17 ++++++----------- crates/edr_provider/src/error.rs | 12 ++++++------ crates/edr_provider/src/requests/eth/call.rs | 8 +++----- .../src/requests/eth/transactions.rs | 2 +- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/crates/edr_napi/src/logger.rs b/crates/edr_napi/src/logger.rs index 3f726cd36b..607ffe4b65 100644 --- a/crates/edr_napi/src/logger.rs +++ b/crates/edr_napi/src/logger.rs @@ -410,11 +410,9 @@ impl LogCollector { logger.log_console_log_messages(console_log_inputs); - if let Some(transaction_failure) = TransactionFailure::from_execution_result( - execution_result, - transaction.hash(), - trace, - ) { + if let Some(transaction_failure) = + TransactionFailure::from_execution_result(execution_result, None, trace) + { logger.log_transaction_failure(&transaction_failure); } }); @@ -782,7 +780,7 @@ impl LogCollector { let transaction_failure = edr_provider::TransactionFailure::from_execution_result( result, - transaction_hash, + Some(transaction_hash), trace, ); @@ -1158,7 +1156,7 @@ impl LogCollector { let transaction_failure = edr_provider::TransactionFailure::from_execution_result( transaction_result, - transaction_hash, + Some(transaction_hash), trace, ); diff --git a/crates/edr_provider/src/data.rs b/crates/edr_provider/src/data.rs index 2198b6ee9c..8bff327643 100644 --- a/crates/edr_provider/src/data.rs +++ b/crates/edr_provider/src/data.rs @@ -608,7 +608,6 @@ impl ProviderData { // Minimum gas cost that is required for transaction to be included in // a block let minimum_cost = transaction.initial_cost(self.spec_id()); - let transaction_hash = *transaction.hash(); let tx_env: TxEnv = transaction.into(); let state_overrides = StateOverrides::default(); @@ -639,16 +638,12 @@ impl ProviderData { let mut initial_estimation = match result { ExecutionResult::Success { gas_used, .. } => Ok(gas_used), - ExecutionResult::Revert { output, .. } => Err(TransactionFailure::revert( - output, - transaction_hash, - trace.clone(), - )), - ExecutionResult::Halt { reason, .. } => Err(TransactionFailure::halt( - reason, - transaction_hash, - trace.clone(), - )), + ExecutionResult::Revert { output, .. } => { + Err(TransactionFailure::revert(output, None, trace.clone())) + } + ExecutionResult::Halt { reason, .. } => { + Err(TransactionFailure::halt(reason, None, trace.clone())) + } } .map_err(|failure| EstimateGasFailure { console_log_inputs: inspector.into_console_log_encoded_messages(), diff --git a/crates/edr_provider/src/error.rs b/crates/edr_provider/src/error.rs index 2d0f013250..77a9e37452 100644 --- a/crates/edr_provider/src/error.rs +++ b/crates/edr_provider/src/error.rs @@ -314,31 +314,31 @@ pub struct TransactionFailure { pub data: String, #[serde(skip)] pub solidity_trace: Trace, - pub transaction_hash: B256, + pub transaction_hash: Option, } impl TransactionFailure { pub fn from_execution_result( execution_result: &ExecutionResult, - transaction_hash: &B256, + transaction_hash: Option<&B256>, solidity_trace: &Trace, ) -> Option { match execution_result { ExecutionResult::Success { .. } => None, ExecutionResult::Revert { output, .. } => Some(Self::revert( output.clone(), - *transaction_hash, + transaction_hash.cloned(), solidity_trace.clone(), )), ExecutionResult::Halt { reason, .. } => Some(Self::halt( *reason, - *transaction_hash, + transaction_hash.cloned(), solidity_trace.clone(), )), } } - pub fn revert(output: Bytes, transaction_hash: B256, solidity_trace: Trace) -> Self { + pub fn revert(output: Bytes, transaction_hash: Option, solidity_trace: Trace) -> Self { let data = format!("0x{}", hex::encode(output.as_ref())); Self { reason: TransactionFailureReason::Revert(output), @@ -348,7 +348,7 @@ impl TransactionFailure { } } - pub fn halt(halt: Halt, tx_hash: B256, solidity_trace: Trace) -> Self { + pub fn halt(halt: Halt, tx_hash: Option, solidity_trace: Trace) -> Self { let reason = match halt { Halt::OpcodeNotFound | Halt::InvalidFEOpcode => { TransactionFailureReason::OpcodeNotFound diff --git a/crates/edr_provider/src/requests/eth/call.rs b/crates/edr_provider/src/requests/eth/call.rs index cf635601b9..77e2d4539b 100644 --- a/crates/edr_provider/src/requests/eth/call.rs +++ b/crates/edr_provider/src/requests/eth/call.rs @@ -35,11 +35,9 @@ pub fn handle_call_request( .map_err(ProviderError::Logger)?; if data.bail_on_call_failure() { - if let Some(failure) = TransactionFailure::from_execution_result( - &result.execution_result, - transaction.hash(), - &result.trace, - ) { + if let Some(failure) = + TransactionFailure::from_execution_result(&result.execution_result, None, &result.trace) + { return Err(ProviderError::TransactionFailed( crate::error::TransactionFailureWithTraces { failure, diff --git a/crates/edr_provider/src/requests/eth/transactions.rs b/crates/edr_provider/src/requests/eth/transactions.rs index 6d1d71521c..b40572662e 100644 --- a/crates/edr_provider/src/requests/eth/transactions.rs +++ b/crates/edr_provider/src/requests/eth/transactions.rs @@ -434,7 +434,7 @@ fn send_raw_transaction_and_log( if data.bail_on_transaction_failure() { let transaction_failure = transaction_result.and_then(|(result, trace)| { - TransactionFailure::from_execution_result(&result, &transaction_hash, &trace) + TransactionFailure::from_execution_result(&result, Some(&transaction_hash), &trace) }); if let Some(failure) = transaction_failure {