Skip to content

Commit

Permalink
fix(api): batch fee input scaling for debug_traceCall (#3344)
Browse files Browse the repository at this point in the history
## What ❔

Changes the `debug_traceCall` handler to use gas price factor instead of
plain gas factor.

Additionally removes entrypoints into `get_batch_fee_input_scaled` with
default scaling factor (1.0)

## Why ❔

Previously, `debug_traceCall` was using incorrect gas scaling factor

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Tests for the changes have been added / updated.
- [x] Documentation comments have been added / updated.
- [x] Code has been formatted via `zkstack dev fmt` and `zkstack dev
lint`.
  • Loading branch information
itegulov authored Dec 5, 2024
1 parent d0078df commit 7ace594
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion core/lib/config/src/configs/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl Web3JsonRpcConfig {
pubsub_polling_interval: Some(200),
max_nonce_ahead: 50,
gas_price_scale_factor: 1.2,
estimate_gas_scale_factor: 1.2,
estimate_gas_scale_factor: 1.5,
estimate_gas_acceptable_overestimation: 1000,
estimate_gas_optimize_search: false,
max_tx_size: 1000000,
Expand Down
2 changes: 1 addition & 1 deletion core/node/api_server/src/tx_sender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ impl TxSender {
}

// For now, both L1 gas price and pubdata price are scaled with the same coefficient
async fn scaled_batch_fee_input(&self) -> anyhow::Result<BatchFeeInput> {
pub(crate) async fn scaled_batch_fee_input(&self) -> anyhow::Result<BatchFeeInput> {
self.0
.batch_fee_input_provider
.get_batch_fee_input_scaled(
Expand Down
23 changes: 10 additions & 13 deletions core/node/api_server/src/tx_sender/tests/send_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use assert_matches::assert_matches;
use chrono::NaiveDateTime;
use test_casing::test_casing;
use zksync_multivm::interface::{tracer::ValidationTraces, ExecutionResult};
use zksync_node_fee_model::MockBatchFeeParamsProvider;
use zksync_node_fee_model::{BatchFeeModelInputProvider, MockBatchFeeParamsProvider};
use zksync_node_test_utils::create_l2_transaction;
use zksync_types::K256PrivateKey;

Expand All @@ -22,10 +22,9 @@ async fn submitting_tx_requires_one_connection() {
.unwrap();

let l2_chain_id = L2ChainId::default();
let fee_input = MockBatchFeeParamsProvider::default()
.get_batch_fee_input_scaled(1.0, 1.0)
.await
.unwrap();
let fee_params_provider: &dyn BatchFeeModelInputProvider =
&MockBatchFeeParamsProvider::default();
let fee_input = fee_params_provider.get_batch_fee_input().await.unwrap();
let (base_fee, gas_per_pubdata) =
derive_base_fee_and_gas_per_pubdata(fee_input, ProtocolVersionId::latest().into());
let tx = create_l2_transaction(base_fee, gas_per_pubdata);
Expand Down Expand Up @@ -130,10 +129,9 @@ async fn fee_validation_errors() {
let l2_chain_id = L2ChainId::default();
let tx_executor = SandboxExecutor::mock(MockOneshotExecutor::default()).await;
let (tx_sender, _) = create_test_tx_sender(pool.clone(), l2_chain_id, tx_executor).await;
let fee_input = MockBatchFeeParamsProvider::default()
.get_batch_fee_input_scaled(1.0, 1.0)
.await
.unwrap();
let fee_params_provider: &dyn BatchFeeModelInputProvider =
&MockBatchFeeParamsProvider::default();
let fee_input = fee_params_provider.get_batch_fee_input().await.unwrap();
let (base_fee, gas_per_pubdata) =
derive_base_fee_and_gas_per_pubdata(fee_input, ProtocolVersionId::latest().into());
let tx = create_l2_transaction(base_fee, gas_per_pubdata);
Expand Down Expand Up @@ -322,10 +320,9 @@ async fn submit_tx_with_validation_traces(actual_range: Range<u64>, expected_ran
.unwrap();

let l2_chain_id = L2ChainId::default();
let fee_input = MockBatchFeeParamsProvider::default()
.get_batch_fee_input_scaled(1.0, 1.0)
.await
.unwrap();
let fee_params_provider: &dyn BatchFeeModelInputProvider =
&MockBatchFeeParamsProvider::default();
let fee_input = fee_params_provider.get_batch_fee_input().await.unwrap();
let (base_fee, gas_per_pubdata) =
derive_base_fee_and_gas_per_pubdata(fee_input, ProtocolVersionId::latest().into());
let tx = create_l2_transaction(base_fee, gas_per_pubdata);
Expand Down
7 changes: 1 addition & 6 deletions core/node/api_server/src/web3/namespaces/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,7 @@ impl DebugNamespace {
// It is important to drop a DB connection before calling the provider, since it acquires a connection internally
// on the main node.
drop(connection);
let scale_factor = self.state.api_config.estimate_gas_scale_factor;
let fee_input_provider = &self.state.tx_sender.0.batch_fee_input_provider;
// For now, the same scaling is used for both the L1 gas price and the pubdata price
fee_input_provider
.get_batch_fee_input_scaled(scale_factor, scale_factor)
.await?
self.state.tx_sender.scaled_batch_fee_input().await?
} else {
let fee_input = block_args.historical_fee_input(&mut connection).await?;
drop(connection);
Expand Down

0 comments on commit 7ace594

Please sign in to comment.