mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 05:14:35 +00:00
Add block_gossip Beacon API events (#5864)
* Add bls event * Update events and types * Add bls in event * Event bls * tests..rs * change order * another tests.rs * Signed BLS * Revert "another tests.rs" This reverts commit7f54e9c1ce. * Revert "Signed BLS" This reverts commit1146bc734b. * withdrawal_keyparis * Fix genesis * block gossip * Add definition for BlockGossip * Fix block gossip * Tests.rs * Update block and events * Add bls event * Event bls * tests..rs * change order * another tests.rs * Signed BLS * Revert "another tests.rs" This reverts commit7f54e9c1ce. * Revert "Signed BLS" This reverts commit1146bc734b. * block gossip * Add definition for BlockGossip * Fix block gossip * Tests.rs * Update block and events * Merge branch 'BeaconAPI-events-block-gossip' of https://github.com/chong-he/lighthouse into BeaconAPI-events-block-gossip * Remove tests * Tests.rs * Tests.rs * Tests.rs * Tests similar to block event * Update common/eth2/src/types.rs Co-authored-by: Michael Sproul <micsproul@gmail.com> * Merge remote-tracking branch 'origin/unstable' into BeaconAPI-events-block-gossip * Fix tests
This commit is contained in:
@@ -67,7 +67,7 @@ use crate::{
|
||||
metrics, BeaconChain, BeaconChainError, BeaconChainTypes,
|
||||
};
|
||||
use derivative::Derivative;
|
||||
use eth2::types::{EventKind, PublishBlockRequest};
|
||||
use eth2::types::{BlockGossip, EventKind, PublishBlockRequest};
|
||||
use execution_layer::PayloadStatus;
|
||||
pub use fork_choice::{AttestationFromBlock, PayloadVerificationStatus};
|
||||
use parking_lot::RwLockReadGuard;
|
||||
@@ -974,6 +974,16 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
|
||||
// Validate the block's execution_payload (if any).
|
||||
validate_execution_payload_for_gossip(&parent_block, block.message(), chain)?;
|
||||
|
||||
// Beacon API block_gossip events
|
||||
if let Some(event_handler) = chain.event_handler.as_ref() {
|
||||
if event_handler.has_block_gossip_subscribers() {
|
||||
event_handler.register(EventKind::BlockGossip(Box::new(BlockGossip {
|
||||
slot: block.slot(),
|
||||
block: block_root,
|
||||
})));
|
||||
}
|
||||
}
|
||||
|
||||
// Having checked the proposer index and the block root we can cache them.
|
||||
let consensus_context = ConsensusContext::new(block.slot())
|
||||
.set_current_block_root(block_root)
|
||||
|
||||
@@ -23,6 +23,7 @@ pub struct ServerSentEventHandler<E: EthSpec> {
|
||||
proposer_slashing_tx: Sender<EventKind<E>>,
|
||||
attester_slashing_tx: Sender<EventKind<E>>,
|
||||
bls_to_execution_change_tx: Sender<EventKind<E>>,
|
||||
block_gossip_tx: Sender<EventKind<E>>,
|
||||
log: Logger,
|
||||
}
|
||||
|
||||
@@ -51,6 +52,7 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
let (proposer_slashing_tx, _) = broadcast::channel(capacity);
|
||||
let (attester_slashing_tx, _) = broadcast::channel(capacity);
|
||||
let (bls_to_execution_change_tx, _) = broadcast::channel(capacity);
|
||||
let (block_gossip_tx, _) = broadcast::channel(capacity);
|
||||
|
||||
Self {
|
||||
attestation_tx,
|
||||
@@ -69,6 +71,7 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
proposer_slashing_tx,
|
||||
attester_slashing_tx,
|
||||
bls_to_execution_change_tx,
|
||||
block_gossip_tx,
|
||||
log,
|
||||
}
|
||||
}
|
||||
@@ -147,6 +150,10 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
.bls_to_execution_change_tx
|
||||
.send(kind)
|
||||
.map(|count| log_count("bls to execution change", count)),
|
||||
EventKind::BlockGossip(_) => self
|
||||
.block_gossip_tx
|
||||
.send(kind)
|
||||
.map(|count| log_count("block gossip", count)),
|
||||
};
|
||||
if let Err(SendError(event)) = result {
|
||||
trace!(self.log, "No receivers registered to listen for event"; "event" => ?event);
|
||||
@@ -217,6 +224,10 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
self.bls_to_execution_change_tx.subscribe()
|
||||
}
|
||||
|
||||
pub fn subscribe_block_gossip(&self) -> Receiver<EventKind<E>> {
|
||||
self.block_gossip_tx.subscribe()
|
||||
}
|
||||
|
||||
pub fn has_attestation_subscribers(&self) -> bool {
|
||||
self.attestation_tx.receiver_count() > 0
|
||||
}
|
||||
@@ -272,4 +283,8 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
pub fn has_bls_to_execution_change_subscribers(&self) -> bool {
|
||||
self.bls_to_execution_change_tx.receiver_count() > 0
|
||||
}
|
||||
|
||||
pub fn has_block_gossip_subscribers(&self) -> bool {
|
||||
self.block_gossip_tx.receiver_count() > 0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user