Skip to content

Commit

Permalink
Return gas used on calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ilitteri committed Nov 12, 2023
1 parent 81c6288 commit de13350
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/node/eth.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashSet;

use bigdecimal::num_traits::ToBytes;
use colored::Colorize;
use futures::FutureExt;
use itertools::Itertools;
Expand Down Expand Up @@ -61,11 +62,15 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
Ok(mut tx) => {
tx.common_data.fee.gas_limit = ETH_CALL_GAS_LIMIT.into();
let result = self.run_l2_call(tx);
let gas_used = result.clone().unwrap().statistics.gas_used;

match result {
Ok(execution_result) => match execution_result {
Ok(execution_result) => match execution_result.result {
ExecutionResult::Success { output } => {
Ok(output.into()).into_boxed_future()
let mut response_bytes = vec![];
response_bytes.extend_from_slice(&gas_used.to_le_bytes());
response_bytes.extend_from_slice(&output);
Ok(response_bytes.into()).into_boxed_future()
}
ExecutionResult::Revert { output } => {
let message = output.to_user_friendly_string();
Expand Down
4 changes: 2 additions & 2 deletions src/node/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {
}

/// Runs L2 'eth call' method - that doesn't commit to a block.
pub fn run_l2_call(&self, mut l2_tx: L2Tx) -> Result<ExecutionResult, String> {
pub fn run_l2_call(&self, mut l2_tx: L2Tx) -> Result<VmExecutionResultAndLogs, String> {
let execution_mode = TxExecutionMode::EthCall;

let inner = self
Expand Down Expand Up @@ -1056,7 +1056,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {
formatter::print_call(call, 0, &inner.show_calls, inner.resolve_hashes);
}

Ok(tx_result.result)
Ok(tx_result)
}

fn display_detailed_gas_info(
Expand Down

0 comments on commit de13350

Please sign in to comment.