diff --git a/Cargo.lock b/Cargo.lock index 917a4f242175..47e25c632c4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5411,9 +5411,9 @@ checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" [[package]] name = "op-alloy-consensus" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5085cc8be65a2da9c04e9a904eccfe38eb69ecc3bc6c6485ce0f1af879f3abe" +checksum = "24aaf487dd59beed72931e31b11b305cdcb6a20651a1cccf992a20706a54cc3b" dependencies = [ "alloy-consensus", "alloy-eips", @@ -5429,9 +5429,9 @@ dependencies = [ [[package]] name = "op-alloy-genesis" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64f5aa1201d83af3b0ebffbfc28fdc7e772d7e44f4dea9e41c51162f84412edf" +checksum = "42ad6c33c2711611e19092a7d17c076542e27687ef975f67bf57039fa3d57e06" dependencies = [ "alloy-consensus", "alloy-eips", @@ -5444,9 +5444,9 @@ dependencies = [ [[package]] name = "op-alloy-network" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d12eafaad5b89792de75f1344d42634dd5271945fd36256e4e5d766cf32107e" +checksum = "8273ddf3a0a8cb891abbc625289f8094fbeab1329e0874b38e14bf1670402b7c" dependencies = [ "alloy-consensus", "alloy-network", @@ -5459,9 +5459,9 @@ dependencies = [ [[package]] name = "op-alloy-protocol" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cf8c05e1b7ed20c4af6f72a54cc389225d2c6af6fcf932ef6481cfdfcb540ac" +checksum = "ccb98f90d0101cdaabb739c44f4d4b2d0ad0ad1a3dd68ce525683ffafd97dd13" dependencies = [ "alloc-no-stdlib", "alloy-consensus", @@ -5483,9 +5483,9 @@ dependencies = [ [[package]] name = "op-alloy-rpc-jsonrpsee" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b6edd6fb56f23ab45c704ad0c598641086e07b3a55d74890acaa01226ffc3e2" +checksum = "44a41095f6aa4f39e3d8927ac8a903a45e76ddb533f466ef592853f9a49fe8cf" dependencies = [ "alloy-eips", "alloy-primitives", @@ -5496,9 +5496,9 @@ dependencies = [ [[package]] name = "op-alloy-rpc-types" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b44194f44faef3db1edd17fc8e0b1309d377c6c7a4ba74a02d78c13d5f2ed90d" +checksum = "21d0ada6356ac7818d4b1ba48c37116662732b97f18a3684f08727dafbef2437" dependencies = [ "alloy-consensus", "alloy-eips", @@ -5515,9 +5515,9 @@ dependencies = [ [[package]] name = "op-alloy-rpc-types-engine" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c005d0a4431fbd9cd16eb0c2f67306de4245f76f311fa1628a68b79e7ea5aa0e" +checksum = "7c63ba3f50dba410d1ce18aa16242c198f91ad44da5221f7347c1525958a9b09" dependencies = [ "alloy-eips", "alloy-primitives", @@ -8362,6 +8362,7 @@ dependencies = [ "alloy-primitives", "derive_more", "once_cell", + "op-alloy-consensus", "op-alloy-rpc-types", "reth-chainspec", "reth-ethereum-forks", diff --git a/Cargo.toml b/Cargo.toml index 80233cdb4397..0c9f94bcf55a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/crates/optimism/chainspec/Cargo.toml b/crates/optimism/chainspec/Cargo.toml index 5ccf26607094..818f2cd0d45c 100644 --- a/crates/optimism/chainspec/Cargo.toml +++ b/crates/optimism/chainspec/Cargo.toml @@ -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 diff --git a/crates/optimism/chainspec/src/lib.rs b/crates/optimism/chainspec/src/lib.rs index a1a08dd3b09a..6670aef1d01d 100644 --- a/crates/optimism/chainspec/src/lib.rs +++ b/crates/optimism/chainspec/src/lib.rs @@ -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, @@ -201,8 +202,8 @@ impl OpChainSpec { &self, parent: &Header, timestamp: u64, - ) -> Result { - let (denominator, elasticity) = decode_holocene_1559_params(&parent.extra_data)?; + ) -> Result { + 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)) @@ -221,13 +222,11 @@ impl OpChainSpec { &self, parent: &Header, timestamp: u64, - ) -> Result { + ) -> Result { // > 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. @@ -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: -/// -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; diff --git a/crates/optimism/evm/src/lib.rs b/crates/optimism/evm/src/lib.rs index 740eb92e6171..f99d2f9def35 100644 --- a/crates/optimism/evm/src/lib.rs +++ b/crates/optimism/evm/src/lib.rs @@ -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, @@ -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); diff --git a/crates/optimism/payload/src/payload.rs b/crates/optimism/payload/src/payload.rs index e243745cea68..1a8655bd7333 100644 --- a/crates/optimism/payload/src/payload.rs +++ b/crates/optimism/payload/src/payload.rs @@ -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}; @@ -45,7 +45,7 @@ impl OpPayloadBuilderAttributes { default_base_fee_params: BaseFeeParams, ) -> Result { 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)? } }