Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions crates/networking/rpc/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use tracing::debug;
pub const ESTIMATE_ERROR_RATIO: f64 = 0.015;
pub const CALL_STIPEND: u64 = 2_300; // Free gas given at beginning of call.
pub const TRANSACTION_GAS: u64 = 21_000; // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions.
pub const DEFAULT_ETH_CALL_GAS_LIMIT: u64 = 50_000_000;

pub struct CallRequest {
transaction: GenericTransaction,
Expand Down Expand Up @@ -106,13 +107,15 @@ impl RpcHandler for CallRequest {
// Block not found
_ => return Ok(Value::Null),
};
// Prepare transaction with gas limit
let mut transaction = self.transaction.clone();
#[allow(clippy::useless_conversion)]
let gas_limit = transaction.gas.map_or(DEFAULT_ETH_CALL_GAS_LIMIT, |gas| {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let gas_limit = transaction
.gas
.and_then(|gas| u64::try_from(gas).ok())
.unwrap_or(DEFAULT_ETH_CALL_GAS_LIMIT);

is simpler

u64::try_from(gas).unwrap_or(DEFAULT_ETH_CALL_GAS_LIMIT)
});
transaction.gas = Some(gas_limit);
// Run transaction
let result = simulate_tx(
&self.transaction,
&header,
context.storage,
context.blockchain,
)?;
let result = simulate_tx(&transaction, &header, context.storage, context.blockchain)?;
serde_json::to_value(format!("0x{:#x}", result.output()))
.map_err(|error| RpcErr::Internal(error.to_string()))
}
Expand Down