mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
refactor: replace ``calculate_next_block_base_fee`` with alloy's builtin function (#7641)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -7,7 +7,7 @@ use futures::{
|
||||
};
|
||||
use metrics::atomics::AtomicU64;
|
||||
use reth_primitives::{
|
||||
basefee::calculate_next_block_base_fee,
|
||||
basefee::calc_next_block_base_fee,
|
||||
eip4844::{calc_blob_gasprice, calculate_excess_blob_gas},
|
||||
ChainSpec, Receipt, SealedBlock, TransactionSigned, B256,
|
||||
};
|
||||
@ -370,12 +370,12 @@ impl FeeHistoryEntry {
|
||||
|
||||
/// Returns the base fee for the next block according to the EIP-1559 spec.
|
||||
pub fn next_block_base_fee(&self, chain_spec: &ChainSpec) -> u64 {
|
||||
calculate_next_block_base_fee(
|
||||
self.gas_used,
|
||||
self.gas_limit,
|
||||
self.base_fee_per_gas,
|
||||
calc_next_block_base_fee(
|
||||
self.gas_used as u128,
|
||||
self.gas_limit as u128,
|
||||
self.base_fee_per_gas as u128,
|
||||
chain_spec.base_fee_params(self.timestamp),
|
||||
)
|
||||
) as u64
|
||||
}
|
||||
|
||||
/// Returns the blob fee for the next block according to the EIP-4844 spec.
|
||||
|
||||
@ -9,7 +9,7 @@ use crate::{
|
||||
};
|
||||
use reth_evm::ConfigureEvm;
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_primitives::{basefee::calculate_next_block_base_fee, BlockNumberOrTag, U256};
|
||||
use reth_primitives::{BlockNumberOrTag, U256};
|
||||
use reth_provider::{BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderFactory};
|
||||
use reth_rpc_types::FeeHistory;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
@ -187,12 +187,12 @@ where
|
||||
//
|
||||
// The unwrap is safe since we checked earlier that we got at least 1 header.
|
||||
let last_header = headers.last().expect("is present");
|
||||
base_fee_per_gas.push(calculate_next_block_base_fee(
|
||||
last_header.gas_used,
|
||||
last_header.gas_limit,
|
||||
last_header.base_fee_per_gas.unwrap_or_default(),
|
||||
self.provider().chain_spec().base_fee_params(last_header.timestamp),
|
||||
) as u128);
|
||||
base_fee_per_gas.push(
|
||||
self.provider().chain_spec().base_fee_params(last_header.timestamp).next_block_base_fee(
|
||||
last_header.gas_used as u128,
|
||||
last_header.gas_limit as u128,
|
||||
last_header.base_fee_per_gas.unwrap_or_default() as u128,
|
||||
));
|
||||
|
||||
// Same goes for the `base_fee_per_blob_gas`:
|
||||
// > "[..] includes the next block after the newest of the returned range, because this value can be derived from the newest block.
|
||||
|
||||
@ -1,16 +1,10 @@
|
||||
//! Implementation of the [`jsonrpsee`] generated [`reth_rpc_api::EthApiServer`] trait
|
||||
//! Handles RPC requests for the `eth_` namespace.
|
||||
|
||||
use super::EthApiSpec;
|
||||
use crate::{
|
||||
eth::{
|
||||
api::{EthApi, EthTransactions},
|
||||
error::EthApiError,
|
||||
revm_utils::EvmOverrides,
|
||||
},
|
||||
result::{internal_rpc_err, ToRpcResult},
|
||||
};
|
||||
use jsonrpsee::core::RpcResult as Result;
|
||||
use serde_json::Value;
|
||||
use tracing::trace;
|
||||
|
||||
use reth_evm::ConfigureEvm;
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_primitives::{
|
||||
@ -28,8 +22,17 @@ use reth_rpc_types::{
|
||||
StateContext, SyncStatus, TransactionRequest, Work,
|
||||
};
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
use serde_json::Value;
|
||||
use tracing::trace;
|
||||
|
||||
use crate::{
|
||||
eth::{
|
||||
api::{EthApi, EthTransactions},
|
||||
error::EthApiError,
|
||||
revm_utils::EvmOverrides,
|
||||
},
|
||||
result::{internal_rpc_err, ToRpcResult},
|
||||
};
|
||||
|
||||
use super::EthApiSpec;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<Provider, Pool, Network, EvmConfig> EthApiServer for EthApi<Provider, Pool, Network, EvmConfig>
|
||||
@ -435,6 +438,8 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use jsonrpsee::types::error::INVALID_PARAMS_CODE;
|
||||
|
||||
use crate::{
|
||||
eth::{
|
||||
cache::EthStateCache, gas_oracle::GasPriceOracle, FeeHistoryCache,
|
||||
@ -442,13 +447,12 @@ mod tests {
|
||||
},
|
||||
EthApi,
|
||||
};
|
||||
use jsonrpsee::types::error::INVALID_PARAMS_CODE;
|
||||
use reth_evm_ethereum::EthEvmConfig;
|
||||
use reth_interfaces::test_utils::{generators, generators::Rng};
|
||||
use reth_network_api::noop::NoopNetwork;
|
||||
use reth_primitives::{
|
||||
basefee::calculate_next_block_base_fee, constants::ETHEREUM_BLOCK_GAS_LIMIT, BaseFeeParams,
|
||||
Block, BlockNumberOrTag, Header, TransactionSigned, B256,
|
||||
constants::ETHEREUM_BLOCK_GAS_LIMIT, BaseFeeParams, Block, BlockNumberOrTag, Header,
|
||||
TransactionSigned, B256,
|
||||
};
|
||||
use reth_provider::{
|
||||
test_utils::{MockEthProvider, NoopProvider},
|
||||
@ -565,12 +569,11 @@ mod tests {
|
||||
|
||||
// Add final base fee (for the next block outside of the request)
|
||||
let last_header = last_header.unwrap();
|
||||
base_fees_per_gas.push(calculate_next_block_base_fee(
|
||||
last_header.gas_used,
|
||||
last_header.gas_limit,
|
||||
last_header.base_fee_per_gas.unwrap_or_default(),
|
||||
BaseFeeParams::ethereum(),
|
||||
) as u128);
|
||||
base_fees_per_gas.push(BaseFeeParams::ethereum().next_block_base_fee(
|
||||
last_header.gas_used as u128,
|
||||
last_header.gas_limit as u128,
|
||||
last_header.base_fee_per_gas.unwrap_or_default() as u128,
|
||||
));
|
||||
|
||||
let eth_api = build_test_eth_api(mock_provider);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user