Skip to content

Commit

Permalink
Merge pull request #4964 from ethDreamer/sidecar-inclusion-proof
Browse files Browse the repository at this point in the history
Add Comments & Eliminate Unnecessary Clones
  • Loading branch information
realbigsean authored Nov 30, 2023
2 parents e5a0e2c + 10fe2ec commit 1996005
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
8 changes: 7 additions & 1 deletion beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,17 @@ impl<E: EthSpec> BeaconBlockResponseType<E> {
}
}

/// The components produced when the local beacon node creates a new block to extend the chain
pub struct BeaconBlockResponse<T: EthSpec, Payload: AbstractExecPayload<T>> {
/// The newly produced beacon block
pub block: BeaconBlock<T, Payload>,
/// The post-state after applying the new block
pub state: BeaconState<T>,
/// The Blobs / Proofs associated with the new block
pub blob_items: Option<(KzgProofs<T>, BlobsList<T>)>,
/// The execution layer reward for the block
pub execution_payload_value: Option<Uint256>,
/// The consensus layer reward to the proposer
pub consensus_block_value: Option<u64>,
}

Expand Down Expand Up @@ -2847,7 +2853,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
if let Some(event_handler) = self.event_handler.as_ref() {
if event_handler.has_blob_sidecar_subscribers() {
event_handler.register(EventKind::BlobSidecar(SseBlobSidecar::from_blob_sidecar(
&blob.cloned(),
blob.as_blob(),
)));
}
}
Expand Down
11 changes: 8 additions & 3 deletions beacon_node/beacon_chain/src/blob_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ impl<T: BeaconChainTypes> GossipVerifiedBlob<T> {
pub fn kzg_commitment(&self) -> KzgCommitment {
self.blob.blob.kzg_commitment
}
pub fn cloned(&self) -> Arc<BlobSidecar<T::EthSpec>> {
self.blob.blob.clone()
}
pub fn signed_block_header(&self) -> SignedBeaconBlockHeader {
self.blob.blob.signed_block_header.clone()
}
Expand All @@ -248,6 +245,13 @@ impl<T: BeaconChainTypes> GossipVerifiedBlob<T> {
pub fn into_inner(self) -> KzgVerifiedBlob<T::EthSpec> {
self.blob
}
pub fn as_blob(&self) -> &BlobSidecar<T::EthSpec> {
self.blob.as_blob()
}
/// This is cheap as we're calling clone on an Arc
pub fn clone_blob(&self) -> Arc<BlobSidecar<T::EthSpec>> {
self.blob.clone_blob()
}
}

/// Wrapper over a `BlobSidecar` for which we have completed kzg verification.
Expand Down Expand Up @@ -278,6 +282,7 @@ impl<T: EthSpec> KzgVerifiedBlob<T> {
pub fn as_blob(&self) -> &BlobSidecar<T> {
&self.blob
}
/// This is cheap as we're calling clone on an Arc
pub fn clone_blob(&self) -> Arc<BlobSidecar<T>> {
self.blob.clone()
}
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/beacon_chain/tests/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use types::{BlobSidecar, EthSpec, ForkName, MinimalEthSpec};

type E = MinimalEthSpec;

/// Verifies that a blob event is emitted when a gossip verified blob is received via gossip or the publish block API.
/// Verifies that a blob event is emitted when a gossip verified blob is received via gossip or the publish block API.
#[tokio::test]
async fn blob_sidecar_event_on_process_gossip_blob() {
let spec = ForkName::Deneb.make_genesis_spec(E::default_spec());
Expand All @@ -31,7 +31,7 @@ async fn blob_sidecar_event_on_process_gossip_blob() {
.map(Arc::new)
.unwrap();
let gossip_verified_blob = GossipVerifiedBlob::__assumed_valid(sidecar);
let expected_sse_blobs = SseBlobSidecar::from_blob_sidecar(&gossip_verified_blob.cloned());
let expected_sse_blobs = SseBlobSidecar::from_blob_sidecar(gossip_verified_blob.as_blob());

let _ = harness
.chain
Expand All @@ -43,7 +43,7 @@ async fn blob_sidecar_event_on_process_gossip_blob() {
assert_eq!(sidecar_event, EventKind::BlobSidecar(expected_sse_blobs));
}

/// Verifies that a blob event is emitted when blobs are received via RPC.
/// Verifies that a blob event is emitted when blobs are received via RPC.
#[tokio::test]
async fn blob_sidecar_event_on_process_rpc_blobs() {
let spec = ForkName::Deneb.make_genesis_spec(E::default_spec());
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/src/publish_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub async fn publish_block<T: BeaconChainTypes, B: IntoGossipVerifiedBlockConten
let blobs_opt = gossip_verified_blobs.as_ref().map(|gossip_verified_blobs| {
let blobs = gossip_verified_blobs
.into_iter()
.map(|b| b.cloned())
.map(|b| b.clone_blob())
.collect::<Vec<_>>();
VariableList::from(blobs)
});
Expand Down

0 comments on commit 1996005

Please sign in to comment.