From 684475adb0ff1b6ee7ad63a9fe727ba2d7b88e39 Mon Sep 17 00:00:00 2001 From: faheelsattar Date: Tue, 14 Jan 2025 19:36:35 +0500 Subject: [PATCH] update error handling --- bolt-sidecar/src/primitives/commitment.rs | 9 ++++++--- bolt-sidecar/src/state/execution.rs | 12 ++++++++---- bolt-sidecar/src/state/pricing.rs | 13 +++++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/bolt-sidecar/src/primitives/commitment.rs b/bolt-sidecar/src/primitives/commitment.rs index 6b8a69c1..06b5b795 100644 --- a/bolt-sidecar/src/primitives/commitment.rs +++ b/bolt-sidecar/src/primitives/commitment.rs @@ -185,7 +185,7 @@ impl InclusionRequest { preconfirmed_gas: u64, min_inclusion_profit: u64, max_base_fee: u128, - ) -> Result<(bool, u128, u128), PricingError> { + ) -> Result { // 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; @@ -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. diff --git a/bolt-sidecar/src/state/execution.rs b/bolt-sidecar/src/state/execution.rs index f1a0299f..df147f5f 100644 --- a/bolt-sidecar/src/state/execution.rs +++ b/bolt-sidecar/src/state/execution.rs @@ -321,14 +321,18 @@ impl ExecutionState { // 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 { diff --git a/bolt-sidecar/src/state/pricing.rs b/bolt-sidecar/src/state/pricing.rs index e4703063..af8a53f7 100644 --- a/bolt-sidecar/src/state/pricing.rs +++ b/bolt-sidecar/src/state/pricing.rs @@ -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 { @@ -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();