Skip to content

Commit

Permalink
Merge pull request #660 from faheelsattar/faheelsattar/return-fee-in-…
Browse files Browse the repository at this point in the history
…error

chore(bolt-sidecar): add params in err message
  • Loading branch information
thedevbirb authored Jan 15, 2025
2 parents 7b2fbd0 + bbf291c commit bb3287a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
5 changes: 4 additions & 1 deletion bolt-sidecar/src/primitives/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ 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);
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());
Expand Down
21 changes: 13 additions & 8 deletions bolt-sidecar/src/state/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub enum ValidationError {
#[error("Max priority fee per gas is greater than max fee per gas")]
MaxPriorityFeePerGasTooHigh,
/// Max priority fee per gas is less than min priority fee.
#[error("Max priority fee per gas is less than min priority fee")]
MaxPriorityFeePerGasTooLow,
#[error("Max priority fee per gas {0} is less than min priority fee {1}")]
MaxPriorityFeePerGasTooLow(u128, u128),
/// The sender does not have enough balance to pay for the transaction.
#[error("Not enough balance to pay for value + maximum fee")]
InsufficientBalance,
Expand Down Expand Up @@ -113,7 +113,7 @@ impl ValidationError {
Self::GasLimitTooHigh => "gas_limit_too_high",
Self::TransactionSizeTooHigh => "transaction_size_too_high",
Self::MaxPriorityFeePerGasTooHigh => "max_priority_fee_per_gas_too_high",
Self::MaxPriorityFeePerGasTooLow => "max_priority_fee_per_gas_too_low",
Self::MaxPriorityFeePerGasTooLow(_, _) => "max_priority_fee_per_gas_too_low",
Self::InsufficientBalance => "insufficient_balance",
Self::Pricing(_) => "pricing",
Self::Eip4844Limit => "eip4844_limit",
Expand Down Expand Up @@ -311,13 +311,18 @@ impl<C: StateFetcher> ExecutionState<C> {

// Ensure max_priority_fee_per_gas is greater than or equal to the calculated
// min_priority_fee
if !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,
)? {
return Err(ValidationError::MaxPriorityFeePerGasTooLow);
) {
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 Expand Up @@ -967,7 +972,7 @@ mod tests {

assert!(matches!(
state.validate_request(&mut request).await,
Err(ValidationError::MaxPriorityFeePerGasTooLow)
Err(ValidationError::MaxPriorityFeePerGasTooLow(_, _))
));

// Create a transaction with a max priority fee that is correct
Expand Down Expand Up @@ -1010,7 +1015,7 @@ mod tests {

assert!(matches!(
state.validate_request(&mut request).await,
Err(ValidationError::MaxPriorityFeePerGasTooLow)
Err(ValidationError::MaxPriorityFeePerGasTooLow(_, _))
));

// Create a transaction with a gas price that is correct
Expand Down
9 changes: 9 additions & 0 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

0 comments on commit bb3287a

Please sign in to comment.