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

View File

@@ -436,14 +436,14 @@ impl From<Genesis> for OpChainSpec {
#[derive(Default, Debug)]
struct OpGenesisInfo {
optimism_chain_info: op_alloy_rpc_types::genesis::OpChainInfo,
optimism_chain_info: op_alloy_rpc_types::OpChainInfo,
base_fee_params: BaseFeeParamsKind,
}
impl OpGenesisInfo {
fn extract_from(genesis: &Genesis) -> 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,
)
.unwrap_or_default(),
@@ -852,7 +852,7 @@ mod tests {
#[test]
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#"
{

View File

@@ -15,9 +15,7 @@ use reth_node_api::{
};
use reth_optimism_chainspec::OpChainSpec;
use reth_optimism_forks::{OptimismHardfork, OptimismHardforks};
use reth_optimism_payload_builder::{
builder::decode_eip_1559_params, OpBuiltPayload, OpPayloadBuilderAttributes,
};
use reth_optimism_payload_builder::{OpBuiltPayload, OpPayloadBuilderAttributes};
/// The types used in the optimism beacon consensus engine.
#[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)
{
let Some(eip_1559_params) = attributes.eip_1559_params else {
return Err(EngineObjectValidationError::InvalidParams(
"MissingEip1559ParamsInPayloadAttributes".to_string().into(),
))
};
let (elasticity, denominator) = decode_eip_1559_params(eip_1559_params);
let (elasticity, denominator) =
attributes.decode_eip_1559_params().ok_or_else(|| {
EngineObjectValidationError::InvalidParams(
"MissingEip1559ParamsInPayloadAttributes".to_string().into(),
)
})?;
if elasticity != 0 && denominator == 0 {
return Err(EngineObjectValidationError::InvalidParams(
"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_eips::merge::BEACON_NONCE;
use alloy_primitives::{Address, Bytes, B64, U256};
use alloy_primitives::{Address, Bytes, U256};
use alloy_rpc_types_engine::PayloadId;
use reth_basic_payload_builder::*;
use reth_chain_state::ExecutedBlock;
@@ -831,12 +831,3 @@ where
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")]
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
//! Optimism builder support
use crate::{builder::decode_eip_1559_params, error::EIP1559ParamError};
use alloy_eips::{
eip1559::BaseFeeParams, eip2718::Decodable2718, eip4844::BlobTransactionSidecar,
eip7685::Requests,
@@ -10,6 +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::eip1559::{decode_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};
@@ -46,31 +44,9 @@ impl OpPayloadBuilderAttributes {
&self,
default_base_fee_params: BaseFeeParams,
) -> Result<Bytes, EIP1559ParamError> {
let eip_1559_params = self.eip_1559_params.ok_or(EIP1559ParamError::NoEIP1559Params)?;
let mut extra_data = [0u8; 9];
// 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))
self.eip_1559_params
.map(|params| decode_holocene_extra_data(params, default_base_fee_params))
.ok_or(EIP1559ParamError::NoEIP1559Params)?
}
}

View File

@@ -5,7 +5,7 @@ use alloy_rpc_types::{Log, TransactionReceipt};
use op_alloy_consensus::{
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_optimism_chainspec::OpChainSpec;
use reth_optimism_evm::RethL1BlockInfo;