mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 12:47:05 +00:00
proposer preferences SSE event
This commit is contained in:
@@ -29,6 +29,7 @@ pub struct ServerSentEventHandler<E: EthSpec> {
|
||||
execution_payload_gossip_tx: Sender<EventKind<E>>,
|
||||
execution_payload_available_tx: Sender<EventKind<E>>,
|
||||
execution_payload_bid_tx: Sender<EventKind<E>>,
|
||||
proposer_preferences_tx: Sender<EventKind<E>>,
|
||||
payload_attestation_message_tx: Sender<EventKind<E>>,
|
||||
}
|
||||
|
||||
@@ -60,6 +61,7 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
let (execution_payload_gossip_tx, _) = broadcast::channel(capacity);
|
||||
let (execution_payload_available_tx, _) = broadcast::channel(capacity);
|
||||
let (execution_payload_bid_tx, _) = broadcast::channel(capacity);
|
||||
let (proposer_preferences_tx, _) = broadcast::channel(capacity);
|
||||
let (payload_attestation_message_tx, _) = broadcast::channel(capacity);
|
||||
|
||||
Self {
|
||||
@@ -85,6 +87,7 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
execution_payload_gossip_tx,
|
||||
execution_payload_available_tx,
|
||||
execution_payload_bid_tx,
|
||||
proposer_preferences_tx,
|
||||
payload_attestation_message_tx,
|
||||
}
|
||||
}
|
||||
@@ -186,6 +189,10 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
.execution_payload_bid_tx
|
||||
.send(kind)
|
||||
.map(|count| log_count("execution payload bid", count)),
|
||||
EventKind::ProposerPreferences(_) => self
|
||||
.proposer_preferences_tx
|
||||
.send(kind)
|
||||
.map(|count| log_count("proposer preferences", count)),
|
||||
EventKind::PayloadAttestationMessage(_) => self
|
||||
.payload_attestation_message_tx
|
||||
.send(kind)
|
||||
@@ -284,6 +291,10 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
self.execution_payload_bid_tx.subscribe()
|
||||
}
|
||||
|
||||
pub fn subscribe_proposer_preferences(&self) -> Receiver<EventKind<E>> {
|
||||
self.proposer_preferences_tx.subscribe()
|
||||
}
|
||||
|
||||
pub fn subscribe_payload_attestation_message(&self) -> Receiver<EventKind<E>> {
|
||||
self.payload_attestation_message_tx.subscribe()
|
||||
}
|
||||
@@ -368,6 +379,10 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
self.execution_payload_bid_tx.receiver_count() > 0
|
||||
}
|
||||
|
||||
pub fn has_proposer_preferences_subscribers(&self) -> bool {
|
||||
self.proposer_preferences_tx.receiver_count() > 0
|
||||
}
|
||||
|
||||
pub fn has_payload_attestation_message_subscribers(&self) -> bool {
|
||||
self.payload_attestation_message_tx.receiver_count() > 0
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::{
|
||||
ProposerPreferencesError, proposer_preference_cache::GossipVerifiedProposerPreferenceCache,
|
||||
},
|
||||
};
|
||||
use eth2::types::{EventKind, ForkVersionedResponse};
|
||||
use slot_clock::SlotClock;
|
||||
use state_processing::signature_sets::{get_pubkey_from_state, proposer_preferences_signature_set};
|
||||
use tracing::debug;
|
||||
@@ -137,6 +138,19 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
%validator_index,
|
||||
"Successfully verified gossip proposer preferences"
|
||||
);
|
||||
|
||||
if let Some(event_handler) = self.event_handler.as_ref()
|
||||
&& event_handler.has_proposer_preferences_subscribers()
|
||||
{
|
||||
event_handler.register(EventKind::ProposerPreferences(Box::new(
|
||||
ForkVersionedResponse {
|
||||
version: self.spec.fork_name_at_slot::<T::EthSpec>(proposal_slot),
|
||||
metadata: Default::default(),
|
||||
data: (*verified.signed_preferences).clone(),
|
||||
},
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(verified)
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user