diff --git a/core/lib/config/src/configs/eth_sender.rs b/core/lib/config/src/configs/eth_sender.rs index 347c2cfcb..e3afd843b 100644 --- a/core/lib/config/src/configs/eth_sender.rs +++ b/core/lib/config/src/configs/eth_sender.rs @@ -43,6 +43,7 @@ impl EthConfig { proof_loading_mode: ProofLoadingMode::OldProofFromDb, pubdata_sending_mode: PubdataSendingMode::Calldata, signing_mode: SigningMode::PrivateKey, + max_acceptable_base_fee_in_wei: 100000000000, }), gas_adjuster: Some(GasAdjusterConfig { default_priority_fee_per_gas: 1000000000, @@ -133,6 +134,9 @@ pub struct SenderConfig { /// Type of signing client for Ethereum transactions. pub signing_mode: SigningMode, + + /// Max acceptable base fee the sender is allowed to use to send L1 txs. + pub max_acceptable_base_fee_in_wei: u64, } impl SenderConfig { diff --git a/core/lib/config/src/testonly.rs b/core/lib/config/src/testonly.rs index 87b77cbc7..e0f4e1532 100644 --- a/core/lib/config/src/testonly.rs +++ b/core/lib/config/src/testonly.rs @@ -388,6 +388,7 @@ impl Distribution for EncodeDist { proof_loading_mode: self.sample(rng), pubdata_sending_mode: PubdataSendingMode::Calldata, signing_mode: SigningMode::PrivateKey, + max_acceptable_base_fee_in_wei: self.sample(rng), } } } diff --git a/core/lib/dal/sqlx-data.json b/core/lib/dal/sqlx-data.json new file mode 100644 index 000000000..95c8c858b --- /dev/null +++ b/core/lib/dal/sqlx-data.json @@ -0,0 +1,3 @@ +{ + "db": "PostgreSQL" +} \ No newline at end of file diff --git a/core/lib/env_config/src/eth_sender.rs b/core/lib/env_config/src/eth_sender.rs index 90e8d5839..d5cd8b8ce 100644 --- a/core/lib/env_config/src/eth_sender.rs +++ b/core/lib/env_config/src/eth_sender.rs @@ -65,6 +65,7 @@ mod tests { proof_loading_mode: ProofLoadingMode::OldProofFromDb, pubdata_sending_mode: PubdataSendingMode::Calldata, signing_mode: SigningMode::PrivateKey, + max_acceptable_base_fee_in_wei: 100_000_000_000, }), gas_adjuster: Some(GasAdjusterConfig { default_priority_fee_per_gas: 20000000000, @@ -126,6 +127,7 @@ mod tests { ETH_SENDER_SENDER_PUBDATA_SENDING_MODE="Calldata" ETH_SENDER_SENDER_SIGNING_MODE="PrivateKey" ETH_CLIENT_WEB3_URL="http://127.0.0.1:8545" + ETH_SENDER_SENDER_MAX_ACCEPTABLE_BASE_FEE_IN_WEI="100000000000" "#; lock.set_env(config); diff --git a/core/lib/protobuf_config/src/eth.rs b/core/lib/protobuf_config/src/eth.rs index 80fd3c535..c411d6f21 100644 --- a/core/lib/protobuf_config/src/eth.rs +++ b/core/lib/protobuf_config/src/eth.rs @@ -158,6 +158,8 @@ impl ProtoRepr for proto::Sender { .and_then(|x| Ok(proto::SigningMode::try_from(*x)?)) .context("signing_mode")? .parse(), + max_acceptable_base_fee_in_wei: *required(&self.max_acceptable_base_fee_in_wei) + .context("max_acceptable_base_fee_in_wei")?, }) } @@ -190,6 +192,7 @@ impl ProtoRepr for proto::Sender { ), proof_loading_mode: Some(proto::ProofLoadingMode::new(&this.proof_loading_mode).into()), signing_mode: Some(proto::SigningMode::new(&this.signing_mode).into()), + max_acceptable_base_fee_in_wei: Some(this.max_acceptable_base_fee_in_wei), } } } diff --git a/core/lib/protobuf_config/src/proto/config/eth_sender.proto b/core/lib/protobuf_config/src/proto/config/eth_sender.proto index c616532c6..1d8cf10bc 100644 --- a/core/lib/protobuf_config/src/proto/config/eth_sender.proto +++ b/core/lib/protobuf_config/src/proto/config/eth_sender.proto @@ -50,6 +50,7 @@ message Sender { optional PubdataSendingMode pubdata_sending_mode = 18; // required optional ProofLoadingMode proof_loading_mode = 19; optional SigningMode signing_mode = 99; // required + optional uint64 max_acceptable_base_fee_in_wei = 100; // required; wei } message GasAdjuster { diff --git a/core/node/eth_sender/src/error.rs b/core/node/eth_sender/src/error.rs index 206bbf2d5..883cc0a89 100644 --- a/core/node/eth_sender/src/error.rs +++ b/core/node/eth_sender/src/error.rs @@ -6,4 +6,6 @@ pub enum ETHSenderError { EthereumGateWayError(#[from] zksync_eth_client::Error), #[error("Token parsing Error: {0}")] ParseError(#[from] contract::Error), + #[error("Max base fee exceeded")] + ExceedMaxBaseFee, } diff --git a/core/node/eth_sender/src/eth_tx_manager.rs b/core/node/eth_sender/src/eth_tx_manager.rs index 5570d3bd6..fe387c332 100644 --- a/core/node/eth_sender/src/eth_tx_manager.rs +++ b/core/node/eth_sender/src/eth_tx_manager.rs @@ -19,6 +19,7 @@ use zksync_types::{ use zksync_utils::time::seconds_since_epoch; use super::{metrics::METRICS, ETHSenderError}; +use crate::ETHSenderError::ExceedMaxBaseFee; #[derive(Debug)] struct EthFee { @@ -244,6 +245,16 @@ impl EthTxManager { blob_base_fee_per_gas, } = self.calculate_fee(storage, tx, time_in_mempool).await?; + if base_fee_per_gas > self.config.max_acceptable_base_fee_in_wei { + tracing::info!( + "base fee per gas: {} exceed max acceptable fee in configuration: {}, skip transaction", + base_fee_per_gas, + self.config.max_acceptable_base_fee_in_wei + ); + + return Err(ExceedMaxBaseFee); + } + METRICS.used_base_fee_per_gas.observe(base_fee_per_gas); METRICS .used_priority_fee_per_gas diff --git a/etc/env/base/eth_sender.toml b/etc/env/base/eth_sender.toml index bffaf9e90..4ad23ae67 100644 --- a/etc/env/base/eth_sender.toml +++ b/etc/env/base/eth_sender.toml @@ -52,6 +52,9 @@ pubdata_sending_mode = "Blobs" signing_mode = "PrivateKey" +# Max acceptable base fee for sending tx to L1 +max_acceptable_base_fee_in_wei = 1000000000000 + [eth_sender.gas_adjuster] # Priority fee to be used by GasAdjuster (in wei). default_priority_fee_per_gas = 1_000_000_000 diff --git a/etc/env/file_based/general.yaml b/etc/env/file_based/general.yaml index 19adec9b3..8dfd4c485 100644 --- a/etc/env/file_based/general.yaml +++ b/etc/env/file_based/general.yaml @@ -136,6 +136,7 @@ eth: max_acceptable_priority_fee_in_gwei: 100000000000 proof_loading_mode: OLD_PROOF_FROM_DB pubdata_sending_mode: BLOBS + max_acceptable_base_fee_in_wei: 100000000000 gas_adjuster: default_priority_fee_per_gas: 1000000000 max_base_fee_samples: 10000