Skip to content

Commit b69451e

Browse files
committed
refactor gas calculation funcs
1 parent 62a675c commit b69451e

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/tasks/submit.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ impl SubmitTask {
417417

418418
// Retry loop
419419
let result = loop {
420-
// Log the retry attempt
421420
let span = debug_span!("SubmitTask::retrying_handle_inbound", retries);
422421

423422
let inbound_result =
@@ -431,6 +430,7 @@ impl SubmitTask {
431430
debug!(slot_number, "403 detected - skipping slot");
432431
return Ok(ControlFlow::Skip);
433432
} else {
433+
// Otherwise, log error and retry
434434
error!(error = %err, "error handling inbound block");
435435
}
436436

@@ -515,7 +515,7 @@ impl SubmitTask {
515515

516516
// Only attempt each block number once
517517
if result.block.block_number() == last_block_attempted {
518-
debug!("block number is unchanged from last attempt - skipping");
518+
debug!(block_number = result.block.block_number(), "block number is unchanged from last attempt - skipping");
519519
continue;
520520
}
521521

@@ -541,20 +541,25 @@ impl SubmitTask {
541541

542542
/// Calculates gas parameters based on the block environment and retry count.
543543
fn calculate_gas(retry_count: usize, block_env: &BlockEnv) -> (u128, u128, u128) {
544-
if let Some(blob_excess) = block_env.blob_excess_gas_and_price {
545-
debug!(?blob_excess, "using blob excess gas and price from block env");
546-
let blob_basefee = blob_excess.blob_gasprice;
547-
548-
let (max_fee_per_gas, max_priority_fee_per_gas, max_fee_per_blob_gas) =
549-
bump_gas_from_retries(retry_count, block_env.basefee, blob_basefee);
550-
551-
(max_fee_per_gas as u128, max_priority_fee_per_gas as u128, max_fee_per_blob_gas)
552-
} else {
553-
warn!("no blob excess gas and price in block env, using defaults");
554-
let (max_fee_per_gas, max_priority_fee_per_gas, max_fee_per_blob_gas) =
555-
bump_gas_from_retries(retry_count, block_env.basefee, 500);
544+
let fallback_blob_basefee = 500;
545+
546+
match block_env.blob_excess_gas_and_price {
547+
Some(excess) => {
548+
if excess.blob_gasprice == 0 {
549+
warn!("blob excess gas price is zero, using default blob base fee");
550+
return bump_gas_from_retries(
551+
retry_count,
552+
block_env.basefee,
553+
fallback_blob_basefee,
554+
);
555+
}
556556

557-
(max_fee_per_gas as u128, max_priority_fee_per_gas as u128, max_fee_per_blob_gas)
557+
bump_gas_from_retries(retry_count, block_env.basefee, excess.blob_gasprice)
558+
}
559+
None => {
560+
warn!("no blob excess gas and price in block env, using defaults");
561+
bump_gas_from_retries(retry_count, block_env.basefee, fallback_blob_basefee)
562+
}
558563
}
559564
}
560565

@@ -563,23 +568,23 @@ pub fn bump_gas_from_retries(
563568
retry_count: usize,
564569
basefee: u64,
565570
blob_basefee: u128,
566-
) -> (u64, u64, u128) {
571+
) -> (u128, u128, u128) {
567572
const PRIORITY_FEE_BASE: u64 = 2 * GWEI_TO_WEI;
568-
const BASE_MULTIPLIER: u64 = 2;
573+
const BASE_MULTIPLIER: u128 = 2;
569574
const BLOB_MULTIPLIER: u128 = 2;
570575

571576
// Increase priority fee by 20% per retry
572577
let priority_fee =
573578
PRIORITY_FEE_BASE * (12u64.pow(retry_count as u32) / 10u64.pow(retry_count as u32));
574579

575580
// Max fee includes basefee + priority + headroom (double basefee, etc.)
576-
let max_fee_per_gas = basefee * BASE_MULTIPLIER + priority_fee;
581+
let max_fee_per_gas = (basefee as u128) * BASE_MULTIPLIER + (priority_fee as u128);
577582
let max_fee_per_blob_gas = blob_basefee * BLOB_MULTIPLIER * (retry_count as u128 + 1);
578583

579584
debug!(
580585
retry_count,
581586
max_fee_per_gas, priority_fee, max_fee_per_blob_gas, "calculated bumped gas parameters"
582587
);
583588

584-
(max_fee_per_gas, priority_fee, max_fee_per_blob_gas)
589+
(max_fee_per_gas as u128, priority_fee as u128, max_fee_per_blob_gas)
585590
}

0 commit comments

Comments
 (0)