-
Notifications
You must be signed in to change notification settings - Fork 781
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
Add blob_sidecar
event to SSE
#4790
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba34a35
Add `blob_sidecar` event to SSE.
jimmygchen ae4b3a6
Return 202 if a block is published but failed blob validation when va…
jimmygchen 99bb548
Merge branch 'deneb-free-blobs' into sse-blobs
jimmygchen 05fc32c
Move `BlobSidecar` event to `process_gossip_blob` and add test.
jimmygchen 934a3fc
Emit `BlobSidecar` event when blobs are received over rpc.
jimmygchen 39cc2fe
Improve test assertions on `SseBlobSidecar`s.
jimmygchen 84302c2
Add quotes to blob index serialization in `SseBlobSidecar`
jimmygchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use beacon_chain::blob_verification::GossipVerifiedBlob; | ||
use beacon_chain::test_utils::BeaconChainHarness; | ||
use bls::Signature; | ||
use eth2::types::EventKind; | ||
use rand::rngs::StdRng; | ||
use rand::SeedableRng; | ||
use std::marker::PhantomData; | ||
use std::sync::Arc; | ||
use types::blob_sidecar::FixedBlobSidecarList; | ||
use types::{BlobSidecar, EthSpec, ForkName, MinimalEthSpec, SignedBlobSidecar}; | ||
|
||
type E = MinimalEthSpec; | ||
|
||
/// 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()); | ||
let harness = BeaconChainHarness::builder(E::default()) | ||
.spec(spec) | ||
.deterministic_keypairs(8) | ||
.fresh_ephemeral_store() | ||
.mock_execution_layer() | ||
.build(); | ||
|
||
// subscribe to blob sidecar events | ||
let event_handler = harness.chain.event_handler.as_ref().unwrap(); | ||
let mut blob_event_receiver = event_handler.subscribe_blob_sidecar(); | ||
|
||
// build and process a gossip verified blob | ||
let kzg = harness.chain.kzg.as_ref().unwrap(); | ||
let mut rng = StdRng::seed_from_u64(0xDEADBEEF0BAD5EEDu64); | ||
let signed_sidecar = SignedBlobSidecar { | ||
message: BlobSidecar::random_valid(&mut rng, kzg) | ||
.map(Arc::new) | ||
.unwrap(), | ||
signature: Signature::empty(), | ||
_phantom: PhantomData, | ||
}; | ||
let gossip_verified_blob = GossipVerifiedBlob::__assumed_valid(signed_sidecar); | ||
let _ = harness | ||
.chain | ||
.process_gossip_blob(gossip_verified_blob) | ||
.await | ||
.unwrap(); | ||
|
||
let sidecar_event = blob_event_receiver.try_recv().unwrap(); | ||
assert!(matches!(sidecar_event, EventKind::BlobSidecar(..))); | ||
} | ||
|
||
/// 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()); | ||
let harness = BeaconChainHarness::builder(E::default()) | ||
.spec(spec) | ||
.deterministic_keypairs(8) | ||
.fresh_ephemeral_store() | ||
.mock_execution_layer() | ||
.build(); | ||
|
||
// subscribe to blob sidecar events | ||
let event_handler = harness.chain.event_handler.as_ref().unwrap(); | ||
let mut blob_event_receiver = event_handler.subscribe_blob_sidecar(); | ||
|
||
// build and process multiple rpc blobs | ||
let kzg = harness.chain.kzg.as_ref().unwrap(); | ||
let mut rng = StdRng::seed_from_u64(0xDEADBEEF0BAD5EEDu64); | ||
|
||
let blob_1 = BlobSidecar::random_valid(&mut rng, kzg) | ||
.map(Arc::new) | ||
.unwrap(); | ||
let blob_2 = Arc::new(BlobSidecar { | ||
index: 1, | ||
..BlobSidecar::random_valid(&mut rng, kzg).unwrap() | ||
}); | ||
let blobs = FixedBlobSidecarList::from(vec![Some(blob_1.clone()), Some(blob_2)]); | ||
|
||
let _ = harness | ||
.chain | ||
.process_rpc_blobs(blob_1.slot, blob_1.block_root, blobs) | ||
.await | ||
.unwrap(); | ||
|
||
let mut events: Vec<EventKind<E>> = vec![]; | ||
while let Ok(sidecar_event) = blob_event_receiver.try_recv() { | ||
assert!(matches!(sidecar_event, EventKind::BlobSidecar(..))); | ||
events.push(sidecar_event); | ||
} | ||
assert!(events.len() == 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! You don't have to do this but since you seeded the RNG with a known value, the blob generated should be the same each time. You could check that the output matches the static
SseBlobSidecar
here so that this test breaks if something goes wrong in the code we use to generate it. Just an idea.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! Addressed in 39cc2fe. Thanks 🙏