Skip to content

Commit

Permalink
update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
faheelsattar committed Jan 14, 2025
1 parent 8e39500 commit 684475a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
9 changes: 6 additions & 3 deletions bolt-sidecar/src/primitives/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl InclusionRequest {
preconfirmed_gas: u64,
min_inclusion_profit: u64,
max_base_fee: u128,
) -> Result<(bool, u128, u128), PricingError> {
) -> Result<bool, PricingError> {
// Each included tx will move the price up
// So we need to calculate the minimum priority fee for each tx
let mut local_preconfirmed_gas = preconfirmed_gas;
Expand All @@ -197,12 +197,15 @@ impl InclusionRequest {

let tip = tx.effective_tip_per_gas(max_base_fee).unwrap_or_default();
if tip < min_priority_fee as u128 {
return Ok((false, tip, min_priority_fee as u128));
return Err(PricingError::TipTooLow {
tip,
min_priority_fee: min_priority_fee as u128,
});
}
// Increment the preconfirmed gas for the next transaction in the bundle
local_preconfirmed_gas = local_preconfirmed_gas.saturating_add(tx.gas_limit());
}
Ok((true, 0, 0))
Ok(true)
}

/// Returns the total gas limit of all transactions in this request.
Expand Down
12 changes: 8 additions & 4 deletions bolt-sidecar/src/state/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,18 @@ impl<C: StateFetcher> ExecutionState<C> {

// Ensure max_priority_fee_per_gas is greater than or equal to the calculated
// min_priority_fee
let (validated, tip, min_priority_fee) = req.validate_min_priority_fee(
if let Err(err) = req.validate_min_priority_fee(
&self.pricing,
template_committed_gas,
self.limits.min_inclusion_profit,
max_basefee,
)?;
if !validated {
return Err(ValidationError::MaxPriorityFeePerGasTooLow(tip, min_priority_fee));
) {
return Err(match err {
pricing::PricingError::TipTooLow { tip, min_priority_fee } => {
ValidationError::MaxPriorityFeePerGasTooLow(tip, min_priority_fee)
}
other => ValidationError::Pricing(other),
});
}

if target_slot < self.slot {
Expand Down
13 changes: 11 additions & 2 deletions bolt-sidecar/src/state/pricing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ pub enum PricingError {
/// Gas required by the incoming transaction
incoming_gas: u64,
},

/// Tip is too low for the required minimum priority fee
#[error("Tip {tip} is too low. Minimum required priority fee is {min_priority_fee}")]
TipTooLow {
/// Tip provided by the transaction
tip: u128,
/// The minimum priority fee required
min_priority_fee: u128,
},
}

impl Default for InclusionPricer {
Expand Down Expand Up @@ -83,8 +92,8 @@ impl InclusionPricer {
let after_gas = remaining_gas - incoming_gas;

// Calculate numerator and denominator for the logarithm
let fraction = (self.gas_scalar * (remaining_gas as f64) + 1.0) /
(self.gas_scalar * (after_gas as f64) + 1.0);
let fraction = (self.gas_scalar * (remaining_gas as f64) + 1.0)
/ (self.gas_scalar * (after_gas as f64) + 1.0);

// Calculate block space value in Ether
let block_space_value = self.base_multiplier * fraction.ln();
Expand Down

0 comments on commit 684475a

Please sign in to comment.