Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(da): fix gas price for da gas estimation to be UO gas price #890

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions crates/builder/src/bundle_proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ where
da_gas_oracle.calc_da_gas_sync(
&op.da_gas_data,
da_block_data,
required_op_fees.max_fee_per_gas,
op.uo.gas_price(base_fee),
)
} else {
match self
Expand All @@ -403,7 +403,7 @@ where
.calc_da_gas(
op.uo.clone().into(),
block_hash.into(),
required_op_fees.max_fee_per_gas,
op.uo.gas_price(base_fee),
)
.await
{
Expand Down Expand Up @@ -2512,9 +2512,8 @@ mod tests {
.returning(move |_| Ok(bd_cloned.clone()));
da_oracle
.expect_calc_da_gas_sync()
.returning(move |_, bd, gp| {
.returning(move |_, bd, _| {
assert_eq!(*bd, block_data);
assert_eq!(gp, base_fee + max_priority_fee_per_gas);
100_000
});

Expand Down
13 changes: 8 additions & 5 deletions crates/pool/src/mempool/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ where
let required_da_gas = da_gas_oracle.calc_da_gas_sync(
&op.po.da_gas_data,
block_da_data,
candidate_gas_price,
op.uo().gas_price(base_fee),
);

let required_pvg = op.uo().required_pre_verification_gas(
Expand Down Expand Up @@ -1356,17 +1356,20 @@ mod tests {
conf.chain_spec.da_pre_verification_gas = true;
conf.chain_spec.include_da_gas_in_gas_limit = true;
conf.da_gas_tracking_enabled = true;
let base_fee = 0;

let po1 = create_op(Address::random(), 0, 10);
let po1_gas_price = po1.uo.gas_price(base_fee);
let pvg = po1.uo.pre_verification_gas();
let da_pvg = po1
.uo
.pre_verification_da_gas_limit(&conf.chain_spec, Some(1));

let mut oracle = MockDAGasOracleSync::default();
oracle
.expect_calc_da_gas_sync()
.returning(move |_, _, _| da_pvg + 1);
oracle.expect_calc_da_gas_sync().returning(move |_, _, gp| {
assert_eq!(gp, po1_gas_price);
da_pvg + 1
});

let mut pool = pool_with_conf_oracle(conf.clone(), oracle);

Expand All @@ -1380,7 +1383,7 @@ mod tests {
0.into(),
Some(&DAGasBlockData::default()),
GasFees::default(),
0,
base_fee,
);

assert_eq!(pool.best_operations().collect::<Vec<_>>().len(), 0);
Expand Down
4 changes: 4 additions & 0 deletions crates/provider/src/alloy/da/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ where
block: BlockHashOrNumber,
gas_price: u128,
) -> ProviderResult<(u128, DAGasUOData, DAGasBlockData)> {
if gas_price == 0 {
Err(anyhow::anyhow!("gas price cannot be zero"))?;
}

let l1_fee: u128 = self
.oracle
.getL1Fee(data)
Expand Down
15 changes: 3 additions & 12 deletions crates/sim/src/gas/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
// You should have received a copy of the GNU General Public License along with Rundler.
// If not, see https://www.gnu.org/licenses/.

use std::{cmp, fmt::Debug};
use std::fmt::Debug;

use anyhow::{bail, Context};
use anyhow::Context;
#[cfg(feature = "test-utils")]
use mockall::automock;
use rundler_provider::{BlockHashOrNumber, DAGasProvider, EvmProvider};
Expand Down Expand Up @@ -68,17 +68,8 @@ pub async fn calc_required_pre_verification_gas<UO: UserOperation, E: DAGasProvi
base_fee: u128,
) -> anyhow::Result<(u128, DAGasUOData)> {
let (da_gas, uo_data) = if chain_spec.da_pre_verification_gas {
let gas_price = cmp::min(
base_fee + op.max_priority_fee_per_gas(),
op.max_fee_per_gas(),
);

if gas_price == 0 {
bail!("Gas price cannot be zero")
}

let (da_gas, uo_data, _) = entry_point
.calc_da_gas(op.clone(), block, gas_price)
.calc_da_gas(op.clone(), block, op.gas_price(base_fee))
.await?;
(da_gas, uo_data)
} else {
Expand Down
Loading