Skip to content

Commit 019e4bb

Browse files
change the logic to have a fixed priority fee in gwei by config
1 parent 01d25d6 commit 019e4bb

4 files changed

Lines changed: 34 additions & 62 deletions

File tree

aggregation_mode/proof_aggregator/src/backend/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ pub struct Config {
2424
pub max_bump_retries: u16,
2525
pub bump_retry_interval_seconds: u64,
2626
pub base_bump_percentage: u64,
27-
pub retry_attempt_percentage: u64,
27+
pub max_fee_bump_percentage: u64,
28+
pub priority_fee_gwei: u128,
2829
}
2930

3031
impl Config {

aggregation_mode/proof_aggregator/src/backend/mod.rs

Lines changed: 28 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use alloy::{
2525
network::{EthereumWallet, TransactionBuilder},
2626
primitives::{utils::parse_ether, Address, U256},
2727
providers::{PendingTransactionError, Provider, ProviderBuilder},
28-
rpc::types::TransactionReceipt,
28+
rpc::types::{TransactionReceipt, TransactionRequest},
2929
signers::local::LocalSigner,
3030
};
3131
use config::Config;
@@ -391,7 +391,8 @@ impl ProofAggregator {
391391
) -> Result<TransactionReceipt, AggregatedProofSubmissionError> {
392392
let retry_interval = Duration::from_secs(self.config.bump_retry_interval_seconds);
393393
let base_bump_percentage = self.config.base_bump_percentage;
394-
let retry_attempt_percentage = self.config.retry_attempt_percentage;
394+
let max_fee_bump_percentage = self.config.max_fee_bump_percentage;
395+
let priority_fee_gwei = self.config.priority_fee_gwei;
395396

396397
// Build the transaction request
397398
let mut tx_req = match aggregated_proof {
@@ -426,8 +427,8 @@ impl ProofAggregator {
426427
tx_req = self
427428
.apply_gas_fee_bump(
428429
base_bump_percentage,
429-
retry_attempt_percentage,
430-
attempt,
430+
max_fee_bump_percentage,
431+
priority_fee_gwei,
431432
tx_req,
432433
)
433434
.await?;
@@ -500,70 +501,38 @@ impl ProofAggregator {
500501
}
501502
}
502503

503-
// Updates the gas fees of a `TransactionRequest` for retry attempts by applying a linear fee
504-
// bump based on the retry number. This method is intended to be used when a previous transaction
505-
// attempt was not confirmed (e.g. receipt timeout or transient failure).
504+
// Updates the gas fees of a `TransactionRequest` using a fixed bump strategy.
505+
// Intended for retrying an on-chain submission after a timeout.
506506
//
507-
// Fee strategy (similar to Go implementation):
508-
// The bump is calculated as: base_bump_percentage + (retry_count * retry_attempt_percentage)
509-
// For example, with `base_bump_percentage = 10` and `retry_attempt_percentage = 5`:
510-
// - `attempt = 1` → 10% + (1 * 5%) = 15% bump
511-
// - `attempt = 2` → 10% + (2 * 5%) = 20% bump
512-
// - `attempt = 3` → 10% + (3 * 5%) = 25% bump
507+
// Strategy:
508+
// - Fetch the current network gas price.
509+
// - Apply `base_bump_percentage` to compute a bumped base fee.
510+
// - Apply `max_fee_bump_percentage` on top of the bumped base fee to set `max_fee_per_gas`.
511+
// - Set `max_priority_fee_per_gas` to a fixed value derived from `priority_fee_gwei`.
513512
//
514-
// The bumped price is: current_gas_price * (1 + total_bump_percentage / 100)
513+
// Fees are recomputed on each retry using the latest gas price (no incremental per-attempt bump).
514+
515515
async fn apply_gas_fee_bump(
516516
&self,
517517
base_bump_percentage: u64,
518-
retry_attempt_percentage: u64,
519-
attempt: u64,
520-
tx_req: alloy::rpc::types::TransactionRequest,
521-
) -> Result<alloy::rpc::types::TransactionRequest, AggregatedProofSubmissionError> {
518+
max_fee_bump_percentage: u64,
519+
priority_fee_gwei: u128,
520+
tx_req: TransactionRequest,
521+
) -> Result<TransactionRequest, AggregatedProofSubmissionError> {
522522
let provider = self.proof_aggregation_service.provider();
523523

524-
// Calculate total bump percentage: base + (retry_count * retry_attempt)
525-
let incremental_retry_percentage = retry_attempt_percentage * attempt;
526-
let total_bump_percentage = base_bump_percentage + incremental_retry_percentage;
527-
528-
info!(
529-
"Applying {}% gas fee bump for attempt {}",
530-
total_bump_percentage,
531-
attempt + 1
532-
);
533-
534-
let mut current_tx_req = tx_req.clone();
535-
536-
if current_tx_req.max_fee_per_gas.is_none() {
537-
let current_gas_price = provider
538-
.get_gas_price()
539-
.await
540-
.map_err(|e| AggregatedProofSubmissionError::GasPriceError(e.to_string()))?;
541-
542-
let new_max_fee =
543-
Self::calculate_bumped_price(current_gas_price, total_bump_percentage);
544-
let new_priority_fee = new_max_fee / 10;
545-
546-
current_tx_req = current_tx_req
547-
.with_max_fee_per_gas(new_max_fee)
548-
.with_max_priority_fee_per_gas(new_priority_fee);
549-
} else {
550-
if let Some(max_fee) = current_tx_req.max_fee_per_gas {
551-
let new_max_fee = Self::calculate_bumped_price(max_fee, total_bump_percentage);
552-
current_tx_req = current_tx_req.with_max_fee_per_gas(new_max_fee);
553-
}
554-
if let Some(priority_fee) = current_tx_req.max_priority_fee_per_gas {
555-
let new_priority_fee =
556-
Self::calculate_bumped_price(priority_fee, total_bump_percentage);
557-
current_tx_req = current_tx_req.with_max_priority_fee_per_gas(new_priority_fee);
558-
}
559-
}
524+
let current_gas_price = provider
525+
.get_gas_price()
526+
.await
527+
.map_err(|e| AggregatedProofSubmissionError::GasPriceError(e.to_string()))?;
560528

561-
Ok(current_tx_req)
562-
}
529+
let new_base_fee = current_gas_price * (1 + base_bump_percentage as u128 / 100);
530+
let new_max_fee = new_base_fee * (1 + max_fee_bump_percentage as u128 / 100);
531+
let new_priority_fee = priority_fee_gwei * 1000000000; // Convert to wei
563532

564-
fn calculate_bumped_price(current_price: u128, total_bump_percentage: u64) -> u128 {
565-
let bump_amount = (current_price * total_bump_percentage as u128) / 100;
566-
current_price + bump_amount
533+
Ok(tx_req
534+
.with_max_fee_per_gas(new_max_fee)
535+
.with_max_priority_fee_per_gas(new_priority_fee))
567536
}
568537

569538
async fn wait_until_can_submit_aggregated_proof(

config-files/config-proof-aggregator-ethereum-package.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ risc0_chunk_aggregator_image_id: "8908f01022827e80a5de71908c16ee44f4a467236df20f
3131
max_bump_retries: 5
3232
bump_retry_interval_seconds: 120
3333
base_bump_percentage: 10
34-
retry_attempt_percentage: 2
34+
max_fee_bump_percentage: 100
35+
priority_fee_gwei: 2
3536

3637
ecdsa:
3738
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"

config-files/config-proof-aggregator.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ risc0_chunk_aggregator_image_id: "8908f01022827e80a5de71908c16ee44f4a467236df20f
3131
max_bump_retries: 5
3232
bump_retry_interval_seconds: 120
3333
base_bump_percentage: 10
34-
retry_attempt_percentage: 2
34+
max_fee_bump_percentage: 100
35+
priority_fee_gwei: 2
3536

3637
ecdsa:
3738
private_key_store_path: "config-files/anvil.proof-aggregator.ecdsa.key.json"

0 commit comments

Comments
 (0)