From 7ace594fb3140212bd94ffd6bffcac99805cf4b1 Mon Sep 17 00:00:00 2001 From: Daniyar Itegulov Date: Fri, 6 Dec 2024 01:30:55 +1100 Subject: [PATCH] fix(api): batch fee input scaling for `debug_traceCall` (#3344) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 - [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`. --- core/lib/config/src/configs/api.rs | 2 +- core/node/api_server/src/tx_sender/mod.rs | 2 +- .../api_server/src/tx_sender/tests/send_tx.rs | 23 ++++++++----------- .../api_server/src/web3/namespaces/debug.rs | 7 +----- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/core/lib/config/src/configs/api.rs b/core/lib/config/src/configs/api.rs index ce0d96129584..1321f25e7604 100644 --- a/core/lib/config/src/configs/api.rs +++ b/core/lib/config/src/configs/api.rs @@ -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, diff --git a/core/node/api_server/src/tx_sender/mod.rs b/core/node/api_server/src/tx_sender/mod.rs index 76cfb83aec54..4c98fc7c455c 100644 --- a/core/node/api_server/src/tx_sender/mod.rs +++ b/core/node/api_server/src/tx_sender/mod.rs @@ -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 { + pub(crate) async fn scaled_batch_fee_input(&self) -> anyhow::Result { self.0 .batch_fee_input_provider .get_batch_fee_input_scaled( diff --git a/core/node/api_server/src/tx_sender/tests/send_tx.rs b/core/node/api_server/src/tx_sender/tests/send_tx.rs index c861f04a832e..c0b02e45ad89 100644 --- a/core/node/api_server/src/tx_sender/tests/send_tx.rs +++ b/core/node/api_server/src/tx_sender/tests/send_tx.rs @@ -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; @@ -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); @@ -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); @@ -322,10 +320,9 @@ async fn submit_tx_with_validation_traces(actual_range: Range, 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); diff --git a/core/node/api_server/src/web3/namespaces/debug.rs b/core/node/api_server/src/web3/namespaces/debug.rs index 4fd32c1b5223..d96c1e659541 100644 --- a/core/node/api_server/src/web3/namespaces/debug.rs +++ b/core/node/api_server/src/web3/namespaces/debug.rs @@ -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);