mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 22:34:45 +00:00
SSE and enw endpoint
This commit is contained in:
@@ -1101,6 +1101,14 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
|
||||
})));
|
||||
}
|
||||
|
||||
// Beacon API execution_payload_bid events
|
||||
if let Some(event_handler) = chain.event_handler.as_ref()
|
||||
&& event_handler.has_execution_payload_bid_subscribers()
|
||||
&& let Ok(bid) = block.message().body().signed_execution_payload_bid()
|
||||
{
|
||||
event_handler.register(EventKind::ExecutionPayloadBid(Box::new(bid.clone())));
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
@@ -26,6 +26,8 @@ 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_bid_tx: Sender<EventKind<E>>,
|
||||
execution_payload_available_tx: Sender<EventKind<E>>,
|
||||
}
|
||||
|
||||
impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
@@ -53,6 +55,8 @@ 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_bid_tx, _) = broadcast::channel(capacity);
|
||||
let (execution_payload_available_tx, _) = broadcast::channel(capacity);
|
||||
|
||||
Self {
|
||||
attestation_tx,
|
||||
@@ -74,6 +78,8 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
attester_slashing_tx,
|
||||
bls_to_execution_change_tx,
|
||||
block_gossip_tx,
|
||||
execution_payload_bid_tx,
|
||||
execution_payload_available_tx,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +168,14 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
.block_gossip_tx
|
||||
.send(kind)
|
||||
.map(|count| log_count("block gossip", count)),
|
||||
EventKind::ExecutionPayloadBid(_) => self
|
||||
.execution_payload_bid_tx
|
||||
.send(kind)
|
||||
.map(|count| log_count("execution payload bid", count)),
|
||||
EventKind::ExecutionPayloadAvailable(_) => self
|
||||
.execution_payload_available_tx
|
||||
.send(kind)
|
||||
.map(|count| log_count("execution payload available", count)),
|
||||
};
|
||||
if let Err(SendError(event)) = result {
|
||||
trace!(?event, "No receivers registered to listen for event");
|
||||
@@ -311,4 +325,20 @@ impl<E: EthSpec> ServerSentEventHandler<E> {
|
||||
pub fn has_block_gossip_subscribers(&self) -> bool {
|
||||
self.block_gossip_tx.receiver_count() > 0
|
||||
}
|
||||
|
||||
pub fn subscribe_execution_payload_bid(&self) -> Receiver<EventKind<E>> {
|
||||
self.execution_payload_bid_tx.subscribe()
|
||||
}
|
||||
|
||||
pub fn subscribe_execution_payload_available(&self) -> Receiver<EventKind<E>> {
|
||||
self.execution_payload_available_tx.subscribe()
|
||||
}
|
||||
|
||||
pub fn has_execution_payload_bid_subscribers(&self) -> bool {
|
||||
self.execution_payload_bid_tx.receiver_count() > 0
|
||||
}
|
||||
|
||||
pub fn has_execution_payload_available_subscribers(&self) -> bool {
|
||||
self.execution_payload_available_tx.receiver_count() > 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,9 +387,18 @@ pub fn get_execution_payload<T: BeaconChainTypes>(
|
||||
let timestamp =
|
||||
compute_timestamp_at_slot(state, state.slot(), spec).map_err(BeaconStateError::from)?;
|
||||
let random = *state.get_randao_mix(current_epoch)?;
|
||||
let latest_execution_payload_header = state.latest_execution_payload_header()?;
|
||||
let latest_execution_payload_header_block_hash = latest_execution_payload_header.block_hash();
|
||||
let latest_execution_payload_header_gas_limit = latest_execution_payload_header.gas_limit();
|
||||
// In GLOAS (ePBS), the execution payload header is replaced by
|
||||
// `latest_block_hash` and `latest_execution_payload_bid`.
|
||||
let (latest_execution_payload_header_block_hash, latest_execution_payload_header_gas_limit) =
|
||||
if state.fork_name_unchecked() == ForkName::Gloas {
|
||||
(
|
||||
*state.latest_block_hash()?,
|
||||
state.latest_execution_payload_bid()?.gas_limit,
|
||||
)
|
||||
} else {
|
||||
let header = state.latest_execution_payload_header()?;
|
||||
(header.block_hash(), header.gas_limit())
|
||||
};
|
||||
let withdrawals = if state.fork_name_unchecked().capella_enabled() {
|
||||
Some(Withdrawals::<T::EthSpec>::from(get_expected_withdrawals(state, spec)?).into())
|
||||
} else {
|
||||
|
||||
@@ -19,6 +19,7 @@ use crate::{
|
||||
metrics,
|
||||
validator_monitor::{get_slot_delay_ms, timestamp_now},
|
||||
};
|
||||
use eth2::types::{EventKind, SseExecutionPayloadAvailable};
|
||||
|
||||
impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
/// Returns `Ok(block_root)` if the given `unverified_envelope` was successfully verified and
|
||||
@@ -357,6 +358,16 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO(gloas) emit SSE event for envelope import (similar to SseBlock for blocks).
|
||||
// Beacon API execution_payload_available events
|
||||
if let Some(event_handler) = self.event_handler.as_ref()
|
||||
&& event_handler.has_execution_payload_available_subscribers()
|
||||
{
|
||||
event_handler.register(EventKind::ExecutionPayloadAvailable(
|
||||
SseExecutionPayloadAvailable {
|
||||
slot: envelope_slot,
|
||||
block_root,
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user