Skip to content

Commit

Permalink
add base fee cap for eth_sender
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-nguy committed Jul 8, 2024
1 parent 91740ac commit 8019661
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions core/lib/config/src/configs/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl EthConfig {
max_acceptable_priority_fee_in_gwei: 100000000000,
proof_loading_mode: ProofLoadingMode::OldProofFromDb,
pubdata_sending_mode: PubdataSendingMode::Calldata,
max_acceptable_base_fee_in_wei: 100000000000,
}),
gas_adjuster: Some(GasAdjusterConfig {
default_priority_fee_per_gas: 1000000000,
Expand Down Expand Up @@ -122,6 +123,9 @@ pub struct SenderConfig {

/// The mode in which we send pubdata, either Calldata or Blobs
pub pubdata_sending_mode: PubdataSendingMode,

/// Max acceptable base fee the sender is allowed to use to send L1 txs.
pub max_acceptable_base_fee_in_wei: u64,
}

impl SenderConfig {
Expand Down
1 change: 1 addition & 0 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ impl Distribution<configs::eth_sender::SenderConfig> for EncodeDist {
max_acceptable_priority_fee_in_gwei: self.sample(rng),
proof_loading_mode: self.sample(rng),
pubdata_sending_mode: PubdataSendingMode::Calldata,
max_acceptable_base_fee_in_wei: self.sample(rng),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/lib/env_config/src/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ mod tests {
max_acceptable_priority_fee_in_gwei: 100_000_000_000,
proof_loading_mode: ProofLoadingMode::OldProofFromDb,
pubdata_sending_mode: PubdataSendingMode::Calldata,
max_acceptable_base_fee_in_wei: 100_000_000_000,
}),
gas_adjuster: Some(GasAdjusterConfig {
default_priority_fee_per_gas: 20000000000,
Expand Down Expand Up @@ -124,6 +125,7 @@ mod tests {
ETH_SENDER_SENDER_PROOF_LOADING_MODE="OldProofFromDb"
ETH_SENDER_SENDER_PUBDATA_SENDING_MODE="Calldata"
ETH_CLIENT_WEB3_URL="http://127.0.0.1:8545"
ETH_SENDER_SENDER_MAX_ACCEPTABLE_BASE_FEE_IN_WEI="100000000000"
"#;
lock.set_env(config);
Expand Down
3 changes: 3 additions & 0 deletions core/lib/protobuf_config/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ impl ProtoRepr for proto::Sender {
.and_then(|x| Ok(proto::ProofLoadingMode::try_from(*x)?))
.context("proof_loading_mode")?
.parse(),
max_acceptable_base_fee_in_wei: *required(&self.max_acceptable_base_fee_in_wei)
.context("max_acceptable_base_fee_in_wei")?,
})
}

Expand Down Expand Up @@ -167,6 +169,7 @@ impl ProtoRepr for proto::Sender {
proto::PubdataSendingMode::new(&this.pubdata_sending_mode).into(),
),
proof_loading_mode: Some(proto::ProofLoadingMode::new(&this.proof_loading_mode).into()),
max_acceptable_base_fee_in_wei: Some(this.max_acceptable_base_fee_in_wei),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions core/lib/protobuf_config/src/proto/config/eth_sender.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ message Sender {
optional uint64 max_acceptable_priority_fee_in_gwei = 16; // required; gwei
optional PubdataSendingMode pubdata_sending_mode = 18; // required
optional ProofLoadingMode proof_loading_mode = 19;
optional uint64 max_acceptable_base_fee_in_wei = 100; // required; wei
}

message GasAdjuster {
Expand Down
23 changes: 19 additions & 4 deletions core/node/eth_sender/src/eth_tx_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,17 @@ impl EthTxManager {
blob_base_fee_per_gas,
} = self.calculate_fee(storage, tx, time_in_mempool).await?;

METRICS.used_base_fee_per_gas.observe(base_fee_per_gas);
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
);
}

METRICS.used_base_fee_per_gas.observe(base_fee_per_gas_cap);
METRICS
.used_priority_fee_per_gas
.observe(priority_fee_per_gas);
Expand All @@ -260,7 +270,12 @@ impl EthTxManager {
};

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

if let Some(blob_sidecar) = &tx.blob_sidecar {
Expand All @@ -274,7 +289,7 @@ impl EthTxManager {
.eth_sender_dal()
.insert_tx_history(
tx.id,
base_fee_per_gas,
base_fee_per_gas_cap,
priority_fee_per_gas,
blob_base_fee_per_gas,
signed_tx.hash,
Expand All @@ -290,7 +305,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,
base_fee_per_gas_cap,
priority_fee_per_gas,
error
);
Expand Down
3 changes: 3 additions & 0 deletions etc/env/base/eth_sender.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ proof_loading_mode="FriProofFromGcs"

pubdata_sending_mode = "Blobs"

# 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
Expand Down
1 change: 1 addition & 0 deletions etc/env/file_based/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8019661

Please sign in to comment.