feat: use 1559 functions directly (#12356)

This commit is contained in:
Matthias Seitz
2024-11-06 21:30:49 +01:00
committed by GitHub
parent 2c5ba732b7
commit fe2b02828d
8 changed files with 33 additions and 81 deletions

25
Cargo.lock generated
View File

@ -5274,9 +5274,9 @@ checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9"
[[package]] [[package]]
name = "op-alloy-consensus" name = "op-alloy-consensus"
version = "0.6.0" version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae4582945fa96ae0ed78babcac6e41f025460e30ed0c9781aaeedf878fc2b527" checksum = "dabf6e7d7d63b2c6ed746b24d334e16388c6c3921bc50172440c72aa923c6b4a"
dependencies = [ dependencies = [
"alloy-consensus", "alloy-consensus",
"alloy-eips", "alloy-eips",
@ -5292,9 +5292,9 @@ dependencies = [
[[package]] [[package]]
name = "op-alloy-genesis" name = "op-alloy-genesis"
version = "0.6.0" version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1ece4a037c56536d8b517d045cef9cc07364c578709c184d33817108309c31e" checksum = "f901aa077832e22820c644d63d2e5e48601eed0f06e40f2a26d1b2a89bd17dec"
dependencies = [ dependencies = [
"alloy-consensus", "alloy-consensus",
"alloy-eips", "alloy-eips",
@ -5306,9 +5306,9 @@ dependencies = [
[[package]] [[package]]
name = "op-alloy-network" name = "op-alloy-network"
version = "0.6.0" version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05e9b64d15a7bf27a06c16eb286349aa2d4e3173260a8ab1fe73bd2c13c89769" checksum = "8b2e7db7997b12c1f364a3bd54b35338357f44c8e2e533a81ebf625104d80110"
dependencies = [ dependencies = [
"alloy-consensus", "alloy-consensus",
"alloy-network", "alloy-network",
@ -5321,9 +5321,9 @@ dependencies = [
[[package]] [[package]]
name = "op-alloy-protocol" name = "op-alloy-protocol"
version = "0.6.0" version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa989d1ea8deced466b0edd7a447264b1f934fd740ab895d32b8544dcce3b151" checksum = "b9226c7618f45f1d1e1f1112230818d5cfa719da9f5ca05fa28eaeb44d024181"
dependencies = [ dependencies = [
"alloy-consensus", "alloy-consensus",
"alloy-eips", "alloy-eips",
@ -5341,9 +5341,9 @@ dependencies = [
[[package]] [[package]]
name = "op-alloy-rpc-types" name = "op-alloy-rpc-types"
version = "0.6.0" version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca6e53039829ff0b3482d8dd02cb2de45d5c7b889023c7e4588a43ea7451664a" checksum = "d60079165fe9a4be99b04865d8746c6c9c7b505be2fdce8982f677ca18c3cc10"
dependencies = [ dependencies = [
"alloy-consensus", "alloy-consensus",
"alloy-eips", "alloy-eips",
@ -5360,9 +5360,9 @@ dependencies = [
[[package]] [[package]]
name = "op-alloy-rpc-types-engine" name = "op-alloy-rpc-types-engine"
version = "0.6.0" version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "283b19e1e7fef1ca9078df39f45a48609cacf856b7b441ed6cf19301ed162cca" checksum = "59a5b505325e343b299b1c574b2b8542f6ac3101e0d92a1c909b2d7dd74665f1"
dependencies = [ dependencies = [
"alloy-eips", "alloy-eips",
"alloy-primitives", "alloy-primitives",
@ -5370,6 +5370,7 @@ dependencies = [
"alloy-serde", "alloy-serde",
"derive_more 1.0.0", "derive_more 1.0.0",
"ethereum_ssz", "ethereum_ssz",
"op-alloy-consensus",
"op-alloy-protocol", "op-alloy-protocol",
"serde", "serde",
"snap", "snap",

View File

@ -468,10 +468,10 @@ alloy-transport-ipc = { version = "0.6.0", default-features = false }
alloy-transport-ws = { version = "0.6.0", default-features = false } alloy-transport-ws = { version = "0.6.0", default-features = false }
# op # op
op-alloy-rpc-types = "0.6" op-alloy-rpc-types = "0.6.2"
op-alloy-rpc-types-engine = "0.6" op-alloy-rpc-types-engine = "0.6.2"
op-alloy-network = "0.6" op-alloy-network = "0.6.2"
op-alloy-consensus = "0.6" op-alloy-consensus = "0.6.2"
# misc # misc
aquamarine = "0.6" aquamarine = "0.6"

View File

@ -436,14 +436,14 @@ impl From<Genesis> for OpChainSpec {
#[derive(Default, Debug)] #[derive(Default, Debug)]
struct OpGenesisInfo { struct OpGenesisInfo {
optimism_chain_info: op_alloy_rpc_types::genesis::OpChainInfo, optimism_chain_info: op_alloy_rpc_types::OpChainInfo,
base_fee_params: BaseFeeParamsKind, base_fee_params: BaseFeeParamsKind,
} }
impl OpGenesisInfo { impl OpGenesisInfo {
fn extract_from(genesis: &Genesis) -> Self { fn extract_from(genesis: &Genesis) -> Self {
let mut info = Self { let mut info = Self {
optimism_chain_info: op_alloy_rpc_types::genesis::OpChainInfo::extract_from( optimism_chain_info: op_alloy_rpc_types::OpChainInfo::extract_from(
&genesis.config.extra_fields, &genesis.config.extra_fields,
) )
.unwrap_or_default(), .unwrap_or_default(),
@ -852,7 +852,7 @@ mod tests {
#[test] #[test]
fn parse_genesis_optimism_with_variable_base_fee_params() { fn parse_genesis_optimism_with_variable_base_fee_params() {
use op_alloy_rpc_types::genesis::OpBaseFeeInfo; use op_alloy_rpc_types::OpBaseFeeInfo;
let geth_genesis = r#" let geth_genesis = r#"
{ {

View File

@ -15,9 +15,7 @@ use reth_node_api::{
}; };
use reth_optimism_chainspec::OpChainSpec; use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_forks::{OptimismHardfork, OptimismHardforks}; use reth_optimism_forks::{OptimismHardfork, OptimismHardforks};
use reth_optimism_payload_builder::{ use reth_optimism_payload_builder::{OpBuiltPayload, OpPayloadBuilderAttributes};
builder::decode_eip_1559_params, OpBuiltPayload, OpPayloadBuilderAttributes,
};
/// The types used in the optimism beacon consensus engine. /// The types used in the optimism beacon consensus engine.
#[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)] #[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
@ -151,12 +149,12 @@ where
if self.chain_spec.is_holocene_active_at_timestamp(attributes.payload_attributes.timestamp) if self.chain_spec.is_holocene_active_at_timestamp(attributes.payload_attributes.timestamp)
{ {
let Some(eip_1559_params) = attributes.eip_1559_params else { let (elasticity, denominator) =
return Err(EngineObjectValidationError::InvalidParams( attributes.decode_eip_1559_params().ok_or_else(|| {
"MissingEip1559ParamsInPayloadAttributes".to_string().into(), EngineObjectValidationError::InvalidParams(
)) "MissingEip1559ParamsInPayloadAttributes".to_string().into(),
}; )
let (elasticity, denominator) = decode_eip_1559_params(eip_1559_params); })?;
if elasticity != 0 && denominator == 0 { if elasticity != 0 && denominator == 0 {
return Err(EngineObjectValidationError::InvalidParams( return Err(EngineObjectValidationError::InvalidParams(
"Eip1559ParamsDenominatorZero".to_string().into(), "Eip1559ParamsDenominatorZero".to_string().into(),

View File

@ -4,7 +4,7 @@ use std::{fmt::Display, sync::Arc};
use alloy_consensus::EMPTY_OMMER_ROOT_HASH; use alloy_consensus::EMPTY_OMMER_ROOT_HASH;
use alloy_eips::merge::BEACON_NONCE; use alloy_eips::merge::BEACON_NONCE;
use alloy_primitives::{Address, Bytes, B64, U256}; use alloy_primitives::{Address, Bytes, U256};
use alloy_rpc_types_engine::PayloadId; use alloy_rpc_types_engine::PayloadId;
use reth_basic_payload_builder::*; use reth_basic_payload_builder::*;
use reth_chain_state::ExecutedBlock; use reth_chain_state::ExecutedBlock;
@ -831,12 +831,3 @@ where
Ok(None) Ok(None)
} }
} }
/// Extracts the Holocene 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_eip_1559_params(eip_1559_params: B64) -> (u32, u32) {
let denominator: [u8; 4] = eip_1559_params.0[..4].try_into().expect("sufficient length");
let elasticity: [u8; 4] = eip_1559_params.0[4..8].try_into().expect("sufficient length");
(u32::from_be_bytes(elasticity), u32::from_be_bytes(denominator))
}

View File

@ -21,17 +21,3 @@ pub enum OptimismPayloadBuilderError {
#[error("blob transaction included in sequencer block")] #[error("blob transaction included in sequencer block")]
BlobTransactionRejected, BlobTransactionRejected,
} }
/// Error type for EIP-1559 parameters
#[derive(Debug, thiserror::Error)]
pub enum EIP1559ParamError {
/// No EIP-1559 parameters provided
#[error("No EIP-1559 parameters provided")]
NoEIP1559Params,
/// Denominator overflow
#[error("Denominator overflow")]
DenominatorOverflow,
/// Elasticity overflow
#[error("Elasticity overflow")]
ElasticityOverflow,
}

View File

@ -1,8 +1,5 @@
//! Payload related types //! Payload related types
//! Optimism builder support
use crate::{builder::decode_eip_1559_params, error::EIP1559ParamError};
use alloy_eips::{ use alloy_eips::{
eip1559::BaseFeeParams, eip2718::Decodable2718, eip4844::BlobTransactionSidecar, eip1559::BaseFeeParams, eip2718::Decodable2718, eip4844::BlobTransactionSidecar,
eip7685::Requests, eip7685::Requests,
@ -10,6 +7,7 @@ use alloy_eips::{
use alloy_primitives::{keccak256, Address, Bytes, B256, B64, U256}; use alloy_primitives::{keccak256, Address, Bytes, B256, B64, U256};
use alloy_rlp::Encodable; use alloy_rlp::Encodable;
use alloy_rpc_types_engine::{ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, PayloadId}; use alloy_rpc_types_engine::{ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, PayloadId};
use op_alloy_consensus::eip1559::{decode_holocene_extra_data, EIP1559ParamError};
/// Re-export for use in downstream arguments. /// Re-export for use in downstream arguments.
pub use op_alloy_rpc_types_engine::OpPayloadAttributes; pub use op_alloy_rpc_types_engine::OpPayloadAttributes;
use op_alloy_rpc_types_engine::{OpExecutionPayloadEnvelopeV3, OpExecutionPayloadEnvelopeV4}; use op_alloy_rpc_types_engine::{OpExecutionPayloadEnvelopeV3, OpExecutionPayloadEnvelopeV4};
@ -46,31 +44,9 @@ impl OpPayloadBuilderAttributes {
&self, &self,
default_base_fee_params: BaseFeeParams, default_base_fee_params: BaseFeeParams,
) -> Result<Bytes, EIP1559ParamError> { ) -> Result<Bytes, EIP1559ParamError> {
let eip_1559_params = self.eip_1559_params.ok_or(EIP1559ParamError::NoEIP1559Params)?; self.eip_1559_params
.map(|params| decode_holocene_extra_data(params, default_base_fee_params))
let mut extra_data = [0u8; 9]; .ok_or(EIP1559ParamError::NoEIP1559Params)?
// If eip 1559 params aren't set, use the canyon base fee param constants
// otherwise use them
if eip_1559_params.is_zero() {
// Try casting max_change_denominator to u32
let max_change_denominator: u32 = (default_base_fee_params.max_change_denominator)
.try_into()
.map_err(|_| EIP1559ParamError::DenominatorOverflow)?;
// Try casting elasticity_multiplier to u32
let elasticity_multiplier: u32 = (default_base_fee_params.elasticity_multiplier)
.try_into()
.map_err(|_| EIP1559ParamError::ElasticityOverflow)?;
// Copy the values safely
extra_data[1..5].copy_from_slice(&max_change_denominator.to_be_bytes());
extra_data[5..9].copy_from_slice(&elasticity_multiplier.to_be_bytes());
} else {
let (elasticity, denominator) = decode_eip_1559_params(eip_1559_params);
extra_data[1..5].copy_from_slice(&denominator.to_be_bytes());
extra_data[5..9].copy_from_slice(&elasticity.to_be_bytes());
}
Ok(Bytes::copy_from_slice(&extra_data))
} }
} }

View File

@ -5,7 +5,7 @@ use alloy_rpc_types::{Log, TransactionReceipt};
use op_alloy_consensus::{ use op_alloy_consensus::{
DepositTransaction, OpDepositReceipt, OpDepositReceiptWithBloom, OpReceiptEnvelope, DepositTransaction, OpDepositReceipt, OpDepositReceiptWithBloom, OpReceiptEnvelope,
}; };
use op_alloy_rpc_types::{receipt::L1BlockInfo, OpTransactionReceipt, OpTransactionReceiptFields}; use op_alloy_rpc_types::{L1BlockInfo, OpTransactionReceipt, OpTransactionReceiptFields};
use reth_node_api::{FullNodeComponents, NodeTypes}; use reth_node_api::{FullNodeComponents, NodeTypes};
use reth_optimism_chainspec::OpChainSpec; use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_evm::RethL1BlockInfo; use reth_optimism_evm::RethL1BlockInfo;