mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-31 13:17:09 +00:00
Implement beacon_blocks_by_head (#9237)
Co-Authored-By: dapplion <35266934+dapplion@users.noreply.github.com>
This commit is contained in:
@@ -18,7 +18,7 @@ use tokio_util::codec::{Decoder, Encoder};
|
||||
use types::SignedExecutionPayloadEnvelope;
|
||||
use types::{
|
||||
BlobSidecar, ChainSpec, DataColumnSidecar, DataColumnsByRootIdentifier, EthSpec, ForkContext,
|
||||
ForkName, Hash256, LightClientBootstrap, LightClientFinalityUpdate,
|
||||
ForkName, ForkVersionDecode, Hash256, LightClientBootstrap, LightClientFinalityUpdate,
|
||||
LightClientOptimisticUpdate, LightClientUpdate, SignedBeaconBlock, SignedBeaconBlockAltair,
|
||||
SignedBeaconBlockBase, SignedBeaconBlockBellatrix, SignedBeaconBlockCapella,
|
||||
SignedBeaconBlockDeneb, SignedBeaconBlockElectra, SignedBeaconBlockFulu,
|
||||
@@ -77,6 +77,7 @@ impl<E: EthSpec> SSZSnappyInboundCodec<E> {
|
||||
},
|
||||
RpcSuccessResponse::BlocksByRange(res) => res.as_ssz_bytes(),
|
||||
RpcSuccessResponse::BlocksByRoot(res) => res.as_ssz_bytes(),
|
||||
RpcSuccessResponse::BlocksByHead(res) => res.as_ssz_bytes(),
|
||||
RpcSuccessResponse::PayloadEnvelopesByRange(res) => res.as_ssz_bytes(),
|
||||
RpcSuccessResponse::PayloadEnvelopesByRoot(res) => res.as_ssz_bytes(),
|
||||
RpcSuccessResponse::BlobsByRange(res) => res.as_ssz_bytes(),
|
||||
@@ -359,6 +360,7 @@ impl<E: EthSpec> Encoder<RequestType<E>> for SSZSnappyOutboundCodec<E> {
|
||||
BlocksByRootRequest::V1(req) => req.block_roots.as_ssz_bytes(),
|
||||
BlocksByRootRequest::V2(req) => req.block_roots.as_ssz_bytes(),
|
||||
},
|
||||
RequestType::BlocksByHead(req) => req.as_ssz_bytes(),
|
||||
RequestType::PayloadEnvelopesByRange(req) => req.as_ssz_bytes(),
|
||||
RequestType::PayloadEnvelopesByRoot(req) => req.beacon_block_roots.as_ssz_bytes(),
|
||||
RequestType::BlobsByRange(req) => req.as_ssz_bytes(),
|
||||
@@ -553,6 +555,9 @@ fn handle_rpc_request<E: EthSpec>(
|
||||
)?,
|
||||
}),
|
||||
))),
|
||||
SupportedProtocol::BlocksByHeadV1 => Ok(Some(RequestType::BlocksByHead(
|
||||
BlocksByHeadRequest::from_ssz_bytes(decoded_buffer)?,
|
||||
))),
|
||||
SupportedProtocol::PayloadEnvelopesByRangeV1 => {
|
||||
Ok(Some(RequestType::PayloadEnvelopesByRange(
|
||||
PayloadEnvelopesByRangeRequest::from_ssz_bytes(decoded_buffer)?,
|
||||
@@ -943,6 +948,18 @@ fn handle_rpc_response<E: EthSpec>(
|
||||
),
|
||||
)),
|
||||
},
|
||||
SupportedProtocol::BlocksByHeadV1 => match fork_name {
|
||||
Some(fork_name) => Ok(Some(RpcSuccessResponse::BlocksByHead(Arc::new(
|
||||
SignedBeaconBlock::from_ssz_bytes_by_fork(decoded_buffer, fork_name)?,
|
||||
)))),
|
||||
None => Err(RPCError::ErrorResponse(
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
format!(
|
||||
"No context bytes provided for {:?} response",
|
||||
versioned_protocol
|
||||
),
|
||||
)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1319,6 +1336,9 @@ mod tests {
|
||||
RequestType::BlocksByRoot(bbroot) => {
|
||||
assert_eq!(decoded, RequestType::BlocksByRoot(bbroot))
|
||||
}
|
||||
RequestType::BlocksByHead(bbhead) => {
|
||||
assert_eq!(decoded, RequestType::BlocksByHead(bbhead))
|
||||
}
|
||||
RequestType::BlobsByRange(blbrange) => {
|
||||
assert_eq!(decoded, RequestType::BlobsByRange(blbrange))
|
||||
}
|
||||
@@ -1867,6 +1887,31 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// BlocksByHead is introduced in Fulu but the response is just `SignedBeaconBlock`,
|
||||
// so the codec must accept blocks of any fork variant — the chain a Fulu peer walks
|
||||
// back may straddle the Fulu boundary and include pre-Fulu canonical blocks.
|
||||
#[test]
|
||||
fn test_blocks_by_head_decodes_all_forks() {
|
||||
let chain_spec = spec_with_all_forks_enabled();
|
||||
for (block, fork) in [
|
||||
(empty_base_block(&chain_spec), ForkName::Base),
|
||||
(altair_block(&chain_spec), ForkName::Altair),
|
||||
(bellatrix_block_small(&chain_spec), ForkName::Bellatrix),
|
||||
] {
|
||||
let block_arc = Arc::new(block);
|
||||
assert_eq!(
|
||||
encode_then_decode_response(
|
||||
SupportedProtocol::BlocksByHeadV1,
|
||||
RpcResponse::Success(RpcSuccessResponse::BlocksByHead(block_arc.clone())),
|
||||
fork,
|
||||
&chain_spec,
|
||||
),
|
||||
Ok(Some(RpcSuccessResponse::BlocksByHead(block_arc))),
|
||||
"BlocksByHeadV1 must round-trip a {fork} block"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Test RPCResponse encoding/decoding for V2 messages
|
||||
#[test]
|
||||
fn test_context_bytes_v2() {
|
||||
@@ -2063,6 +2108,10 @@ mod tests {
|
||||
RequestType::BlobsByRange(blbrange_request()),
|
||||
RequestType::DataColumnsByRange(dcbrange_request()),
|
||||
RequestType::MetaData(MetadataRequest::new_v2()),
|
||||
RequestType::BlocksByHead(BlocksByHeadRequest {
|
||||
beacon_root: Hash256::zero(),
|
||||
count: 32,
|
||||
}),
|
||||
];
|
||||
for req in requests.iter() {
|
||||
for fork_name in ForkName::list_all() {
|
||||
|
||||
@@ -89,6 +89,7 @@ pub struct RateLimiterConfig {
|
||||
pub(super) goodbye_quota: Quota,
|
||||
pub(super) blocks_by_range_quota: Quota,
|
||||
pub(super) blocks_by_root_quota: Quota,
|
||||
pub(super) blocks_by_head_quota: Quota,
|
||||
pub(super) payload_envelopes_by_range_quota: Quota,
|
||||
pub(super) payload_envelopes_by_root_quota: Quota,
|
||||
pub(super) blobs_by_range_quota: Quota,
|
||||
@@ -113,6 +114,8 @@ impl RateLimiterConfig {
|
||||
Quota::n_every(NonZeroU64::new(128).unwrap(), 10);
|
||||
pub const DEFAULT_BLOCKS_BY_ROOT_QUOTA: Quota =
|
||||
Quota::n_every(NonZeroU64::new(128).unwrap(), 10);
|
||||
pub const DEFAULT_BLOCKS_BY_HEAD_QUOTA: Quota =
|
||||
Quota::n_every(NonZeroU64::new(128).unwrap(), 10);
|
||||
pub const DEFAULT_PAYLOAD_ENVELOPES_BY_RANGE_QUOTA: Quota =
|
||||
Quota::n_every(NonZeroU64::new(128).unwrap(), 10);
|
||||
pub const DEFAULT_PAYLOAD_ENVELOPES_BY_ROOT_QUOTA: Quota =
|
||||
@@ -143,6 +146,7 @@ impl Default for RateLimiterConfig {
|
||||
goodbye_quota: Self::DEFAULT_GOODBYE_QUOTA,
|
||||
blocks_by_range_quota: Self::DEFAULT_BLOCKS_BY_RANGE_QUOTA,
|
||||
blocks_by_root_quota: Self::DEFAULT_BLOCKS_BY_ROOT_QUOTA,
|
||||
blocks_by_head_quota: Self::DEFAULT_BLOCKS_BY_HEAD_QUOTA,
|
||||
payload_envelopes_by_range_quota: Self::DEFAULT_PAYLOAD_ENVELOPES_BY_RANGE_QUOTA,
|
||||
payload_envelopes_by_root_quota: Self::DEFAULT_PAYLOAD_ENVELOPES_BY_ROOT_QUOTA,
|
||||
blobs_by_range_quota: Self::DEFAULT_BLOBS_BY_RANGE_QUOTA,
|
||||
@@ -177,6 +181,7 @@ impl Debug for RateLimiterConfig {
|
||||
.field("goodbye", fmt_q!(&self.goodbye_quota))
|
||||
.field("blocks_by_range", fmt_q!(&self.blocks_by_range_quota))
|
||||
.field("blocks_by_root", fmt_q!(&self.blocks_by_root_quota))
|
||||
.field("blocks_by_head", fmt_q!(&self.blocks_by_head_quota))
|
||||
.field(
|
||||
"payload_envelopes_by_range",
|
||||
fmt_q!(&self.payload_envelopes_by_range_quota),
|
||||
@@ -213,6 +218,7 @@ impl FromStr for RateLimiterConfig {
|
||||
let mut goodbye_quota = None;
|
||||
let mut blocks_by_range_quota = None;
|
||||
let mut blocks_by_root_quota = None;
|
||||
let mut blocks_by_head_quota = None;
|
||||
let mut payload_envelopes_by_range_quota = None;
|
||||
let mut payload_envelopes_by_root_quota = None;
|
||||
let mut blobs_by_range_quota = None;
|
||||
@@ -232,6 +238,7 @@ impl FromStr for RateLimiterConfig {
|
||||
Protocol::Goodbye => goodbye_quota = goodbye_quota.or(quota),
|
||||
Protocol::BlocksByRange => blocks_by_range_quota = blocks_by_range_quota.or(quota),
|
||||
Protocol::BlocksByRoot => blocks_by_root_quota = blocks_by_root_quota.or(quota),
|
||||
Protocol::BlocksByHead => blocks_by_head_quota = blocks_by_head_quota.or(quota),
|
||||
Protocol::PayloadEnvelopesByRange => {
|
||||
payload_envelopes_by_range_quota = payload_envelopes_by_range_quota.or(quota)
|
||||
}
|
||||
@@ -274,6 +281,8 @@ impl FromStr for RateLimiterConfig {
|
||||
.unwrap_or(Self::DEFAULT_BLOCKS_BY_RANGE_QUOTA),
|
||||
blocks_by_root_quota: blocks_by_root_quota
|
||||
.unwrap_or(Self::DEFAULT_BLOCKS_BY_ROOT_QUOTA),
|
||||
blocks_by_head_quota: blocks_by_head_quota
|
||||
.unwrap_or(Self::DEFAULT_BLOCKS_BY_HEAD_QUOTA),
|
||||
payload_envelopes_by_range_quota: payload_envelopes_by_range_quota
|
||||
.unwrap_or(Self::DEFAULT_PAYLOAD_ENVELOPES_BY_RANGE_QUOTA),
|
||||
payload_envelopes_by_root_quota: payload_envelopes_by_root_quota
|
||||
|
||||
@@ -488,6 +488,18 @@ impl From<BlocksByRangeRequest> for OldBlocksByRangeRequest {
|
||||
}
|
||||
}
|
||||
|
||||
/// Request a contiguous range of beacon blocks by walking the parent chain of `beacon_root`.
|
||||
///
|
||||
/// New in Fulu (see consensus-specs PR 5181). The responder walks the parent chain of
|
||||
/// `beacon_root` (inclusive) and emits up to `count` blocks in descending slot order.
|
||||
#[derive(Encode, Decode, Clone, Debug, PartialEq)]
|
||||
pub struct BlocksByHeadRequest {
|
||||
/// The block root to start the parent walk from (inclusive).
|
||||
pub beacon_root: Hash256,
|
||||
/// The maximum number of blocks to return.
|
||||
pub count: u64,
|
||||
}
|
||||
|
||||
/// Request a number of beacon block bodies from a peer.
|
||||
#[superstruct(variants(V1, V2), variant_attributes(derive(Clone, Debug, PartialEq)))]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -622,6 +634,9 @@ pub enum RpcSuccessResponse<E: EthSpec> {
|
||||
/// A response to a get BLOCKS_BY_ROOT request.
|
||||
BlocksByRoot(Arc<SignedBeaconBlock<E>>),
|
||||
|
||||
/// A response to a get BEACON_BLOCKS_BY_HEAD request.
|
||||
BlocksByHead(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>>),
|
||||
@@ -669,6 +684,9 @@ pub enum ResponseTermination {
|
||||
/// Blocks by root stream termination.
|
||||
BlocksByRoot,
|
||||
|
||||
/// Blocks by head stream termination.
|
||||
BlocksByHead,
|
||||
|
||||
/// Execution payload envelopes by range stream termination.
|
||||
PayloadEnvelopesByRange,
|
||||
|
||||
@@ -696,6 +714,7 @@ impl ResponseTermination {
|
||||
match self {
|
||||
ResponseTermination::BlocksByRange => Protocol::BlocksByRange,
|
||||
ResponseTermination::BlocksByRoot => Protocol::BlocksByRoot,
|
||||
ResponseTermination::BlocksByHead => Protocol::BlocksByHead,
|
||||
ResponseTermination::PayloadEnvelopesByRange => Protocol::PayloadEnvelopesByRange,
|
||||
ResponseTermination::PayloadEnvelopesByRoot => Protocol::PayloadEnvelopesByRoot,
|
||||
ResponseTermination::BlobsByRange => Protocol::BlobsByRange,
|
||||
@@ -793,6 +812,7 @@ impl<E: EthSpec> RpcSuccessResponse<E> {
|
||||
RpcSuccessResponse::Status(_) => Protocol::Status,
|
||||
RpcSuccessResponse::BlocksByRange(_) => Protocol::BlocksByRange,
|
||||
RpcSuccessResponse::BlocksByRoot(_) => Protocol::BlocksByRoot,
|
||||
RpcSuccessResponse::BlocksByHead(_) => Protocol::BlocksByHead,
|
||||
RpcSuccessResponse::PayloadEnvelopesByRange(_) => Protocol::PayloadEnvelopesByRange,
|
||||
RpcSuccessResponse::PayloadEnvelopesByRoot(_) => Protocol::PayloadEnvelopesByRoot,
|
||||
RpcSuccessResponse::BlobsByRange(_) => Protocol::BlobsByRange,
|
||||
@@ -812,7 +832,9 @@ impl<E: EthSpec> RpcSuccessResponse<E> {
|
||||
|
||||
pub fn slot(&self) -> Option<Slot> {
|
||||
match self {
|
||||
Self::BlocksByRange(r) | Self::BlocksByRoot(r) => Some(r.slot()),
|
||||
Self::BlocksByRange(r) | Self::BlocksByRoot(r) | Self::BlocksByHead(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()),
|
||||
@@ -864,6 +886,9 @@ impl<E: EthSpec> std::fmt::Display for RpcSuccessResponse<E> {
|
||||
RpcSuccessResponse::BlocksByRoot(block) => {
|
||||
write!(f, "BlocksByRoot: Block slot: {}", block.slot())
|
||||
}
|
||||
RpcSuccessResponse::BlocksByHead(block) => {
|
||||
write!(f, "BlocksByHead: Block slot: {}", block.slot())
|
||||
}
|
||||
RpcSuccessResponse::PayloadEnvelopesByRange(envelope) => {
|
||||
write!(
|
||||
f,
|
||||
@@ -975,6 +1000,16 @@ impl std::fmt::Display for OldBlocksByRangeRequest {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for BlocksByHeadRequest {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"BlocksByHead: beacon_root: {}, count: {}",
|
||||
self.beacon_root, self.count
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for BlobsByRootRequest {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
|
||||
@@ -262,6 +262,9 @@ pub enum Protocol {
|
||||
/// The `BlocksByRoot` protocol name.
|
||||
#[strum(serialize = "beacon_blocks_by_root")]
|
||||
BlocksByRoot,
|
||||
/// The `BlocksByHead` protocol name.
|
||||
#[strum(serialize = "beacon_blocks_by_head")]
|
||||
BlocksByHead,
|
||||
/// The `BlobsByRange` protocol name.
|
||||
#[strum(serialize = "blob_sidecars_by_range")]
|
||||
BlobsByRange,
|
||||
@@ -306,6 +309,7 @@ impl Protocol {
|
||||
Protocol::Goodbye => None,
|
||||
Protocol::BlocksByRange => Some(ResponseTermination::BlocksByRange),
|
||||
Protocol::BlocksByRoot => Some(ResponseTermination::BlocksByRoot),
|
||||
Protocol::BlocksByHead => Some(ResponseTermination::BlocksByHead),
|
||||
Protocol::PayloadEnvelopesByRange => Some(ResponseTermination::PayloadEnvelopesByRange),
|
||||
Protocol::PayloadEnvelopesByRoot => Some(ResponseTermination::PayloadEnvelopesByRoot),
|
||||
Protocol::BlobsByRange => Some(ResponseTermination::BlobsByRange),
|
||||
@@ -338,6 +342,7 @@ pub enum SupportedProtocol {
|
||||
BlocksByRangeV2,
|
||||
BlocksByRootV1,
|
||||
BlocksByRootV2,
|
||||
BlocksByHeadV1,
|
||||
PayloadEnvelopesByRangeV1,
|
||||
PayloadEnvelopesByRootV1,
|
||||
BlobsByRangeV1,
|
||||
@@ -366,6 +371,7 @@ impl SupportedProtocol {
|
||||
SupportedProtocol::PayloadEnvelopesByRootV1 => "1",
|
||||
SupportedProtocol::BlocksByRootV1 => "1",
|
||||
SupportedProtocol::BlocksByRootV2 => "2",
|
||||
SupportedProtocol::BlocksByHeadV1 => "1",
|
||||
SupportedProtocol::BlobsByRangeV1 => "1",
|
||||
SupportedProtocol::BlobsByRootV1 => "1",
|
||||
SupportedProtocol::DataColumnsByRootV1 => "1",
|
||||
@@ -390,6 +396,7 @@ impl SupportedProtocol {
|
||||
SupportedProtocol::BlocksByRangeV2 => Protocol::BlocksByRange,
|
||||
SupportedProtocol::BlocksByRootV1 => Protocol::BlocksByRoot,
|
||||
SupportedProtocol::BlocksByRootV2 => Protocol::BlocksByRoot,
|
||||
SupportedProtocol::BlocksByHeadV1 => Protocol::BlocksByHead,
|
||||
SupportedProtocol::PayloadEnvelopesByRangeV1 => Protocol::PayloadEnvelopesByRange,
|
||||
SupportedProtocol::PayloadEnvelopesByRootV1 => Protocol::PayloadEnvelopesByRoot,
|
||||
SupportedProtocol::BlobsByRangeV1 => Protocol::BlobsByRange,
|
||||
@@ -458,6 +465,13 @@ impl SupportedProtocol {
|
||||
),
|
||||
]);
|
||||
}
|
||||
// BeaconBlocksByHead is new in Fulu (consensus-specs PR 5181).
|
||||
if fork_context.fork_exists(ForkName::Fulu) {
|
||||
supported.push(ProtocolId::new(
|
||||
SupportedProtocol::BlocksByHeadV1,
|
||||
Encoding::SSZSnappy,
|
||||
));
|
||||
}
|
||||
supported
|
||||
}
|
||||
}
|
||||
@@ -564,6 +578,10 @@ impl ProtocolId {
|
||||
<OldBlocksByRangeRequestV2 as Encode>::ssz_fixed_len(),
|
||||
),
|
||||
Protocol::BlocksByRoot => RpcLimits::new(0, spec.max_blocks_by_root_request),
|
||||
Protocol::BlocksByHead => RpcLimits::new(
|
||||
<BlocksByHeadRequest as Encode>::ssz_fixed_len(),
|
||||
<BlocksByHeadRequest as Encode>::ssz_fixed_len(),
|
||||
),
|
||||
Protocol::PayloadEnvelopesByRange => RpcLimits::new(
|
||||
<PayloadEnvelopesByRangeRequest as Encode>::ssz_fixed_len(),
|
||||
<PayloadEnvelopesByRangeRequest as Encode>::ssz_fixed_len(),
|
||||
@@ -609,6 +627,7 @@ impl ProtocolId {
|
||||
Protocol::Goodbye => RpcLimits::new(0, 0), // Goodbye request has no response
|
||||
Protocol::BlocksByRange => rpc_block_limits_by_fork(fork_context.current_fork_name()),
|
||||
Protocol::BlocksByRoot => rpc_block_limits_by_fork(fork_context.current_fork_name()),
|
||||
Protocol::BlocksByHead => rpc_block_limits_by_fork(fork_context.current_fork_name()),
|
||||
Protocol::PayloadEnvelopesByRange => rpc_payload_limits(),
|
||||
Protocol::PayloadEnvelopesByRoot => rpc_payload_limits(),
|
||||
Protocol::BlobsByRange => rpc_blob_limits::<E>(),
|
||||
@@ -648,6 +667,7 @@ impl ProtocolId {
|
||||
match self.versioned_protocol {
|
||||
SupportedProtocol::BlocksByRangeV2
|
||||
| SupportedProtocol::BlocksByRootV2
|
||||
| SupportedProtocol::BlocksByHeadV1
|
||||
| SupportedProtocol::PayloadEnvelopesByRangeV1
|
||||
| SupportedProtocol::PayloadEnvelopesByRootV1
|
||||
| SupportedProtocol::BlobsByRangeV1
|
||||
@@ -801,6 +821,7 @@ pub enum RequestType<E: EthSpec> {
|
||||
Goodbye(GoodbyeReason),
|
||||
BlocksByRange(OldBlocksByRangeRequest),
|
||||
BlocksByRoot(BlocksByRootRequest),
|
||||
BlocksByHead(BlocksByHeadRequest),
|
||||
PayloadEnvelopesByRange(PayloadEnvelopesByRangeRequest),
|
||||
PayloadEnvelopesByRoot(PayloadEnvelopesByRootRequest),
|
||||
BlobsByRange(BlobsByRangeRequest),
|
||||
@@ -826,6 +847,7 @@ impl<E: EthSpec> RequestType<E> {
|
||||
RequestType::Goodbye(_) => 0,
|
||||
RequestType::BlocksByRange(req) => *req.count(),
|
||||
RequestType::BlocksByRoot(req) => req.block_roots().len() as u64,
|
||||
RequestType::BlocksByHead(req) => req.count,
|
||||
RequestType::PayloadEnvelopesByRange(req) => req.count,
|
||||
RequestType::PayloadEnvelopesByRoot(req) => req.beacon_block_roots.len() as u64,
|
||||
RequestType::BlobsByRange(req) => req.max_blobs_requested(digest_epoch, spec),
|
||||
@@ -857,6 +879,7 @@ impl<E: EthSpec> RequestType<E> {
|
||||
BlocksByRootRequest::V1(_) => SupportedProtocol::BlocksByRootV1,
|
||||
BlocksByRootRequest::V2(_) => SupportedProtocol::BlocksByRootV2,
|
||||
},
|
||||
RequestType::BlocksByHead(_) => SupportedProtocol::BlocksByHeadV1,
|
||||
RequestType::PayloadEnvelopesByRange(_) => SupportedProtocol::PayloadEnvelopesByRangeV1,
|
||||
RequestType::PayloadEnvelopesByRoot(_) => SupportedProtocol::PayloadEnvelopesByRootV1,
|
||||
RequestType::BlobsByRange(_) => SupportedProtocol::BlobsByRangeV1,
|
||||
@@ -890,6 +913,7 @@ impl<E: EthSpec> RequestType<E> {
|
||||
// variants that have `multiple_responses()` can have values.
|
||||
RequestType::BlocksByRange(_) => ResponseTermination::BlocksByRange,
|
||||
RequestType::BlocksByRoot(_) => ResponseTermination::BlocksByRoot,
|
||||
RequestType::BlocksByHead(_) => ResponseTermination::BlocksByHead,
|
||||
RequestType::PayloadEnvelopesByRange(_) => ResponseTermination::PayloadEnvelopesByRange,
|
||||
RequestType::PayloadEnvelopesByRoot(_) => ResponseTermination::PayloadEnvelopesByRoot,
|
||||
RequestType::BlobsByRange(_) => ResponseTermination::BlobsByRange,
|
||||
@@ -926,6 +950,10 @@ impl<E: EthSpec> RequestType<E> {
|
||||
ProtocolId::new(SupportedProtocol::BlocksByRootV2, Encoding::SSZSnappy),
|
||||
ProtocolId::new(SupportedProtocol::BlocksByRootV1, Encoding::SSZSnappy),
|
||||
],
|
||||
RequestType::BlocksByHead(_) => vec![ProtocolId::new(
|
||||
SupportedProtocol::BlocksByHeadV1,
|
||||
Encoding::SSZSnappy,
|
||||
)],
|
||||
RequestType::PayloadEnvelopesByRange(_) => vec![ProtocolId::new(
|
||||
SupportedProtocol::PayloadEnvelopesByRangeV1,
|
||||
Encoding::SSZSnappy,
|
||||
@@ -984,6 +1012,7 @@ impl<E: EthSpec> RequestType<E> {
|
||||
RequestType::Goodbye(_) => false,
|
||||
RequestType::BlocksByRange(_) => false,
|
||||
RequestType::BlocksByRoot(_) => false,
|
||||
RequestType::BlocksByHead(_) => false,
|
||||
RequestType::BlobsByRange(_) => false,
|
||||
RequestType::PayloadEnvelopesByRange(_) => false,
|
||||
RequestType::PayloadEnvelopesByRoot(_) => false,
|
||||
@@ -1097,6 +1126,7 @@ impl<E: EthSpec> std::fmt::Display for RequestType<E> {
|
||||
RequestType::Goodbye(reason) => write!(f, "Goodbye: {}", reason),
|
||||
RequestType::BlocksByRange(req) => write!(f, "Blocks by range: {}", req),
|
||||
RequestType::BlocksByRoot(req) => write!(f, "Blocks by root: {:?}", req),
|
||||
RequestType::BlocksByHead(req) => write!(f, "Blocks by head: {}", req),
|
||||
RequestType::PayloadEnvelopesByRange(req) => {
|
||||
write!(f, "Payload envelopes by range: {:?}", req)
|
||||
}
|
||||
@@ -1171,6 +1201,8 @@ mod tests {
|
||||
fork_context.fork_exists(ForkName::Gloas)
|
||||
}
|
||||
|
||||
BlocksByHeadV1 => fork_context.fork_exists(ForkName::Fulu),
|
||||
|
||||
// Light client protocols are not in currently_supported()
|
||||
LightClientBootstrapV1
|
||||
| LightClientOptimisticUpdateV1
|
||||
|
||||
@@ -105,6 +105,8 @@ pub struct RPCRateLimiter {
|
||||
bbrange_rl: Limiter<PeerId>,
|
||||
/// BlocksByRoot rate limiter.
|
||||
bbroots_rl: Limiter<PeerId>,
|
||||
/// BlocksByHead rate limiter.
|
||||
bbhead_rl: Limiter<PeerId>,
|
||||
/// BlobsByRange rate limiter.
|
||||
blbrange_rl: Limiter<PeerId>,
|
||||
/// BlobsByRoot rate limiter.
|
||||
@@ -152,6 +154,8 @@ pub struct RPCRateLimiterBuilder {
|
||||
bbrange_quota: Option<Quota>,
|
||||
/// Quota for the BlocksByRoot protocol.
|
||||
bbroots_quota: Option<Quota>,
|
||||
/// Quota for the BlocksByHead protocol.
|
||||
bbhead_quota: Option<Quota>,
|
||||
/// Quota for the ExecutionPayloadEnvelopesByRange protocol.
|
||||
perange_quota: Option<Quota>,
|
||||
/// Quota for the ExecutionPayloadEnvelopesByRoot protocol.
|
||||
@@ -185,6 +189,7 @@ impl RPCRateLimiterBuilder {
|
||||
Protocol::Goodbye => self.goodbye_quota = q,
|
||||
Protocol::BlocksByRange => self.bbrange_quota = q,
|
||||
Protocol::BlocksByRoot => self.bbroots_quota = q,
|
||||
Protocol::BlocksByHead => self.bbhead_quota = q,
|
||||
Protocol::PayloadEnvelopesByRange => self.perange_quota = q,
|
||||
Protocol::PayloadEnvelopesByRoot => self.peroots_quota = q,
|
||||
Protocol::BlobsByRange => self.blbrange_quota = q,
|
||||
@@ -211,6 +216,9 @@ impl RPCRateLimiterBuilder {
|
||||
let bbrange_quota = self
|
||||
.bbrange_quota
|
||||
.ok_or("BlocksByRange quota not specified")?;
|
||||
let bbhead_quota = self
|
||||
.bbhead_quota
|
||||
.ok_or("BlocksByHead quota not specified")?;
|
||||
let perange_quota = self
|
||||
.perange_quota
|
||||
.ok_or("PayloadEnvelopesByRange quota not specified")?;
|
||||
@@ -252,6 +260,7 @@ impl RPCRateLimiterBuilder {
|
||||
let goodbye_rl = Limiter::from_quota(goodbye_quota)?;
|
||||
let bbroots_rl = Limiter::from_quota(bbroots_quota)?;
|
||||
let bbrange_rl = Limiter::from_quota(bbrange_quota)?;
|
||||
let bbhead_rl = Limiter::from_quota(bbhead_quota)?;
|
||||
let envrange_rl = Limiter::from_quota(perange_quota)?;
|
||||
let envroots_rl = Limiter::from_quota(peroots_quota)?;
|
||||
let blbrange_rl = Limiter::from_quota(blbrange_quota)?;
|
||||
@@ -277,6 +286,7 @@ impl RPCRateLimiterBuilder {
|
||||
goodbye_rl,
|
||||
bbroots_rl,
|
||||
bbrange_rl,
|
||||
bbhead_rl,
|
||||
envrange_rl,
|
||||
envroots_rl,
|
||||
blbrange_rl,
|
||||
@@ -332,6 +342,7 @@ impl RPCRateLimiter {
|
||||
goodbye_quota,
|
||||
blocks_by_range_quota,
|
||||
blocks_by_root_quota,
|
||||
blocks_by_head_quota,
|
||||
payload_envelopes_by_range_quota,
|
||||
payload_envelopes_by_root_quota,
|
||||
blobs_by_range_quota,
|
||||
@@ -351,6 +362,7 @@ impl RPCRateLimiter {
|
||||
.set_quota(Protocol::Goodbye, goodbye_quota)
|
||||
.set_quota(Protocol::BlocksByRange, blocks_by_range_quota)
|
||||
.set_quota(Protocol::BlocksByRoot, blocks_by_root_quota)
|
||||
.set_quota(Protocol::BlocksByHead, blocks_by_head_quota)
|
||||
.set_quota(
|
||||
Protocol::PayloadEnvelopesByRange,
|
||||
payload_envelopes_by_range_quota,
|
||||
@@ -406,6 +418,7 @@ impl RPCRateLimiter {
|
||||
Protocol::Goodbye => &mut self.goodbye_rl,
|
||||
Protocol::BlocksByRange => &mut self.bbrange_rl,
|
||||
Protocol::BlocksByRoot => &mut self.bbroots_rl,
|
||||
Protocol::BlocksByHead => &mut self.bbhead_rl,
|
||||
Protocol::PayloadEnvelopesByRange => &mut self.envrange_rl,
|
||||
Protocol::PayloadEnvelopesByRoot => &mut self.envroots_rl,
|
||||
Protocol::BlobsByRange => &mut self.blbrange_rl,
|
||||
@@ -432,6 +445,7 @@ impl RPCRateLimiter {
|
||||
status_rl,
|
||||
bbrange_rl,
|
||||
bbroots_rl,
|
||||
bbhead_rl,
|
||||
envrange_rl,
|
||||
envroots_rl,
|
||||
blbrange_rl,
|
||||
@@ -451,6 +465,7 @@ impl RPCRateLimiter {
|
||||
status_rl.prune(time_since_start);
|
||||
bbrange_rl.prune(time_since_start);
|
||||
bbroots_rl.prune(time_since_start);
|
||||
bbhead_rl.prune(time_since_start);
|
||||
envrange_rl.prune(time_since_start);
|
||||
envroots_rl.prune(time_since_start);
|
||||
blbrange_rl.prune(time_since_start);
|
||||
|
||||
Reference in New Issue
Block a user