Skip to content

Commit 58012d2

Browse files
feat: add BlobsBundleV2 (#2206)
1 parent bddeec3 commit 58012d2

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

crates/rpc-types-engine/src/payload.rs

+74
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,80 @@ impl FromIterator<BlobTransactionSidecar> for BlobsBundleV1 {
824824
}
825825
}
826826

827+
/// This includes all bundled blob related data of an executed payload.
828+
#[derive(Clone, Debug, Default, PartialEq, Eq)]
829+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
830+
#[cfg_attr(feature = "ssz", derive(ssz_derive::Encode, ssz_derive::Decode))]
831+
pub struct BlobsBundleV2 {
832+
/// All commitments in the bundle.
833+
pub commitments: Vec<alloy_consensus::Bytes48>,
834+
/// All cell proofs in the bundle.
835+
pub cell_proofs: Vec<alloy_consensus::Bytes48>,
836+
/// All blobs in the bundle.
837+
pub blobs: Vec<alloy_consensus::Blob>,
838+
}
839+
840+
impl BlobsBundleV2 {
841+
/// Creates a new blob bundle from the given sidecars.
842+
///
843+
/// This folds the sidecar fields into single commit, proof, and blob vectors.
844+
pub fn new(sidecars: impl IntoIterator<Item = BlobTransactionSidecar>) -> Self {
845+
let (commitments, cell_proofs, blobs) = sidecars.into_iter().fold(
846+
(Vec::new(), Vec::new(), Vec::new()),
847+
|(mut commitments, mut cell_proofs, mut blobs), sidecar| {
848+
commitments.extend(sidecar.commitments);
849+
cell_proofs.extend(sidecar.proofs);
850+
blobs.extend(sidecar.blobs);
851+
(commitments, cell_proofs, blobs)
852+
},
853+
);
854+
Self { commitments, cell_proofs, blobs }
855+
}
856+
857+
/// Returns a new empty blobs bundle.
858+
///
859+
/// This is useful for the opstack engine API that expects an empty bundle as part of the
860+
/// payload for API compatibility reasons.
861+
pub fn empty() -> Self {
862+
Self::default()
863+
}
864+
865+
/// Take `len` blob data from the bundle.
866+
///
867+
/// # Panics
868+
///
869+
/// If len is more than the blobs bundle len.
870+
pub fn take(&mut self, len: usize) -> (Vec<Bytes48>, Vec<Bytes48>, Vec<Blob>) {
871+
(
872+
self.commitments.drain(0..len).collect(),
873+
self.cell_proofs.drain(0..len).collect(),
874+
self.blobs.drain(0..len).collect(),
875+
)
876+
}
877+
878+
/// Returns the sidecar from the bundle
879+
///
880+
/// # Panics
881+
///
882+
/// If len is more than the blobs bundle len.
883+
pub fn pop_sidecar(&mut self, len: usize) -> BlobTransactionSidecar {
884+
let (commitments, cell_proofs, blobs) = self.take(len);
885+
BlobTransactionSidecar { commitments, proofs: cell_proofs, blobs }
886+
}
887+
}
888+
889+
impl From<Vec<BlobTransactionSidecar>> for BlobsBundleV2 {
890+
fn from(sidecars: Vec<BlobTransactionSidecar>) -> Self {
891+
Self::new(sidecars)
892+
}
893+
}
894+
895+
impl FromIterator<BlobTransactionSidecar> for BlobsBundleV2 {
896+
fn from_iter<T: IntoIterator<Item = BlobTransactionSidecar>>(iter: T) -> Self {
897+
Self::new(iter)
898+
}
899+
}
900+
827901
/// An execution payload, which can be either [ExecutionPayloadV1], [ExecutionPayloadV2], or
828902
/// [ExecutionPayloadV3].
829903
#[derive(Clone, Debug, PartialEq, Eq)]

0 commit comments

Comments
 (0)