mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-02 04:03:35 +00:00
SSE and enw endpoint
This commit is contained in:
@@ -2655,6 +2655,55 @@ impl BeaconNodeHttpClient {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Path for `v1/beacon/execution_payload_envelope/{block_id}`
|
||||
pub fn get_beacon_execution_payload_envelope_path(
|
||||
&self,
|
||||
block_id: BlockId,
|
||||
) -> Result<Url, Error> {
|
||||
let mut path = self.eth_path(V1)?;
|
||||
path.path_segments_mut()
|
||||
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
|
||||
.push("beacon")
|
||||
.push("execution_payload_envelope")
|
||||
.push(&block_id.to_string());
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
/// `GET v1/beacon/execution_payload_envelope/{block_id}`
|
||||
///
|
||||
/// Returns `Ok(None)` on a 404 error.
|
||||
pub async fn get_beacon_execution_payload_envelope<E: EthSpec>(
|
||||
&self,
|
||||
block_id: BlockId,
|
||||
) -> Result<Option<ExecutionOptimisticFinalizedBeaconResponse<SignedExecutionPayloadEnvelope<E>>>, Error>
|
||||
{
|
||||
let path = self.get_beacon_execution_payload_envelope_path(block_id)?;
|
||||
self.get_opt(path)
|
||||
.await
|
||||
.map(|opt| opt.map(BeaconResponse::ForkVersioned))
|
||||
}
|
||||
|
||||
/// `GET v1/beacon/execution_payload_envelope/{block_id}` in SSZ format
|
||||
///
|
||||
/// Returns `Ok(None)` on a 404 error.
|
||||
pub async fn get_beacon_execution_payload_envelope_ssz<E: EthSpec>(
|
||||
&self,
|
||||
block_id: BlockId,
|
||||
) -> Result<Option<SignedExecutionPayloadEnvelope<E>>, Error> {
|
||||
let path = self.get_beacon_execution_payload_envelope_path(block_id)?;
|
||||
let opt_response = self
|
||||
.get_bytes_opt_accept_header(path, Accept::Ssz, self.timeouts.get_beacon_blocks_ssz)
|
||||
.await?;
|
||||
match opt_response {
|
||||
Some(bytes) => {
|
||||
SignedExecutionPayloadEnvelope::from_ssz_bytes(&bytes)
|
||||
.map(Some)
|
||||
.map_err(Error::InvalidSsz)
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// `GET v2/validator/blocks/{slot}` in ssz format
|
||||
pub async fn get_validator_blocks_ssz<E: EthSpec>(
|
||||
&self,
|
||||
|
||||
@@ -1064,6 +1064,12 @@ pub struct BlockGossip {
|
||||
pub slot: Slot,
|
||||
pub block: Hash256,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
|
||||
pub struct SseExecutionPayloadAvailable {
|
||||
pub slot: Slot,
|
||||
pub block_root: Hash256,
|
||||
}
|
||||
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct SseChainReorg {
|
||||
pub slot: Slot,
|
||||
@@ -1206,6 +1212,8 @@ pub enum EventKind<E: EthSpec> {
|
||||
AttesterSlashing(Box<AttesterSlashing<E>>),
|
||||
BlsToExecutionChange(Box<SignedBlsToExecutionChange>),
|
||||
BlockGossip(Box<BlockGossip>),
|
||||
ExecutionPayloadBid(Box<SignedExecutionPayloadBid<E>>),
|
||||
ExecutionPayloadAvailable(SseExecutionPayloadAvailable),
|
||||
}
|
||||
|
||||
impl<E: EthSpec> EventKind<E> {
|
||||
@@ -1231,6 +1239,8 @@ impl<E: EthSpec> EventKind<E> {
|
||||
EventKind::AttesterSlashing(_) => "attester_slashing",
|
||||
EventKind::BlsToExecutionChange(_) => "bls_to_execution_change",
|
||||
EventKind::BlockGossip(_) => "block_gossip",
|
||||
EventKind::ExecutionPayloadBid(_) => "execution_payload_bid",
|
||||
EventKind::ExecutionPayloadAvailable(_) => "execution_payload_available",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1324,6 +1334,22 @@ impl<E: EthSpec> EventKind<E> {
|
||||
"block_gossip" => Ok(EventKind::BlockGossip(serde_json::from_str(data).map_err(
|
||||
|e| ServerError::InvalidServerSentEvent(format!("Block Gossip: {:?}", e)),
|
||||
)?)),
|
||||
"execution_payload_bid" => Ok(EventKind::ExecutionPayloadBid(
|
||||
serde_json::from_str(data).map_err(|e| {
|
||||
ServerError::InvalidServerSentEvent(format!(
|
||||
"Execution Payload Bid: {:?}",
|
||||
e
|
||||
))
|
||||
})?,
|
||||
)),
|
||||
"execution_payload_available" => Ok(EventKind::ExecutionPayloadAvailable(
|
||||
serde_json::from_str(data).map_err(|e| {
|
||||
ServerError::InvalidServerSentEvent(format!(
|
||||
"Execution Payload Available: {:?}",
|
||||
e
|
||||
))
|
||||
})?,
|
||||
)),
|
||||
_ => Err(ServerError::InvalidServerSentEvent(
|
||||
"Could not parse event tag".to_string(),
|
||||
)),
|
||||
@@ -1361,6 +1387,8 @@ pub enum EventTopic {
|
||||
ProposerSlashing,
|
||||
BlsToExecutionChange,
|
||||
BlockGossip,
|
||||
ExecutionPayloadBid,
|
||||
ExecutionPayloadAvailable,
|
||||
}
|
||||
|
||||
impl FromStr for EventTopic {
|
||||
@@ -1388,6 +1416,8 @@ impl FromStr for EventTopic {
|
||||
"proposer_slashing" => Ok(EventTopic::ProposerSlashing),
|
||||
"bls_to_execution_change" => Ok(EventTopic::BlsToExecutionChange),
|
||||
"block_gossip" => Ok(EventTopic::BlockGossip),
|
||||
"execution_payload_bid" => Ok(EventTopic::ExecutionPayloadBid),
|
||||
"execution_payload_available" => Ok(EventTopic::ExecutionPayloadAvailable),
|
||||
_ => Err("event topic cannot be parsed.".to_string()),
|
||||
}
|
||||
}
|
||||
@@ -1416,6 +1446,8 @@ impl fmt::Display for EventTopic {
|
||||
EventTopic::ProposerSlashing => write!(f, "proposer_slashing"),
|
||||
EventTopic::BlsToExecutionChange => write!(f, "bls_to_execution_change"),
|
||||
EventTopic::BlockGossip => write!(f, "block_gossip"),
|
||||
EventTopic::ExecutionPayloadBid => write!(f, "execution_payload_bid"),
|
||||
EventTopic::ExecutionPayloadAvailable => write!(f, "execution_payload_available"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user