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(l1): use latest block base fee as default gas price #1023

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 14 additions & 2 deletions crates/networking/rpc/eth/gas_price.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ethereum_rust_blockchain::constants::MIN_GAS_LIMIT;
use ethereum_rust_storage::Store;
use tracing::error;

Expand Down Expand Up @@ -80,7 +79,20 @@ impl RpcHandler for GasPrice {
}
results.sort();

let sample_gas = results.get(results.len() / 2).unwrap_or(&MIN_GAS_LIMIT);
let Some(Some(latest_block_base_fee)) = storage
.get_block_header(latest_block_number)?
.map(|header| header.base_fee_per_gas.map(|base_fee| base_fee * 2))
else {
error!("FATAL: LATEST BLOCK BASE FEE IS MISSING");
return Err(RpcErr::Internal(
"Error calculating gas price: could not find block base fee in latest block"
.to_owned(),
));
};

let sample_gas = results
.get(results.len() / 2)
.unwrap_or(&latest_block_base_fee);

let gas_as_hex = format!("0x{:x}", sample_gas);
Ok(serde_json::Value::String(gas_as_hex))
Expand Down
Loading