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

chore: update holocene fns #13366

Merged
merged 1 commit into from
Dec 12, 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
29 changes: 15 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,11 @@ alloy-transport-ipc = { version = "0.8.0", default-features = false }
alloy-transport-ws = { version = "0.8.0", default-features = false }

# op
op-alloy-rpc-types = "0.8.1"
op-alloy-rpc-types-engine = "0.8.1"
op-alloy-rpc-jsonrpsee = "0.8.1"
op-alloy-network = "0.8.1"
op-alloy-consensus = "0.8.1"
op-alloy-rpc-types = "0.8.2"
op-alloy-rpc-types-engine = "0.8.2"
op-alloy-rpc-jsonrpsee = "0.8.2"
op-alloy-network = "0.8.2"
op-alloy-consensus = "0.8.2"

# misc
aquamarine = "0.6"
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/chainspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ alloy-eips.workspace = true

# op
op-alloy-rpc-types.workspace = true
op-alloy-consensus.workspace = true

# io
serde_json.workspace = true
Expand Down
47 changes: 6 additions & 41 deletions crates/optimism/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub use dev::OP_DEV;
#[cfg(not(feature = "std"))]
pub(crate) use once_cell::sync::Lazy as LazyLock;
pub use op::OP_MAINNET;
use op_alloy_consensus::{decode_holocene_extra_data, EIP1559ParamError};
pub use op_sepolia::OP_SEPOLIA;
use reth_chainspec::{
BaseFeeParams, BaseFeeParamsKind, ChainSpec, ChainSpecBuilder, DepositContract, EthChainSpec,
Expand Down Expand Up @@ -201,8 +202,8 @@ impl OpChainSpec {
&self,
parent: &Header,
timestamp: u64,
) -> Result<u64, DecodeError> {
let (denominator, elasticity) = decode_holocene_1559_params(&parent.extra_data)?;
) -> Result<u64, EIP1559ParamError> {
let (denominator, elasticity) = decode_holocene_extra_data(&parent.extra_data)?;
let base_fee = if elasticity == 0 && denominator == 0 {
parent
.next_block_base_fee(self.base_fee_params_at_timestamp(timestamp))
Expand All @@ -221,13 +222,11 @@ impl OpChainSpec {
&self,
parent: &Header,
timestamp: u64,
) -> Result<U256, DecodeError> {
) -> Result<U256, EIP1559ParamError> {
// > if Holocene is active in parent_header.timestamp, then the parameters from
// > parent_header.extraData are used.
let is_holocene_activated = self.inner.is_fork_active_at_timestamp(
reth_optimism_forks::OpHardfork::Holocene,
parent.timestamp,
);
let is_holocene_activated =
self.inner.is_fork_active_at_timestamp(OpHardfork::Holocene, parent.timestamp);

// If we are in the Holocene, we need to use the base fee params
// from the parent block's extra data.
Expand All @@ -244,40 +243,6 @@ impl OpChainSpec {
}
}

#[derive(Clone, Debug, Display, Eq, PartialEq)]
/// Error type for decoding Holocene 1559 parameters
pub enum DecodeError {
#[display("Insufficient data to decode")]
/// Insufficient data to decode
InsufficientData,
#[display("Invalid denominator parameter")]
/// Invalid denominator parameter
InvalidDenominator,
#[display("Invalid elasticity parameter")]
/// Invalid elasticity parameter
InvalidElasticity,
}

impl core::error::Error for DecodeError {
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
// None of the errors have sub-errors
None
}
}

/// Extracts the Holcene 1599 parameters from the encoded form:
/// <https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/holocene/exec-engine.md#eip1559params-encoding>
pub fn decode_holocene_1559_params(extra_data: &[u8]) -> Result<(u32, u32), DecodeError> {
if extra_data.len() < 9 {
return Err(DecodeError::InsufficientData);
}
let denominator: [u8; 4] =
extra_data[1..5].try_into().map_err(|_| DecodeError::InvalidDenominator)?;
let elasticity: [u8; 4] =
extra_data[5..9].try_into().map_err(|_| DecodeError::InvalidElasticity)?;
Ok((u32::from_be_bytes(denominator), u32::from_be_bytes(elasticity)))
}

impl EthChainSpec for OpChainSpec {
type Header = Header;

Expand Down
5 changes: 3 additions & 2 deletions crates/optimism/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ extern crate alloc;
use alloc::{sync::Arc, vec::Vec};
use alloy_consensus::Header;
use alloy_primitives::{Address, U256};
use op_alloy_consensus::EIP1559ParamError;
use reth_evm::{ConfigureEvm, ConfigureEvmEnv, NextBlockEnvAttributes};
use reth_optimism_chainspec::{DecodeError, OpChainSpec};
use reth_optimism_chainspec::OpChainSpec;
use reth_primitives::{transaction::FillTxEnv, Head, TransactionSigned};
use reth_revm::{
inspector_handle_register,
Expand Down Expand Up @@ -58,7 +59,7 @@ impl OpEvmConfig {
impl ConfigureEvmEnv for OpEvmConfig {
type Header = Header;
type Transaction = TransactionSigned;
type Error = DecodeError;
type Error = EIP1559ParamError;

fn fill_tx_env(&self, tx_env: &mut TxEnv, transaction: &TransactionSigned, sender: Address) {
transaction.fill_tx_env(tx_env, sender);
Expand Down
4 changes: 2 additions & 2 deletions crates/optimism/payload/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use alloy_eips::{
use alloy_primitives::{keccak256, Address, Bytes, B256, B64, U256};
use alloy_rlp::Encodable;
use alloy_rpc_types_engine::{ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, PayloadId};
use op_alloy_consensus::{decode_holocene_extra_data, EIP1559ParamError};
use op_alloy_consensus::{encode_holocene_extra_data, EIP1559ParamError};
/// Re-export for use in downstream arguments.
pub use op_alloy_rpc_types_engine::OpPayloadAttributes;
use op_alloy_rpc_types_engine::{OpExecutionPayloadEnvelopeV3, OpExecutionPayloadEnvelopeV4};
Expand Down Expand Up @@ -45,7 +45,7 @@ impl OpPayloadBuilderAttributes {
default_base_fee_params: BaseFeeParams,
) -> Result<Bytes, EIP1559ParamError> {
self.eip_1559_params
.map(|params| decode_holocene_extra_data(params, default_base_fee_params))
.map(|params| encode_holocene_extra_data(params, default_base_fee_params))
.ok_or(EIP1559ParamError::NoEIP1559Params)?
}
}
Expand Down
Loading