Skip to content

Commit

Permalink
cr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sunce86 committed Mar 6, 2025
1 parent dc64c22 commit aa73d01
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions crates/driver/src/infra/blockchain/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type AdditionalTip = (MaxAdditionalTip, AdditionalTipPercentage);
pub struct GasPriceEstimator {
//TODO: remove visibility once boundary is removed
pub(super) gas: Arc<dyn GasPriceEstimating>,
additional_tip: Option<AdditionalTip>,
additional_tip: AdditionalTip,
max_fee_per_gas: eth::U256,
min_priority_fee: eth::U256,
}
Expand Down Expand Up @@ -53,7 +53,8 @@ impl GasPriceEstimator {
..
} => (max_additional_tip, additional_tip_percentage),
})
.next();
.next()
.unwrap_or((eth::U256::zero(), 0.));
// Use the lowest max_fee_per_gas of all mempools as the max_fee_per_gas
let max_fee_per_gas = mempools
.iter()
Expand Down Expand Up @@ -84,24 +85,19 @@ impl GasPriceEstimator {
.estimate()
.await
.map(|estimate| {
let additional_tip = self
.additional_tip
.map(|(max_additional_tip, additional_tip_percentage)| {
max_additional_tip
.to_f64_lossy()
.min(estimate.max_fee_per_gas * additional_tip_percentage)
})
.map(eth::U256::from_f64_lossy)
.unwrap_or(eth::U256::zero());
let (max, percentage) = self.additional_tip;
let additional_tip = max
.to_f64_lossy()
.min(estimate.max_fee_per_gas * percentage);

let tip = std::cmp::max(
self.min_priority_fee,
eth::U256::from_f64_lossy(estimate.max_priority_fee_per_gas),
self.min_priority_fee + eth::U256::from_f64_lossy(additional_tip),
eth::U256::from_f64_lossy(estimate.max_priority_fee_per_gas + additional_tip),
);

eth::GasPrice::new(
self.max_fee_per_gas.into(),
(tip + additional_tip).into(),
tip.into(),
eth::U256::from_f64_lossy(estimate.base_fee_per_gas).into(),
)
})
Expand Down

0 comments on commit aa73d01

Please sign in to comment.