Skip to content

Commit

Permalink
Don't include transaction hashes in failed calls or gas estimates
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Mar 2, 2024
1 parent 3e0cabb commit a676a48
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 30 deletions.
12 changes: 5 additions & 7 deletions crates/edr_napi/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -782,7 +780,7 @@ impl LogCollector {

let transaction_failure = edr_provider::TransactionFailure::from_execution_result(
result,
transaction_hash,
Some(transaction_hash),
trace,
);

Expand Down Expand Up @@ -1158,7 +1156,7 @@ impl LogCollector {

let transaction_failure = edr_provider::TransactionFailure::from_execution_result(
transaction_result,
transaction_hash,
Some(transaction_hash),
trace,
);

Expand Down
17 changes: 6 additions & 11 deletions crates/edr_provider/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ impl<LoggerErrorT: Debug> ProviderData<LoggerErrorT> {
// 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();
Expand Down Expand Up @@ -639,16 +638,12 @@ impl<LoggerErrorT: Debug> ProviderData<LoggerErrorT> {

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(),
Expand Down
12 changes: 6 additions & 6 deletions crates/edr_provider/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,31 +314,31 @@ pub struct TransactionFailure {
pub data: String,
#[serde(skip)]
pub solidity_trace: Trace,
pub transaction_hash: B256,
pub transaction_hash: Option<B256>,
}

impl TransactionFailure {
pub fn from_execution_result(
execution_result: &ExecutionResult,
transaction_hash: &B256,
transaction_hash: Option<&B256>,
solidity_trace: &Trace,
) -> Option<Self> {
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<B256>, solidity_trace: Trace) -> Self {
let data = format!("0x{}", hex::encode(output.as_ref()));
Self {
reason: TransactionFailureReason::Revert(output),
Expand All @@ -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<B256>, solidity_trace: Trace) -> Self {
let reason = match halt {
Halt::OpcodeNotFound | Halt::InvalidFEOpcode => {
TransactionFailureReason::OpcodeNotFound
Expand Down
8 changes: 3 additions & 5 deletions crates/edr_provider/src/requests/eth/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ pub fn handle_call_request<LoggerErrorT: Debug>(
.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,
Expand Down
2 changes: 1 addition & 1 deletion crates/edr_provider/src/requests/eth/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ fn send_raw_transaction_and_log<LoggerErrorT: Debug>(

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 {
Expand Down

0 comments on commit a676a48

Please sign in to comment.