Skip to content

Commit

Permalink
cap priority fee per gas
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Jul 10, 2024
1 parent df64db6 commit c99e25f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
4 changes: 1 addition & 3 deletions core/lib/config/src/configs/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,11 @@ pub struct SenderConfig {
/// The mode in which we send pubdata, either Calldata or Blobs
pub pubdata_sending_mode: PubdataSendingMode,

<<<<<<< HEAD
/// 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,
>>>>>>> 80196613 (add base fee cap for eth_sender)
}

impl SenderConfig {
Expand Down
2 changes: 2 additions & 0 deletions core/node/eth_sender/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
28 changes: 12 additions & 16 deletions core/node/eth_sender/src/eth_tx_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -244,17 +245,17 @@ impl EthTxManager {
blob_base_fee_per_gas,
} = self.calculate_fee(storage, tx, time_in_mempool).await?;

let mut base_fee_per_gas_cap = base_fee_per_gas;
if base_fee_per_gas_cap > self.config.max_acceptable_base_fee_in_wei {
base_fee_per_gas_cap = self.config.max_acceptable_base_fee_in_wei;
tracing::debug!(
"initial base_fee {}, max reached and cap to {}",
base_fee_per_gas,
base_fee_per_gas_cap
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_cap);
METRICS.used_base_fee_per_gas.observe(base_fee_per_gas);
METRICS
.used_priority_fee_per_gas
.observe(priority_fee_per_gas);
Expand All @@ -270,12 +271,7 @@ impl EthTxManager {
};

let mut signed_tx = self
.sign_tx(
tx,
base_fee_per_gas_cap,
priority_fee_per_gas,
blob_gas_price,
)
.sign_tx(tx, base_fee_per_gas, priority_fee_per_gas, blob_gas_price)
.await;

if let Some(blob_sidecar) = &tx.blob_sidecar {
Expand All @@ -289,7 +285,7 @@ impl EthTxManager {
.eth_sender_dal()
.insert_tx_history(
tx.id,
base_fee_per_gas_cap,
base_fee_per_gas,
priority_fee_per_gas,
blob_base_fee_per_gas,
signed_tx.hash,
Expand All @@ -305,7 +301,7 @@ impl EthTxManager {
tracing::warn!(
"Error when sending new signed tx for tx {}, base_fee_per_gas {}, priority_fee_per_gas: {}: {}",
tx.id,
base_fee_per_gas_cap,
base_fee_per_gas,
priority_fee_per_gas,
error
);
Expand Down

0 comments on commit c99e25f

Please sign in to comment.