Skip to content

Commit c79f587

Browse files
committed
fix eth_blobBaseFee
1 parent 1e6e7a1 commit c79f587

File tree

2 files changed

+23
-33
lines changed

2 files changed

+23
-33
lines changed

gas-oracle/app/src/l1_base_fee.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::{str::FromStr, sync::Arc};
22

33
use crate::{
4-
abi::gas_price_oracle_abi::GasPriceOracle, calc_blob_basefee, external_sign::ExternalSign, metrics::ORACLE_SERVICE_METRICS, signer::send_transaction, OracleError
4+
abi::gas_price_oracle_abi::GasPriceOracle, external_sign::ExternalSign,
5+
metrics::ORACLE_SERVICE_METRICS, signer::send_transaction, OracleError,
56
};
67
use ethers::prelude::*;
78
use eyre::anyhow;
@@ -210,8 +211,14 @@ async fn query_l1_base_fee(
210211
})?;
211212

212213
let l1_base_fee = latest_block.base_fee_per_gas.unwrap_or_default();
213-
let excess_blob_gas = latest_block.excess_blob_gas.unwrap_or_default();
214-
let latest_blob_fee = calc_blob_basefee(excess_blob_gas.as_u64());
214+
215+
// Use the Blob blobBaseFee provided by the L1 node.
216+
// We no longer compute it locally (e.g. via `calc_blob_basefee`) to avoid
217+
// depending on future L1 config changes.
218+
let latest_blob_fee = l1_provider
219+
.request::<(), U256>("eth_blobBaseFee", ())
220+
.await
221+
.map_err(|e| OracleError::L1BaseFeeError(anyhow!(format!("eth_blobBaseFee: {:#?}", e))))?;
215222

216223
let gas_price = match l1_provider.get_gas_price().await {
217224
Ok(gp) => gp,
@@ -226,3 +233,15 @@ async fn query_l1_base_fee(
226233

227234
Ok((l1_base_fee, U256::from(latest_blob_fee), gas_price))
228235
}
236+
237+
#[tokio::test]
238+
async fn test_eth_blob_base_fee() -> Result<(), OracleError> {
239+
let l1_provider = Provider::<Http>::try_from("https://ethereum-rpc.publicnode.com").unwrap();
240+
let blob_base_fee = l1_provider
241+
.request::<(), U256>("eth_blobBaseFee", ())
242+
.await
243+
.map_err(|e| OracleError::L1BaseFeeError(anyhow!(format!("eth_blobBaseFee: {:#?}", e))))?;
244+
245+
println!("eth_blobBaseFee: {:?}", blob_base_fee);
246+
Ok(())
247+
}

gas-oracle/app/src/lib.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,4 @@ pub fn contract_error<M: Middleware>(e: ContractError<M>) -> String {
3939
format!("error: {:#?}", e)
4040
};
4141
error_msg
42-
}
43-
44-
/// Minimum gas price for data blobs.
45-
pub const MIN_BLOB_GASPRICE: u64 = 1;
46-
47-
/// Controls the maximum rate of change for blob gas price.
48-
pub const BLOB_GASPRICE_UPDATE_FRACTION: u64 = 3338477;
49-
50-
pub fn calc_blob_basefee(excess_blob_gas: u64) -> u128 {
51-
fake_exponential(MIN_BLOB_GASPRICE, excess_blob_gas, BLOB_GASPRICE_UPDATE_FRACTION)
52-
}
53-
54-
fn fake_exponential(factor: u64, numerator: u64, denominator: u64) -> u128 {
55-
assert_ne!(denominator, 0, "attempt to divide by zero");
56-
let factor = factor as u128;
57-
let numerator = numerator as u128;
58-
let denominator = denominator as u128;
59-
60-
let mut i = 1;
61-
let mut output = 0;
62-
let mut numerator_accum = factor * denominator;
63-
while numerator_accum > 0 {
64-
output += numerator_accum;
65-
66-
// Denominator is asserted as not zero at the start of the function.
67-
numerator_accum = (numerator_accum * numerator) / (denominator * i);
68-
i += 1;
69-
}
70-
output / denominator
71-
}
42+
}

0 commit comments

Comments
 (0)