mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 03:12:41 +00:00
Serve rpc by range and by root:
This commit is contained in:
@@ -17,7 +17,8 @@ use types::light_client::consts::MAX_REQUEST_LIGHT_CLIENT_UPDATES;
|
||||
use types::{
|
||||
BlobSidecar, ChainSpec, ColumnIndex, DataColumnSidecar, DataColumnsByRootIdentifier, Epoch,
|
||||
EthSpec, ForkContext, Hash256, LightClientBootstrap, LightClientFinalityUpdate,
|
||||
LightClientOptimisticUpdate, LightClientUpdate, SignedBeaconBlock, Slot,
|
||||
LightClientOptimisticUpdate, LightClientUpdate, SignedBeaconBlock,
|
||||
SignedExecutionPayloadEnvelope, Slot,
|
||||
};
|
||||
|
||||
/// Maximum length of error message.
|
||||
@@ -362,6 +363,16 @@ impl BlocksByRangeRequest {
|
||||
}
|
||||
}
|
||||
|
||||
/// Request a number of execution payload envelopes from a peer.
|
||||
#[derive(Encode, Decode, Clone, Debug, PartialEq)]
|
||||
pub struct PayloadEnvelopesByRangeRequest {
|
||||
/// The starting slot to request execution payload envelopes.
|
||||
pub start_slot: u64,
|
||||
|
||||
/// The number of slots from the start slot.
|
||||
pub count: u64,
|
||||
}
|
||||
|
||||
/// Request a number of beacon blobs from a peer.
|
||||
#[derive(Encode, Decode, Clone, Debug, PartialEq)]
|
||||
pub struct BlobsByRangeRequest {
|
||||
@@ -505,6 +516,31 @@ impl BlocksByRootRequest {
|
||||
}
|
||||
}
|
||||
|
||||
/// Reqwuest a number of execution payload envelopes from a peer
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PayloadEnvelopesByRootRequest {
|
||||
/// The list of beacon block roots used to request execution payload envelopes.
|
||||
pub beacon_block_roots: RuntimeVariableList<Hash256>,
|
||||
}
|
||||
|
||||
impl PayloadEnvelopesByRootRequest {
|
||||
pub fn new(
|
||||
beacon_block_roots: Vec<Hash256>,
|
||||
fork_context: &ForkContext,
|
||||
) -> Result<Self, String> {
|
||||
let max_requests_envelopes = fork_context
|
||||
.spec
|
||||
.max_request_blocks(fork_context.current_fork_name());
|
||||
|
||||
let beacon_block_roots =
|
||||
RuntimeVariableList::new(beacon_block_roots, max_requests_envelopes).map_err(|e| {
|
||||
format!("ExecutionPayloadEnvelopesByRootRequest too many beacon block roots: {e:?}")
|
||||
})?;
|
||||
|
||||
Ok(Self { beacon_block_roots })
|
||||
}
|
||||
}
|
||||
|
||||
/// Request a number of beacon blocks and blobs from a peer.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct BlobsByRootRequest {
|
||||
@@ -588,6 +624,13 @@ pub enum RpcSuccessResponse<E: EthSpec> {
|
||||
/// A response to a get BLOCKS_BY_ROOT request.
|
||||
BlocksByRoot(Arc<SignedBeaconBlock<E>>),
|
||||
|
||||
/// A response to a get EXECUTION_PAYLOAD_ENVELOPES_BY_RANGE request. A None response signifies
|
||||
/// the end of the batch.
|
||||
PayloadEnvelopesbyRange(Arc<SignedExecutionPayloadEnvelope<E>>),
|
||||
|
||||
/// A response to a get EXECUTION_PAYLOAD_ENVELOPES_BY_ROOT request.
|
||||
PayloadEnvelopesByRoot(Arc<SignedExecutionPayloadEnvelope<E>>),
|
||||
|
||||
/// A response to a get BLOBS_BY_RANGE request
|
||||
BlobsByRange(Arc<BlobSidecar<E>>),
|
||||
|
||||
@@ -628,6 +671,12 @@ pub enum ResponseTermination {
|
||||
/// Blocks by root stream termination.
|
||||
BlocksByRoot,
|
||||
|
||||
/// Execution payload envelopes by range stream termination.
|
||||
PayloadEnvelopesByRange,
|
||||
|
||||
/// Execution payload envelopes by root stream termination.
|
||||
PayloadEnvelopesByRoot,
|
||||
|
||||
/// Blobs by range stream termination.
|
||||
BlobsByRange,
|
||||
|
||||
@@ -649,6 +698,8 @@ impl ResponseTermination {
|
||||
match self {
|
||||
ResponseTermination::BlocksByRange => Protocol::BlocksByRange,
|
||||
ResponseTermination::BlocksByRoot => Protocol::BlocksByRoot,
|
||||
ResponseTermination::PayloadEnvelopesByRange => Protocol::PayloadEnvelopesByRange,
|
||||
ResponseTermination::PayloadEnvelopesByRoot => Protocol::PayloadEnvelopesByRoot,
|
||||
ResponseTermination::BlobsByRange => Protocol::BlobsByRange,
|
||||
ResponseTermination::BlobsByRoot => Protocol::BlobsByRoot,
|
||||
ResponseTermination::DataColumnsByRoot => Protocol::DataColumnsByRoot,
|
||||
@@ -744,6 +795,8 @@ impl<E: EthSpec> RpcSuccessResponse<E> {
|
||||
RpcSuccessResponse::Status(_) => Protocol::Status,
|
||||
RpcSuccessResponse::BlocksByRange(_) => Protocol::BlocksByRange,
|
||||
RpcSuccessResponse::BlocksByRoot(_) => Protocol::BlocksByRoot,
|
||||
RpcSuccessResponse::PayloadEnvelopesbyRange(_) => Protocol::PayloadEnvelopesByRange,
|
||||
RpcSuccessResponse::PayloadEnvelopesByRoot(_) => Protocol::PayloadEnvelopesByRoot,
|
||||
RpcSuccessResponse::BlobsByRange(_) => Protocol::BlobsByRange,
|
||||
RpcSuccessResponse::BlobsByRoot(_) => Protocol::BlobsByRoot,
|
||||
RpcSuccessResponse::DataColumnsByRoot(_) => Protocol::DataColumnsByRoot,
|
||||
@@ -762,6 +815,7 @@ impl<E: EthSpec> RpcSuccessResponse<E> {
|
||||
pub fn slot(&self) -> Option<Slot> {
|
||||
match self {
|
||||
Self::BlocksByRange(r) | Self::BlocksByRoot(r) => Some(r.slot()),
|
||||
Self::PayloadEnvelopesByRoot(r) | Self::PayloadEnvelopesbyRange(r) => Some(r.slot()),
|
||||
Self::BlobsByRange(r) | Self::BlobsByRoot(r) => Some(r.slot()),
|
||||
Self::DataColumnsByRange(r) | Self::DataColumnsByRoot(r) => Some(r.slot()),
|
||||
Self::LightClientBootstrap(r) => Some(r.get_slot()),
|
||||
@@ -812,6 +866,20 @@ impl<E: EthSpec> std::fmt::Display for RpcSuccessResponse<E> {
|
||||
RpcSuccessResponse::BlocksByRoot(block) => {
|
||||
write!(f, "BlocksByRoot: Block slot: {}", block.slot())
|
||||
}
|
||||
RpcSuccessResponse::PayloadEnvelopesbyRange(envelope) => {
|
||||
write!(
|
||||
f,
|
||||
"ExecutionPayloadEnvelopesByRange: Envelope slot: {}",
|
||||
envelope.slot()
|
||||
)
|
||||
}
|
||||
RpcSuccessResponse::PayloadEnvelopesByRoot(envelope) => {
|
||||
write!(
|
||||
f,
|
||||
"ExecutionPayloadEnvelopesByRoot: Envelope slot: {}",
|
||||
envelope.slot()
|
||||
)
|
||||
}
|
||||
RpcSuccessResponse::BlobsByRange(blob) => {
|
||||
write!(f, "BlobsByRange: Blob slot: {}", blob.slot())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user