mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: integrate blob_params_at_timestamp (#14128)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -7247,6 +7247,7 @@ dependencies = [
|
||||
"futures",
|
||||
"itertools 0.13.0",
|
||||
"pin-project",
|
||||
"reth-chainspec",
|
||||
"reth-consensus-common",
|
||||
"reth-engine-primitives",
|
||||
"reth-errors",
|
||||
|
||||
@ -411,17 +411,6 @@ impl ChainSpec {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the [`BlobParams`] for the given timestamp.
|
||||
///
|
||||
/// Note: This always return [`BlobParams::cancun`] pre prague.
|
||||
pub fn blob_fee_params_at_timestamp(&self, timestamp: u64) -> BlobParams {
|
||||
if self.is_prague_active_at_timestamp(timestamp) {
|
||||
self.blob_params.prague
|
||||
} else {
|
||||
self.blob_params.cancun
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the hash of the genesis block.
|
||||
pub fn genesis_hash(&self) -> B256 {
|
||||
*self.genesis_hash.get_or_init(|| self.genesis_header().hash_slow())
|
||||
|
||||
@ -15,6 +15,7 @@ workspace = true
|
||||
reth-primitives.workspace = true
|
||||
reth-primitives-traits.workspace = true
|
||||
reth-errors.workspace = true
|
||||
reth-chainspec.workspace = true
|
||||
reth-consensus-common.workspace = true
|
||||
reth-fs-util.workspace = true
|
||||
reth-rpc-types-compat.workspace = true
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
//! Stream wrapper that simulates reorgs.
|
||||
|
||||
use alloy_consensus::{Header, Transaction};
|
||||
use alloy_eips::eip7840::BlobParams;
|
||||
use alloy_rpc_types_engine::{
|
||||
CancunPayloadFields, ExecutionPayload, ExecutionPayloadSidecar, ForkchoiceState, PayloadStatus,
|
||||
};
|
||||
use futures::{stream::FuturesUnordered, Stream, StreamExt, TryFutureExt};
|
||||
use itertools::Either;
|
||||
use reth_chainspec::EthChainSpec;
|
||||
use reth_engine_primitives::{
|
||||
BeaconEngineMessage, BeaconOnNewPayloadError, EngineTypes, OnForkChoiceUpdated,
|
||||
};
|
||||
@ -109,7 +109,7 @@ where
|
||||
Engine: EngineTypes,
|
||||
Provider: BlockReader<Block = reth_primitives::Block> + StateProviderFactory,
|
||||
Evm: ConfigureEvm<Header = Header, Transaction = reth_primitives::TransactionSigned>,
|
||||
Spec: EthereumHardforks,
|
||||
Spec: EthChainSpec + EthereumHardforks,
|
||||
{
|
||||
type Item = S::Item;
|
||||
|
||||
@ -256,7 +256,7 @@ fn create_reorg_head<Provider, Evm, Spec>(
|
||||
where
|
||||
Provider: BlockReader<Block = reth_primitives::Block> + StateProviderFactory,
|
||||
Evm: ConfigureEvm<Header = Header, Transaction = reth_primitives::TransactionSigned>,
|
||||
Spec: EthereumHardforks,
|
||||
Spec: EthChainSpec + EthereumHardforks,
|
||||
{
|
||||
let chain_spec = payload_validator.chain_spec();
|
||||
|
||||
@ -380,11 +380,8 @@ where
|
||||
let hashed_state = state_provider.hashed_post_state(outcome.state());
|
||||
|
||||
let (blob_gas_used, excess_blob_gas) =
|
||||
if chain_spec.is_cancun_active_at_timestamp(reorg_target.timestamp) {
|
||||
(
|
||||
Some(sum_blob_gas_used),
|
||||
reorg_target_parent.next_block_excess_blob_gas(BlobParams::cancun()),
|
||||
)
|
||||
if let Some(blob_params) = chain_spec.blob_params_at_timestamp(reorg_target.timestamp) {
|
||||
(Some(sum_blob_gas_used), reorg_target_parent.next_block_excess_blob_gas(blob_params))
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
|
||||
use alloy_consensus::EMPTY_OMMER_ROOT_HASH;
|
||||
use alloy_eips::{eip7840::BlobParams, merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS};
|
||||
use alloy_eips::merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS;
|
||||
use alloy_primitives::U256;
|
||||
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
||||
use reth_consensus::{
|
||||
@ -192,13 +192,7 @@ where
|
||||
)?;
|
||||
|
||||
// ensure that the blob gas fields for this block
|
||||
if self.chain_spec.is_cancun_active_at_timestamp(header.timestamp()) {
|
||||
let blob_params = if self.chain_spec.is_prague_active_at_timestamp(header.timestamp()) {
|
||||
BlobParams::prague()
|
||||
} else {
|
||||
BlobParams::cancun()
|
||||
};
|
||||
|
||||
if let Some(blob_params) = self.chain_spec.blob_params_at_timestamp(header.timestamp()) {
|
||||
validate_against_parent_4844(header.header(), parent.header(), blob_params)?;
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ use alloc::{sync::Arc, vec::Vec};
|
||||
use alloy_consensus::{BlockHeader, Header};
|
||||
use alloy_primitives::{Address, U256};
|
||||
use core::{convert::Infallible, fmt::Debug};
|
||||
use reth_chainspec::ChainSpec;
|
||||
use reth_chainspec::{ChainSpec, EthChainSpec};
|
||||
use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv, Database, Evm, NextBlockEnvAttributes};
|
||||
use reth_primitives::TransactionSigned;
|
||||
use reth_primitives_traits::transaction::execute::FillTxEnv;
|
||||
@ -32,7 +32,7 @@ use revm_primitives::{
|
||||
};
|
||||
|
||||
mod config;
|
||||
use alloy_eips::{eip1559::INITIAL_BASE_FEE, eip7840::BlobParams};
|
||||
use alloy_eips::eip1559::INITIAL_BASE_FEE;
|
||||
pub use config::{revm_spec, revm_spec_by_timestamp_and_block_number};
|
||||
use reth_ethereum_forks::EthereumHardfork;
|
||||
|
||||
@ -188,13 +188,12 @@ impl ConfigureEvmEnv for EthEvmConfig {
|
||||
parent.number() + 1,
|
||||
);
|
||||
|
||||
let blob_params =
|
||||
if spec_id >= SpecId::PRAGUE { BlobParams::prague() } else { BlobParams::cancun() };
|
||||
|
||||
// if the parent block did not have excess blob gas (i.e. it was pre-cancun), but it is
|
||||
// cancun now, we need to set the excess blob gas to the default value(0)
|
||||
let blob_excess_gas_and_price = parent
|
||||
.next_block_excess_blob_gas(blob_params)
|
||||
.maybe_next_block_excess_blob_gas(
|
||||
self.chain_spec.blob_params_at_timestamp(attributes.timestamp),
|
||||
)
|
||||
.or_else(|| (spec_id == SpecId::CANCUN).then_some(0))
|
||||
.map(|gas| BlobExcessGasAndPrice::new(gas, spec_id >= SpecId::PRAGUE));
|
||||
|
||||
|
||||
@ -9,17 +9,16 @@
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
#![allow(clippy::useless_let_if_seq)]
|
||||
|
||||
use alloy_consensus::{Header, Transaction, Typed2718, EMPTY_OMMER_ROOT_HASH};
|
||||
use alloy_consensus::{BlockHeader, Header, Transaction, Typed2718, EMPTY_OMMER_ROOT_HASH};
|
||||
use alloy_eips::{
|
||||
eip4844::MAX_DATA_GAS_PER_BLOCK, eip6110, eip7685::Requests, eip7840::BlobParams,
|
||||
merge::BEACON_NONCE,
|
||||
eip4844::MAX_DATA_GAS_PER_BLOCK, eip6110, eip7685::Requests, merge::BEACON_NONCE,
|
||||
};
|
||||
use alloy_primitives::U256;
|
||||
use reth_basic_payload_builder::{
|
||||
commit_withdrawals, is_better_payload, BuildArguments, BuildOutcome, PayloadBuilder,
|
||||
PayloadConfig,
|
||||
};
|
||||
use reth_chainspec::{ChainSpec, ChainSpecProvider};
|
||||
use reth_chainspec::{ChainSpec, ChainSpecProvider, EthChainSpec};
|
||||
use reth_errors::RethError;
|
||||
use reth_evm::{
|
||||
env::EvmEnv, system_calls::SystemCaller, ConfigureEvm, Evm, EvmError, InvalidTxError,
|
||||
@ -419,13 +418,9 @@ where
|
||||
.map_err(PayloadBuilderError::other)?;
|
||||
|
||||
excess_blob_gas = if chain_spec.is_cancun_active_at_timestamp(parent_header.timestamp) {
|
||||
let blob_params = if chain_spec.is_prague_active_at_timestamp(attributes.timestamp) {
|
||||
BlobParams::prague()
|
||||
} else {
|
||||
// cancun
|
||||
BlobParams::cancun()
|
||||
};
|
||||
parent_header.next_block_excess_blob_gas(blob_params)
|
||||
parent_header.maybe_next_block_excess_blob_gas(
|
||||
chain_spec.blob_params_at_timestamp(attributes.timestamp),
|
||||
)
|
||||
} else {
|
||||
// for the first post-fork block, both parent.blob_gas_used and
|
||||
// parent.excess_blob_gas are evaluated as 0
|
||||
|
||||
@ -14,9 +14,8 @@ extern crate alloc;
|
||||
|
||||
use alloc::sync::Arc;
|
||||
use alloy_consensus::{BlockHeader as _, EMPTY_OMMER_ROOT_HASH};
|
||||
use alloy_eips::eip7840::BlobParams;
|
||||
use alloy_primitives::{B64, U256};
|
||||
use reth_chainspec::EthereumHardforks;
|
||||
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
||||
use reth_consensus::{
|
||||
Consensus, ConsensusError, FullConsensus, HeaderValidator, PostExecutionInput,
|
||||
};
|
||||
@ -149,8 +148,8 @@ impl<H: BlockHeader> HeaderValidator<H> for OpBeaconConsensus {
|
||||
}
|
||||
|
||||
// ensure that the blob gas fields for this block
|
||||
if self.chain_spec.is_cancun_active_at_timestamp(header.timestamp()) {
|
||||
validate_against_parent_4844(header.header(), parent.header(), BlobParams::cancun())?;
|
||||
if let Some(blob_params) = self.chain_spec.blob_params_at_timestamp(header.timestamp()) {
|
||||
validate_against_parent_4844(header.header(), parent.header(), blob_params)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@ -14,10 +14,10 @@ extern crate alloc;
|
||||
|
||||
use alloc::sync::Arc;
|
||||
use alloy_consensus::{BlockHeader, Header};
|
||||
use alloy_eips::eip7840::BlobParams;
|
||||
use alloy_primitives::{Address, U256};
|
||||
use core::fmt::Debug;
|
||||
use op_alloy_consensus::EIP1559ParamError;
|
||||
use reth_chainspec::EthChainSpec;
|
||||
use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv, Database, Evm, NextBlockEnvAttributes};
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
use reth_optimism_primitives::OpTransactionSigned;
|
||||
@ -194,7 +194,9 @@ impl ConfigureEvmEnv for OpEvmConfig {
|
||||
// if the parent block did not have excess blob gas (i.e. it was pre-cancun), but it is
|
||||
// cancun now, we need to set the excess blob gas to the default value(0)
|
||||
let blob_excess_gas_and_price = parent
|
||||
.next_block_excess_blob_gas(BlobParams::cancun())
|
||||
.maybe_next_block_excess_blob_gas(
|
||||
self.chain_spec().blob_params_at_timestamp(attributes.timestamp),
|
||||
)
|
||||
.or_else(|| (spec_id.is_enabled_in(SpecId::CANCUN)).then_some(0))
|
||||
.map(|gas| BlobExcessGasAndPrice::new(gas, false));
|
||||
|
||||
|
||||
@ -165,7 +165,13 @@ pub trait EthFees: LoadFee {
|
||||
for header in &headers {
|
||||
base_fee_per_gas.push(header.base_fee_per_gas().unwrap_or_default() as u128);
|
||||
gas_used_ratio.push(header.gas_used() as f64 / header.gas_limit() as f64);
|
||||
base_fee_per_blob_gas.push(header.blob_fee(BlobParams::cancun()).unwrap_or_default());
|
||||
|
||||
let blob_params = self.provider()
|
||||
.chain_spec()
|
||||
.blob_params_at_timestamp(header.timestamp())
|
||||
.unwrap_or_else(BlobParams::cancun);
|
||||
|
||||
base_fee_per_blob_gas.push(header.blob_fee(blob_params).unwrap_or_default());
|
||||
blob_gas_used_ratio.push(
|
||||
header.blob_gas_used().unwrap_or_default() as f64
|
||||
/ alloy_eips::eip4844::MAX_DATA_GAS_PER_BLOCK as f64,
|
||||
@ -206,7 +212,12 @@ pub trait EthFees: LoadFee {
|
||||
|
||||
// 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.
|
||||
base_fee_per_blob_gas.push(last_header.next_block_blob_fee(BlobParams::cancun()).unwrap_or_default());
|
||||
base_fee_per_blob_gas.push(
|
||||
last_header
|
||||
.maybe_next_block_blob_fee(
|
||||
self.provider().chain_spec().blob_params_at_timestamp(last_header.timestamp())
|
||||
).unwrap_or_default()
|
||||
);
|
||||
};
|
||||
|
||||
Ok(FeeHistory {
|
||||
@ -331,7 +342,11 @@ pub trait LoadFee: LoadBlock {
|
||||
async move {
|
||||
self.block_with_senders(BlockNumberOrTag::Latest.into())
|
||||
.await?
|
||||
.and_then(|h| h.next_block_blob_fee(BlobParams::cancun()))
|
||||
.and_then(|h| {
|
||||
h.maybe_next_block_blob_fee(
|
||||
self.provider().chain_spec().blob_params_at_timestamp(h.timestamp()),
|
||||
)
|
||||
})
|
||||
.ok_or(EthApiError::ExcessBlobGasNotSet.into())
|
||||
.map(U256::from)
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ use crate::{
|
||||
BlockInfo, PoolTransaction, PoolUpdateKind,
|
||||
};
|
||||
use alloy_consensus::{BlockHeader, Typed2718};
|
||||
use alloy_eips::{eip7840::BlobParams, BlockNumberOrTag};
|
||||
use alloy_eips::BlockNumberOrTag;
|
||||
use alloy_primitives::{Address, BlockHash, BlockNumber};
|
||||
use alloy_rlp::Encodable;
|
||||
use futures_util::{
|
||||
@ -119,7 +119,9 @@ pub async fn maintain_transaction_pool<N, Client, P, St, Tasks>(
|
||||
chain_spec.base_fee_params_at_timestamp(latest.timestamp() + 12),
|
||||
)
|
||||
.unwrap_or_default(),
|
||||
pending_blob_fee: latest.next_block_blob_fee(BlobParams::cancun()),
|
||||
pending_blob_fee: latest.maybe_next_block_blob_fee(
|
||||
chain_spec.blob_params_at_timestamp(latest.timestamp() + 12),
|
||||
),
|
||||
};
|
||||
pool.set_block_info(info);
|
||||
}
|
||||
@ -277,8 +279,9 @@ pub async fn maintain_transaction_pool<N, Client, P, St, Tasks>(
|
||||
chain_spec.base_fee_params_at_timestamp(new_tip.timestamp() + 12),
|
||||
)
|
||||
.unwrap_or_default();
|
||||
let pending_block_blob_fee =
|
||||
new_tip.header().next_block_blob_fee(BlobParams::cancun());
|
||||
let pending_block_blob_fee = new_tip.header().maybe_next_block_blob_fee(
|
||||
chain_spec.blob_params_at_timestamp(new_tip.timestamp() + 12),
|
||||
);
|
||||
|
||||
// we know all changed account in the new chain
|
||||
let new_changed_accounts: HashSet<_> =
|
||||
@ -382,7 +385,9 @@ pub async fn maintain_transaction_pool<N, Client, P, St, Tasks>(
|
||||
chain_spec.base_fee_params_at_timestamp(tip.timestamp() + 12),
|
||||
)
|
||||
.unwrap_or_default();
|
||||
let pending_block_blob_fee = tip.header().next_block_blob_fee(BlobParams::cancun());
|
||||
let pending_block_blob_fee = tip.header().maybe_next_block_blob_fee(
|
||||
chain_spec.blob_params_at_timestamp(tip.timestamp() + 12),
|
||||
);
|
||||
|
||||
let first_block = blocks.first();
|
||||
trace!(
|
||||
|
||||
Reference in New Issue
Block a user