From 0ed3d9552498d8f8224196b1d96b3e144b9e4b9b Mon Sep 17 00:00:00 2001 From: clabby Date: Tue, 1 Oct 2024 15:26:58 -0400 Subject: [PATCH 1/3] feat(rpc-types-engine): EIP-1559 parameters in `OptimismPayloadAttributes` --- crates/rpc-types-engine/src/attributes.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/rpc-types-engine/src/attributes.rs b/crates/rpc-types-engine/src/attributes.rs index 822fd05e..6ba54680 100644 --- a/crates/rpc-types-engine/src/attributes.rs +++ b/crates/rpc-types-engine/src/attributes.rs @@ -1,7 +1,7 @@ //! Optimism-specific payload attributes. use alloc::vec::Vec; -use alloy_primitives::Bytes; +use alloy_primitives::{Bytes, FixedBytes}; use alloy_rpc_types_engine::PayloadAttributes; use op_alloy_protocol::L2BlockInfo; @@ -26,6 +26,11 @@ pub struct OptimismPayloadAttributes { serde(skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt") )] pub gas_limit: Option, + /// If set, this sets the EIP-1559 parameters for the block. + /// + /// Prior to Holocene activation, this field should always be [None]. + #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] + pub eip_1559_params: Option>, } /// Optimism Payload Attributes with parent block reference. From 7f94741e103a0de9fb1a54212af52d16b6dc3578 Mon Sep 17 00:00:00 2001 From: clabby Date: Tue, 1 Oct 2024 15:57:59 -0400 Subject: [PATCH 2/3] change to b64 --- crates/rpc-types-engine/src/attributes.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/rpc-types-engine/src/attributes.rs b/crates/rpc-types-engine/src/attributes.rs index 6ba54680..3ab3b64d 100644 --- a/crates/rpc-types-engine/src/attributes.rs +++ b/crates/rpc-types-engine/src/attributes.rs @@ -1,7 +1,7 @@ //! Optimism-specific payload attributes. use alloc::vec::Vec; -use alloy_primitives::{Bytes, FixedBytes}; +use alloy_primitives::{Bytes, B64}; use alloy_rpc_types_engine::PayloadAttributes; use op_alloy_protocol::L2BlockInfo; @@ -30,7 +30,7 @@ pub struct OptimismPayloadAttributes { /// /// Prior to Holocene activation, this field should always be [None]. #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] - pub eip_1559_params: Option>, + pub eip_1559_params: Option, } /// Optimism Payload Attributes with parent block reference. From c96e6c6333cc738f3a9ba0342f72e16fc5493961 Mon Sep 17 00:00:00 2001 From: clabby Date: Tue, 1 Oct 2024 16:31:19 -0400 Subject: [PATCH 3/3] add serde roundtrip test fmt --- crates/rpc-types-engine/src/attributes.rs | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/crates/rpc-types-engine/src/attributes.rs b/crates/rpc-types-engine/src/attributes.rs index 3ab3b64d..490ebf4e 100644 --- a/crates/rpc-types-engine/src/attributes.rs +++ b/crates/rpc-types-engine/src/attributes.rs @@ -70,3 +70,54 @@ impl OptimismAttributesWithParent { self.is_last_in_span } } + +#[cfg(all(test, feature = "serde"))] +mod test { + use super::*; + use alloy_primitives::{b64, Address, B256}; + use alloy_rpc_types_engine::PayloadAttributes; + + #[test] + fn test_serde_roundtrip_attributes_pre_holocene() { + let attributes = OptimismPayloadAttributes { + payload_attributes: PayloadAttributes { + timestamp: 0x1337, + prev_randao: B256::ZERO, + suggested_fee_recipient: Address::ZERO, + withdrawals: Default::default(), + parent_beacon_block_root: Some(B256::ZERO), + }, + transactions: Some(vec![b"hello".to_vec().into()]), + no_tx_pool: Some(true), + gas_limit: Some(42), + eip_1559_params: None, + }; + + let ser = serde_json::to_string(&attributes).unwrap(); + let de: OptimismPayloadAttributes = serde_json::from_str(&ser).unwrap(); + + assert_eq!(attributes, de); + } + + #[test] + fn test_serde_roundtrip_attributes_post_holocene() { + let attributes = OptimismPayloadAttributes { + payload_attributes: PayloadAttributes { + timestamp: 0x1337, + prev_randao: B256::ZERO, + suggested_fee_recipient: Address::ZERO, + withdrawals: Default::default(), + parent_beacon_block_root: Some(B256::ZERO), + }, + transactions: Some(vec![b"hello".to_vec().into()]), + no_tx_pool: Some(true), + gas_limit: Some(42), + eip_1559_params: Some(b64!("0000dead0000beef")), + }; + + let ser = serde_json::to_string(&attributes).unwrap(); + let de: OptimismPayloadAttributes = serde_json::from_str(&ser).unwrap(); + + assert_eq!(attributes, de); + } +}