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(eips): Make prague field an enum #1574

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 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
29 changes: 29 additions & 0 deletions crates/eips/src/eip7685.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,35 @@ impl Requests {
}
}

/// A list of requests or a precomputed requests hash.
///
/// For testing purposes, the `Hash` variant stores a precomputed requests hash. This can be useful
/// when the exact contents of the requests are unnecessary, and only a consistent hash value is
/// needed to simulate the presence of requests without holding actual data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the whitespaces in this comment are a bit funky, please reformat it :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the whitespaces in this comment are a bit funky, please reformat it :D

done


DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum RequestsOrHash {
/// Stores a list of requests, allowing for dynamic requests hash calculation.
Requests(Requests),
/// Stores a precomputed requests hash, used primarily for testing.
Hash(B256),
}

impl RequestsOrHash {
/// Returns the requests hash for the enum instance.
///
/// - If the instance contains a list of requests, this function calculates the hash using
/// `requests_hash` of the [`Requests`] struct.
/// - If it contains a precomputed hash, it returns that hash directly.
#[cfg(feature = "sha2")]
pub fn requests_hash(&self) -> B256 {
match self {
Self::Requests(requests) => requests.requests_hash(),
Self::Hash(precomputed_hash) => *precomputed_hash,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
Expand Down
22 changes: 18 additions & 4 deletions crates/rpc-types-engine/src/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{CancunPayloadFields, MaybeCancunPayloadFields};
use alloc::vec::Vec;
use alloy_eips::eip7685::Requests;
use alloy_eips::eip7685::{Requests, RequestsOrHash};
use alloy_primitives::B256;

/// Container type for all available additional `newPayload` request parameters that are not present
Expand All @@ -15,7 +15,7 @@ pub struct ExecutionPayloadSidecar {
cancun: MaybeCancunPayloadFields,
/// The EIP-7685 requests provided as additional request params to `engine_newPayloadV4` that
/// are not present in the `ExecutionPayload`.
prague: Option<Requests>,
prague: Option<RequestsOrHash>,
}

impl ExecutionPayloadSidecar {
Expand All @@ -30,7 +30,7 @@ impl ExecutionPayloadSidecar {
}

/// Creates a new instance post prague for `engine_newPayloadV4`
pub fn v4(cancun: CancunPayloadFields, requests: Requests) -> Self {
pub fn v4(cancun: CancunPayloadFields, requests: RequestsOrHash) -> Self {
Self { cancun: cancun.into(), prague: Some(requests) }
}

Expand All @@ -51,6 +51,20 @@ impl ExecutionPayloadSidecar {

/// Returns the EIP-7685 requests
pub const fn requests(&self) -> Option<&Requests> {
self.prague.as_ref()
if let Some(RequestsOrHash::Requests(ref requests)) = self.prague {
Some(requests)
} else {
None
}
}

/// Calculates or retrieves the requests hash.
///
/// - If the `prague` field contains a list of requests, it calculates the requests hash
/// dynamically.
/// - If it contains a precomputed hash (used for testing), it returns that hash directly.

DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
pub fn requests_hash(&self) -> B256 {
self.prague.as_ref().unwrap().requests_hash()
}
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
}