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

feat(rpc-types-engine): EIP-1559 parameters in OptimismPayloadAttributes #138

Merged
merged 3 commits into from
Oct 1, 2024
Merged
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
58 changes: 57 additions & 1 deletion crates/rpc-types-engine/src/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Optimism-specific payload attributes.

use alloc::vec::Vec;
use alloy_primitives::Bytes;
use alloy_primitives::{Bytes, B64};
use alloy_rpc_types_engine::PayloadAttributes;
use op_alloy_protocol::L2BlockInfo;

Expand All @@ -26,6 +26,11 @@ pub struct OptimismPayloadAttributes {
serde(skip_serializing_if = "Option::is_none", with = "alloy_serde::quantity::opt")
)]
pub gas_limit: Option<u64>,
/// 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<B64>,
clabby marked this conversation as resolved.
Show resolved Hide resolved
}

/// Optimism Payload Attributes with parent block reference.
Expand Down Expand Up @@ -65,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);
}
}
Loading