Add Gloas SSE event boilerplate (#9053)

Implement boilerplate for new SSE events as specified in
- https://github.com/ethereum/beacon-APIs/pull/588

While that one is not merged yet, I believe the SSE events might be utilized in Dora already.


  Implement the boilerplate, i.e. subscription tracking and publish queues. A PR to implement to fully implement already implementable events will follow.


Co-Authored-By: Daniel Knopik <daniel@dknopik.de>
This commit is contained in:
Daniel Knopik
2026-03-31 08:16:34 +02:00
committed by GitHub
parent d92efc1e0f
commit 2b224c59f7
3 changed files with 182 additions and 0 deletions

View File

@@ -25,6 +25,11 @@ pub struct ServerSentEventHandler<E: EthSpec> {
attester_slashing_tx: Sender<EventKind<E>>,
bls_to_execution_change_tx: Sender<EventKind<E>>,
block_gossip_tx: Sender<EventKind<E>>,
execution_payload_tx: Sender<EventKind<E>>,
execution_payload_gossip_tx: Sender<EventKind<E>>,
execution_payload_available_tx: Sender<EventKind<E>>,
execution_payload_bid_tx: Sender<EventKind<E>>,
payload_attestation_message_tx: Sender<EventKind<E>>,
}
impl<E: EthSpec> ServerSentEventHandler<E> {
@@ -51,6 +56,11 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
let (attester_slashing_tx, _) = broadcast::channel(capacity);
let (bls_to_execution_change_tx, _) = broadcast::channel(capacity);
let (block_gossip_tx, _) = broadcast::channel(capacity);
let (execution_payload_tx, _) = broadcast::channel(capacity);
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 (payload_attestation_message_tx, _) = broadcast::channel(capacity);
Self {
attestation_tx,
@@ -71,6 +81,11 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
attester_slashing_tx,
bls_to_execution_change_tx,
block_gossip_tx,
execution_payload_tx,
execution_payload_gossip_tx,
execution_payload_available_tx,
execution_payload_bid_tx,
payload_attestation_message_tx,
}
}
@@ -155,6 +170,26 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
.block_gossip_tx
.send(kind)
.map(|count| log_count("block gossip", count)),
EventKind::ExecutionPayload(_) => self
.execution_payload_tx
.send(kind)
.map(|count| log_count("execution payload", count)),
EventKind::ExecutionPayloadGossip(_) => self
.execution_payload_gossip_tx
.send(kind)
.map(|count| log_count("execution payload gossip", count)),
EventKind::ExecutionPayloadAvailable(_) => self
.execution_payload_available_tx
.send(kind)
.map(|count| log_count("execution payload available", count)),
EventKind::ExecutionPayloadBid(_) => self
.execution_payload_bid_tx
.send(kind)
.map(|count| log_count("execution payload bid", count)),
EventKind::PayloadAttestationMessage(_) => self
.payload_attestation_message_tx
.send(kind)
.map(|count| log_count("payload attestation message", count)),
};
if let Err(SendError(event)) = result {
trace!(?event, "No receivers registered to listen for event");
@@ -233,6 +268,26 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
self.block_gossip_tx.subscribe()
}
pub fn subscribe_execution_payload(&self) -> Receiver<EventKind<E>> {
self.execution_payload_tx.subscribe()
}
pub fn subscribe_execution_payload_gossip(&self) -> Receiver<EventKind<E>> {
self.execution_payload_gossip_tx.subscribe()
}
pub fn subscribe_execution_payload_available(&self) -> Receiver<EventKind<E>> {
self.execution_payload_available_tx.subscribe()
}
pub fn subscribe_execution_payload_bid(&self) -> Receiver<EventKind<E>> {
self.execution_payload_bid_tx.subscribe()
}
pub fn subscribe_payload_attestation_message(&self) -> Receiver<EventKind<E>> {
self.payload_attestation_message_tx.subscribe()
}
pub fn has_attestation_subscribers(&self) -> bool {
self.attestation_tx.receiver_count() > 0
}
@@ -296,4 +351,24 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
pub fn has_block_gossip_subscribers(&self) -> bool {
self.block_gossip_tx.receiver_count() > 0
}
pub fn has_execution_payload_subscribers(&self) -> bool {
self.execution_payload_tx.receiver_count() > 0
}
pub fn has_execution_payload_gossip_subscribers(&self) -> bool {
self.execution_payload_gossip_tx.receiver_count() > 0
}
pub fn has_execution_payload_available_subscribers(&self) -> bool {
self.execution_payload_available_tx.receiver_count() > 0
}
pub fn has_execution_payload_bid_subscribers(&self) -> bool {
self.execution_payload_bid_tx.receiver_count() > 0
}
pub fn has_payload_attestation_message_subscribers(&self) -> bool {
self.payload_attestation_message_tx.receiver_count() > 0
}
}