Skip to content

Commit

Permalink
Move default_eth_call_gas method to BlockArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
slowli committed Aug 16, 2024
1 parent 83446eb commit 09d4175
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 40 deletions.
16 changes: 14 additions & 2 deletions core/node/api_server/src/execution_sandbox/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use zksync_multivm::{
TxExecutionMode, VmExecutionMode, VmExecutionResultAndLogs, VmInterface,
},
tracers::StorageInvocations,
utils::adjust_pubdata_price_for_tx,
utils::{adjust_pubdata_price_for_tx, get_eth_call_gas_limit},
vm_latest::{constants::BATCH_COMPUTATIONAL_GAS_LIMIT, HistoryDisabled},
MultiVMTracer, MultiVmTracerPointer, VmInstance,
};
Expand Down Expand Up @@ -473,7 +473,19 @@ impl BlockArgs {
)
}

pub(crate) async fn resolve_block_info(
pub(crate) async fn default_eth_call_gas(
&self,
connection: &mut Connection<'_, Core>,
) -> anyhow::Result<U256> {
let protocol_version = self
.resolve_block_info(connection)
.await
.context("failed to resolve block info")?
.protocol_version;
Ok(get_eth_call_gas_limit(protocol_version.into()).into())
}

async fn resolve_block_info(
&self,
connection: &mut Connection<'_, Core>,
) -> anyhow::Result<ResolvedBlockInfo> {
Expand Down
18 changes: 1 addition & 17 deletions core/node/api_server/src/tx_sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use zksync_multivm::{
interface::{TransactionExecutionMetrics, TxExecutionMode, VmExecutionResultAndLogs},
utils::{
adjust_pubdata_price_for_tx, derive_base_fee_and_gas_per_pubdata, derive_overhead,
get_eth_call_gas_limit, get_max_batch_gas_limit,
get_max_batch_gas_limit,
},
vm_latest::constants::BATCH_COMPUTATIONAL_GAS_LIMIT,
};
Expand Down Expand Up @@ -1075,20 +1075,4 @@ impl TxSender {
}
Ok(())
}

// FIXME: rework as `BlockArgs` method with supplied connection
pub(crate) async fn get_default_eth_call_gas(
&self,
block_args: BlockArgs,
) -> anyhow::Result<u64> {
let mut connection = self.acquire_replica_connection().await?;

let protocol_version = block_args
.resolve_block_info(&mut connection)
.await
.context("failed to resolve block info")?
.protocol_version;

Ok(get_eth_call_gas_limit(protocol_version.into()))
}
}
13 changes: 2 additions & 11 deletions core/node/api_server/src/web3/namespaces/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,15 @@ impl DebugNamespace {
.state
.resolve_block_args(&mut connection, block_id)
.await?;
drop(connection);

self.current_method().set_block_diff(
self.state
.last_sealed_l2_block
.diff_with_block_args(&block_args),
);

if request.gas.is_none() {
request.gas = Some(
self.state
.tx_sender
.get_default_eth_call_gas(block_args)
.await
.map_err(Web3Error::InternalError)?
.into(),
)
request.gas = Some(block_args.default_eth_call_gas(&mut connection).await?);
}
drop(connection);

let call_overrides = request.get_call_overrides()?;
let tx = L2Tx::from_request(request.into(), MAX_ENCODED_TX_SIZE)?;
Expand Down
13 changes: 3 additions & 10 deletions core/node/api_server/src/web3/namespaces/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,11 @@ impl EthNamespace {
.last_sealed_l2_block
.diff_with_block_args(&block_args),
);
drop(connection);

if request.gas.is_none() {
request.gas = Some(
self.state
.tx_sender
.get_default_eth_call_gas(block_args)
.await
.map_err(Web3Error::InternalError)?
.into(),
)
request.gas = Some(block_args.default_eth_call_gas(&mut connection).await?);
}
drop(connection);

let call_overrides = request.get_call_overrides()?;
let tx = L2Tx::from_request(request.into(), self.state.api_config.max_tx_size)?;

Expand Down

0 comments on commit 09d4175

Please sign in to comment.