mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-27 01:33:33 +00:00
Light client updates by range RPC (#6383)
* enable lc update over rpc * resolve TODOs * resolve merge conflicts * move max light client updates to eth spec * Merge branch 'unstable' of https://github.com/sigp/lighthouse into light-client-updates-by-range-rpc * remove ethspec dependency * Update beacon_node/network/src/network_beacon_processor/rpc_methods.rs Co-authored-by: Michael Sproul <micsproul@gmail.com> * Update beacon_node/lighthouse_network/src/rpc/methods.rs Co-authored-by: Michael Sproul <micsproul@gmail.com>
This commit is contained in:
@@ -558,6 +558,7 @@ impl<E: EthSpec> PeerManager<E> {
|
||||
Protocol::LightClientBootstrap => return,
|
||||
Protocol::LightClientOptimisticUpdate => return,
|
||||
Protocol::LightClientFinalityUpdate => return,
|
||||
Protocol::LightClientUpdatesByRange => return,
|
||||
Protocol::BlobsByRoot => PeerAction::MidToleranceError,
|
||||
Protocol::DataColumnsByRoot => PeerAction::MidToleranceError,
|
||||
Protocol::DataColumnsByRange => PeerAction::MidToleranceError,
|
||||
@@ -585,6 +586,7 @@ impl<E: EthSpec> PeerManager<E> {
|
||||
Protocol::LightClientBootstrap => return,
|
||||
Protocol::LightClientOptimisticUpdate => return,
|
||||
Protocol::LightClientFinalityUpdate => return,
|
||||
Protocol::LightClientUpdatesByRange => return,
|
||||
Protocol::MetaData => PeerAction::Fatal,
|
||||
Protocol::Status => PeerAction::Fatal,
|
||||
}
|
||||
@@ -606,6 +608,7 @@ impl<E: EthSpec> PeerManager<E> {
|
||||
Protocol::LightClientBootstrap => return,
|
||||
Protocol::LightClientOptimisticUpdate => return,
|
||||
Protocol::LightClientFinalityUpdate => return,
|
||||
Protocol::LightClientUpdatesByRange => return,
|
||||
Protocol::Goodbye => return,
|
||||
Protocol::MetaData => return,
|
||||
Protocol::Status => return,
|
||||
|
||||
@@ -18,9 +18,9 @@ use tokio_util::codec::{Decoder, Encoder};
|
||||
use types::{
|
||||
BlobSidecar, ChainSpec, DataColumnSidecar, EthSpec, ForkContext, ForkName, Hash256,
|
||||
LightClientBootstrap, LightClientFinalityUpdate, LightClientOptimisticUpdate,
|
||||
RuntimeVariableList, SignedBeaconBlock, SignedBeaconBlockAltair, SignedBeaconBlockBase,
|
||||
SignedBeaconBlockBellatrix, SignedBeaconBlockCapella, SignedBeaconBlockDeneb,
|
||||
SignedBeaconBlockElectra,
|
||||
LightClientUpdate, RuntimeVariableList, SignedBeaconBlock, SignedBeaconBlockAltair,
|
||||
SignedBeaconBlockBase, SignedBeaconBlockBellatrix, SignedBeaconBlockCapella,
|
||||
SignedBeaconBlockDeneb, SignedBeaconBlockElectra,
|
||||
};
|
||||
use unsigned_varint::codec::Uvi;
|
||||
|
||||
@@ -76,6 +76,7 @@ impl<E: EthSpec> SSZSnappyInboundCodec<E> {
|
||||
RpcSuccessResponse::LightClientBootstrap(res) => res.as_ssz_bytes(),
|
||||
RpcSuccessResponse::LightClientOptimisticUpdate(res) => res.as_ssz_bytes(),
|
||||
RpcSuccessResponse::LightClientFinalityUpdate(res) => res.as_ssz_bytes(),
|
||||
RpcSuccessResponse::LightClientUpdatesByRange(res) => res.as_ssz_bytes(),
|
||||
RpcSuccessResponse::Pong(res) => res.data.as_ssz_bytes(),
|
||||
RpcSuccessResponse::MetaData(res) =>
|
||||
// Encode the correct version of the MetaData response based on the negotiated version.
|
||||
@@ -342,6 +343,7 @@ impl<E: EthSpec> Encoder<RequestType> for SSZSnappyOutboundCodec<E> {
|
||||
RequestType::DataColumnsByRoot(req) => req.data_column_ids.as_ssz_bytes(),
|
||||
RequestType::Ping(req) => req.as_ssz_bytes(),
|
||||
RequestType::LightClientBootstrap(req) => req.as_ssz_bytes(),
|
||||
RequestType::LightClientUpdatesByRange(req) => req.as_ssz_bytes(),
|
||||
// no metadata to encode
|
||||
RequestType::MetaData(_)
|
||||
| RequestType::LightClientOptimisticUpdate
|
||||
@@ -503,6 +505,10 @@ fn context_bytes<E: EthSpec>(
|
||||
return lc_finality_update
|
||||
.map_with_fork_name(|fork_name| fork_context.to_context_bytes(fork_name));
|
||||
}
|
||||
RpcSuccessResponse::LightClientUpdatesByRange(lc_update) => {
|
||||
return lc_update
|
||||
.map_with_fork_name(|fork_name| fork_context.to_context_bytes(fork_name));
|
||||
}
|
||||
// These will not pass the has_context_bytes() check
|
||||
RpcSuccessResponse::Status(_)
|
||||
| RpcSuccessResponse::Pong(_)
|
||||
@@ -613,6 +619,11 @@ fn handle_rpc_request(
|
||||
SupportedProtocol::LightClientFinalityUpdateV1 => {
|
||||
Ok(Some(RequestType::LightClientFinalityUpdate))
|
||||
}
|
||||
SupportedProtocol::LightClientUpdatesByRangeV1 => {
|
||||
Ok(Some(RequestType::LightClientUpdatesByRange(
|
||||
LightClientUpdatesByRangeRequest::from_ssz_bytes(decoded_buffer)?,
|
||||
)))
|
||||
}
|
||||
// MetaData requests return early from InboundUpgrade and do not reach the decoder.
|
||||
// Handle this case just for completeness.
|
||||
SupportedProtocol::MetaDataV3 => {
|
||||
@@ -795,6 +806,21 @@ fn handle_rpc_response<E: EthSpec>(
|
||||
),
|
||||
)),
|
||||
},
|
||||
SupportedProtocol::LightClientUpdatesByRangeV1 => match fork_name {
|
||||
Some(fork_name) => Ok(Some(RpcSuccessResponse::LightClientUpdatesByRange(
|
||||
Arc::new(LightClientUpdate::from_ssz_bytes(
|
||||
decoded_buffer,
|
||||
&fork_name,
|
||||
)?),
|
||||
))),
|
||||
None => Err(RPCError::ErrorResponse(
|
||||
RpcErrorResponse::InvalidRequest,
|
||||
format!(
|
||||
"No context bytes provided for {:?} response",
|
||||
versioned_protocol
|
||||
),
|
||||
)),
|
||||
},
|
||||
// MetaData V2/V3 responses have no context bytes, so behave similarly to V1 responses
|
||||
SupportedProtocol::MetaDataV3 => Ok(Some(RpcSuccessResponse::MetaData(MetaData::V3(
|
||||
MetaDataV3::from_ssz_bytes(decoded_buffer)?,
|
||||
@@ -1215,6 +1241,12 @@ mod tests {
|
||||
)
|
||||
}
|
||||
RequestType::LightClientOptimisticUpdate | RequestType::LightClientFinalityUpdate => {}
|
||||
RequestType::LightClientUpdatesByRange(light_client_updates_by_range) => {
|
||||
assert_eq!(
|
||||
decoded,
|
||||
RequestType::LightClientUpdatesByRange(light_client_updates_by_range)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,7 @@ pub struct RateLimiterConfig {
|
||||
pub(super) light_client_bootstrap_quota: Quota,
|
||||
pub(super) light_client_optimistic_update_quota: Quota,
|
||||
pub(super) light_client_finality_update_quota: Quota,
|
||||
pub(super) light_client_updates_by_range_quota: Quota,
|
||||
}
|
||||
|
||||
impl RateLimiterConfig {
|
||||
@@ -121,6 +122,7 @@ impl RateLimiterConfig {
|
||||
pub const DEFAULT_LIGHT_CLIENT_BOOTSTRAP_QUOTA: Quota = Quota::one_every(10);
|
||||
pub const DEFAULT_LIGHT_CLIENT_OPTIMISTIC_UPDATE_QUOTA: Quota = Quota::one_every(10);
|
||||
pub const DEFAULT_LIGHT_CLIENT_FINALITY_UPDATE_QUOTA: Quota = Quota::one_every(10);
|
||||
pub const DEFAULT_LIGHT_CLIENT_UPDATES_BY_RANGE_QUOTA: Quota = Quota::one_every(10);
|
||||
}
|
||||
|
||||
impl Default for RateLimiterConfig {
|
||||
@@ -140,6 +142,7 @@ impl Default for RateLimiterConfig {
|
||||
light_client_optimistic_update_quota:
|
||||
Self::DEFAULT_LIGHT_CLIENT_OPTIMISTIC_UPDATE_QUOTA,
|
||||
light_client_finality_update_quota: Self::DEFAULT_LIGHT_CLIENT_FINALITY_UPDATE_QUOTA,
|
||||
light_client_updates_by_range_quota: Self::DEFAULT_LIGHT_CLIENT_UPDATES_BY_RANGE_QUOTA,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,6 +201,7 @@ impl FromStr for RateLimiterConfig {
|
||||
let mut light_client_bootstrap_quota = None;
|
||||
let mut light_client_optimistic_update_quota = None;
|
||||
let mut light_client_finality_update_quota = None;
|
||||
let mut light_client_updates_by_range_quota = None;
|
||||
|
||||
for proto_def in s.split(';') {
|
||||
let ProtocolQuota { protocol, quota } = proto_def.parse()?;
|
||||
@@ -228,6 +232,10 @@ impl FromStr for RateLimiterConfig {
|
||||
light_client_finality_update_quota =
|
||||
light_client_finality_update_quota.or(quota)
|
||||
}
|
||||
Protocol::LightClientUpdatesByRange => {
|
||||
light_client_updates_by_range_quota =
|
||||
light_client_updates_by_range_quota.or(quota)
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(RateLimiterConfig {
|
||||
@@ -252,6 +260,8 @@ impl FromStr for RateLimiterConfig {
|
||||
.unwrap_or(Self::DEFAULT_LIGHT_CLIENT_OPTIMISTIC_UPDATE_QUOTA),
|
||||
light_client_finality_update_quota: light_client_finality_update_quota
|
||||
.unwrap_or(Self::DEFAULT_LIGHT_CLIENT_FINALITY_UPDATE_QUOTA),
|
||||
light_client_updates_by_range_quota: light_client_updates_by_range_quota
|
||||
.unwrap_or(Self::DEFAULT_LIGHT_CLIENT_UPDATES_BY_RANGE_QUOTA),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ use std::sync::Arc;
|
||||
use strum::IntoStaticStr;
|
||||
use superstruct::superstruct;
|
||||
use types::blob_sidecar::BlobIdentifier;
|
||||
use types::light_client_update::MAX_REQUEST_LIGHT_CLIENT_UPDATES;
|
||||
use types::{
|
||||
blob_sidecar::BlobSidecar, ChainSpec, ColumnIndex, DataColumnIdentifier, DataColumnSidecar,
|
||||
Epoch, EthSpec, Hash256, LightClientBootstrap, LightClientFinalityUpdate,
|
||||
LightClientOptimisticUpdate, RuntimeVariableList, SignedBeaconBlock, Slot,
|
||||
LightClientOptimisticUpdate, LightClientUpdate, RuntimeVariableList, SignedBeaconBlock, Slot,
|
||||
};
|
||||
|
||||
/// Maximum length of error message.
|
||||
@@ -471,6 +472,34 @@ impl DataColumnsByRootRequest {
|
||||
}
|
||||
}
|
||||
|
||||
/// Request a number of beacon data columns from a peer.
|
||||
#[derive(Encode, Decode, Clone, Debug, PartialEq)]
|
||||
pub struct LightClientUpdatesByRangeRequest {
|
||||
/// The starting period to request light client updates.
|
||||
pub start_period: u64,
|
||||
/// The number of periods from `start_period`.
|
||||
pub count: u64,
|
||||
}
|
||||
|
||||
impl LightClientUpdatesByRangeRequest {
|
||||
pub fn max_requested(&self) -> u64 {
|
||||
MAX_REQUEST_LIGHT_CLIENT_UPDATES
|
||||
}
|
||||
|
||||
pub fn ssz_min_len() -> usize {
|
||||
LightClientUpdatesByRangeRequest {
|
||||
start_period: 0,
|
||||
count: 0,
|
||||
}
|
||||
.as_ssz_bytes()
|
||||
.len()
|
||||
}
|
||||
|
||||
pub fn ssz_max_len() -> usize {
|
||||
Self::ssz_min_len()
|
||||
}
|
||||
}
|
||||
|
||||
/* RPC Handling and Grouping */
|
||||
// Collection of enums and structs used by the Codecs to encode/decode RPC messages
|
||||
|
||||
@@ -498,6 +527,9 @@ pub enum RpcSuccessResponse<E: EthSpec> {
|
||||
/// A response to a get LIGHT_CLIENT_FINALITY_UPDATE request.
|
||||
LightClientFinalityUpdate(Arc<LightClientFinalityUpdate<E>>),
|
||||
|
||||
/// A response to a get LIGHT_CLIENT_UPDATES_BY_RANGE request.
|
||||
LightClientUpdatesByRange(Arc<LightClientUpdate<E>>),
|
||||
|
||||
/// A response to a get BLOBS_BY_ROOT request.
|
||||
BlobsByRoot(Arc<BlobSidecar<E>>),
|
||||
|
||||
@@ -534,6 +566,9 @@ pub enum ResponseTermination {
|
||||
|
||||
/// Data column sidecars by range stream termination.
|
||||
DataColumnsByRange,
|
||||
|
||||
/// Light client updates by range stream termination.
|
||||
LightClientUpdatesByRange,
|
||||
}
|
||||
|
||||
/// The structured response containing a result/code indicating success or failure
|
||||
@@ -633,6 +668,7 @@ impl<E: EthSpec> RpcSuccessResponse<E> {
|
||||
Protocol::LightClientOptimisticUpdate
|
||||
}
|
||||
RpcSuccessResponse::LightClientFinalityUpdate(_) => Protocol::LightClientFinalityUpdate,
|
||||
RpcSuccessResponse::LightClientUpdatesByRange(_) => Protocol::LightClientUpdatesByRange,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -704,6 +740,13 @@ impl<E: EthSpec> std::fmt::Display for RpcSuccessResponse<E> {
|
||||
update.signature_slot()
|
||||
)
|
||||
}
|
||||
RpcSuccessResponse::LightClientUpdatesByRange(update) => {
|
||||
write!(
|
||||
f,
|
||||
"LightClientUpdatesByRange Slot: {}",
|
||||
update.signature_slot(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -553,6 +553,9 @@ where
|
||||
ResponseTermination::BlobsByRoot => Protocol::BlobsByRoot,
|
||||
ResponseTermination::DataColumnsByRoot => Protocol::DataColumnsByRoot,
|
||||
ResponseTermination::DataColumnsByRange => Protocol::DataColumnsByRange,
|
||||
ResponseTermination::LightClientUpdatesByRange => {
|
||||
Protocol::LightClientUpdatesByRange
|
||||
}
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
@@ -21,7 +21,8 @@ use types::{
|
||||
BlobSidecar, ChainSpec, DataColumnSidecar, EmptyBlock, EthSpec, ForkContext, ForkName,
|
||||
LightClientBootstrap, LightClientBootstrapAltair, LightClientFinalityUpdate,
|
||||
LightClientFinalityUpdateAltair, LightClientOptimisticUpdate,
|
||||
LightClientOptimisticUpdateAltair, MainnetEthSpec, Signature, SignedBeaconBlock,
|
||||
LightClientOptimisticUpdateAltair, LightClientUpdate, MainnetEthSpec, Signature,
|
||||
SignedBeaconBlock,
|
||||
};
|
||||
|
||||
// Note: Hardcoding the `EthSpec` type for `SignedBeaconBlock` as min/max values is
|
||||
@@ -143,6 +144,13 @@ pub static LIGHT_CLIENT_BOOTSTRAP_ELECTRA_MAX: LazyLock<usize> = LazyLock::new(|
|
||||
LightClientBootstrap::<MainnetEthSpec>::ssz_max_len_for_fork(ForkName::Electra)
|
||||
});
|
||||
|
||||
pub static LIGHT_CLIENT_UPDATES_BY_RANGE_CAPELLA_MAX: LazyLock<usize> =
|
||||
LazyLock::new(|| LightClientUpdate::<MainnetEthSpec>::ssz_max_len_for_fork(ForkName::Capella));
|
||||
pub static LIGHT_CLIENT_UPDATES_BY_RANGE_DENEB_MAX: LazyLock<usize> =
|
||||
LazyLock::new(|| LightClientUpdate::<MainnetEthSpec>::ssz_max_len_for_fork(ForkName::Deneb));
|
||||
pub static LIGHT_CLIENT_UPDATES_BY_RANGE_ELECTRA_MAX: LazyLock<usize> =
|
||||
LazyLock::new(|| LightClientUpdate::<MainnetEthSpec>::ssz_max_len_for_fork(ForkName::Electra));
|
||||
|
||||
/// The protocol prefix the RPC protocol id.
|
||||
const PROTOCOL_PREFIX: &str = "/eth2/beacon_chain/req";
|
||||
/// The number of seconds to wait for the first bytes of a request once a protocol has been
|
||||
@@ -190,6 +198,26 @@ pub fn rpc_block_limits_by_fork(current_fork: ForkName) -> RpcLimits {
|
||||
}
|
||||
}
|
||||
|
||||
fn rpc_light_client_updates_by_range_limits_by_fork(current_fork: ForkName) -> RpcLimits {
|
||||
let altair_fixed_len = LightClientFinalityUpdateAltair::<MainnetEthSpec>::ssz_fixed_len();
|
||||
|
||||
match ¤t_fork {
|
||||
ForkName::Base => RpcLimits::new(0, 0),
|
||||
ForkName::Altair | ForkName::Bellatrix => {
|
||||
RpcLimits::new(altair_fixed_len, altair_fixed_len)
|
||||
}
|
||||
ForkName::Capella => {
|
||||
RpcLimits::new(altair_fixed_len, *LIGHT_CLIENT_UPDATES_BY_RANGE_CAPELLA_MAX)
|
||||
}
|
||||
ForkName::Deneb => {
|
||||
RpcLimits::new(altair_fixed_len, *LIGHT_CLIENT_UPDATES_BY_RANGE_DENEB_MAX)
|
||||
}
|
||||
ForkName::Electra => {
|
||||
RpcLimits::new(altair_fixed_len, *LIGHT_CLIENT_UPDATES_BY_RANGE_ELECTRA_MAX)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn rpc_light_client_finality_update_limits_by_fork(current_fork: ForkName) -> RpcLimits {
|
||||
let altair_fixed_len = LightClientFinalityUpdateAltair::<MainnetEthSpec>::ssz_fixed_len();
|
||||
|
||||
@@ -286,6 +314,9 @@ pub enum Protocol {
|
||||
/// The `LightClientFinalityUpdate` protocol name.
|
||||
#[strum(serialize = "light_client_finality_update")]
|
||||
LightClientFinalityUpdate,
|
||||
/// The `LightClientUpdatesByRange` protocol name
|
||||
#[strum(serialize = "light_client_updates_by_range")]
|
||||
LightClientUpdatesByRange,
|
||||
}
|
||||
|
||||
impl Protocol {
|
||||
@@ -304,6 +335,7 @@ impl Protocol {
|
||||
Protocol::LightClientBootstrap => None,
|
||||
Protocol::LightClientOptimisticUpdate => None,
|
||||
Protocol::LightClientFinalityUpdate => None,
|
||||
Protocol::LightClientUpdatesByRange => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,6 +366,7 @@ pub enum SupportedProtocol {
|
||||
LightClientBootstrapV1,
|
||||
LightClientOptimisticUpdateV1,
|
||||
LightClientFinalityUpdateV1,
|
||||
LightClientUpdatesByRangeV1,
|
||||
}
|
||||
|
||||
impl SupportedProtocol {
|
||||
@@ -356,6 +389,7 @@ impl SupportedProtocol {
|
||||
SupportedProtocol::LightClientBootstrapV1 => "1",
|
||||
SupportedProtocol::LightClientOptimisticUpdateV1 => "1",
|
||||
SupportedProtocol::LightClientFinalityUpdateV1 => "1",
|
||||
SupportedProtocol::LightClientUpdatesByRangeV1 => "1",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,6 +414,7 @@ impl SupportedProtocol {
|
||||
Protocol::LightClientOptimisticUpdate
|
||||
}
|
||||
SupportedProtocol::LightClientFinalityUpdateV1 => Protocol::LightClientFinalityUpdate,
|
||||
SupportedProtocol::LightClientUpdatesByRangeV1 => Protocol::LightClientUpdatesByRange,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -542,6 +577,10 @@ impl ProtocolId {
|
||||
),
|
||||
Protocol::LightClientOptimisticUpdate => RpcLimits::new(0, 0),
|
||||
Protocol::LightClientFinalityUpdate => RpcLimits::new(0, 0),
|
||||
Protocol::LightClientUpdatesByRange => RpcLimits::new(
|
||||
LightClientUpdatesByRangeRequest::ssz_min_len(),
|
||||
LightClientUpdatesByRangeRequest::ssz_max_len(),
|
||||
),
|
||||
Protocol::MetaData => RpcLimits::new(0, 0), // Metadata requests are empty
|
||||
}
|
||||
}
|
||||
@@ -577,6 +616,9 @@ impl ProtocolId {
|
||||
Protocol::LightClientFinalityUpdate => {
|
||||
rpc_light_client_finality_update_limits_by_fork(fork_context.current_fork())
|
||||
}
|
||||
Protocol::LightClientUpdatesByRange => {
|
||||
rpc_light_client_updates_by_range_limits_by_fork(fork_context.current_fork())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -592,7 +634,8 @@ impl ProtocolId {
|
||||
| SupportedProtocol::DataColumnsByRangeV1
|
||||
| SupportedProtocol::LightClientBootstrapV1
|
||||
| SupportedProtocol::LightClientOptimisticUpdateV1
|
||||
| SupportedProtocol::LightClientFinalityUpdateV1 => true,
|
||||
| SupportedProtocol::LightClientFinalityUpdateV1
|
||||
| SupportedProtocol::LightClientUpdatesByRangeV1 => true,
|
||||
SupportedProtocol::StatusV1
|
||||
| SupportedProtocol::BlocksByRootV1
|
||||
| SupportedProtocol::BlocksByRangeV1
|
||||
@@ -723,6 +766,7 @@ pub enum RequestType {
|
||||
LightClientBootstrap(LightClientBootstrapRequest),
|
||||
LightClientOptimisticUpdate,
|
||||
LightClientFinalityUpdate,
|
||||
LightClientUpdatesByRange(LightClientUpdatesByRangeRequest),
|
||||
Ping(Ping),
|
||||
MetaData(MetadataRequest),
|
||||
}
|
||||
@@ -747,6 +791,7 @@ impl RequestType {
|
||||
RequestType::LightClientBootstrap(_) => 1,
|
||||
RequestType::LightClientOptimisticUpdate => 1,
|
||||
RequestType::LightClientFinalityUpdate => 1,
|
||||
RequestType::LightClientUpdatesByRange(req) => req.max_requested(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -780,6 +825,9 @@ impl RequestType {
|
||||
RequestType::LightClientFinalityUpdate => {
|
||||
SupportedProtocol::LightClientFinalityUpdateV1
|
||||
}
|
||||
RequestType::LightClientUpdatesByRange(_) => {
|
||||
SupportedProtocol::LightClientUpdatesByRangeV1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -802,6 +850,7 @@ impl RequestType {
|
||||
RequestType::LightClientBootstrap(_) => unreachable!(),
|
||||
RequestType::LightClientFinalityUpdate => unreachable!(),
|
||||
RequestType::LightClientOptimisticUpdate => unreachable!(),
|
||||
RequestType::LightClientUpdatesByRange(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -861,6 +910,10 @@ impl RequestType {
|
||||
SupportedProtocol::LightClientFinalityUpdateV1,
|
||||
Encoding::SSZSnappy,
|
||||
)],
|
||||
RequestType::LightClientUpdatesByRange(_) => vec![ProtocolId::new(
|
||||
SupportedProtocol::LightClientUpdatesByRangeV1,
|
||||
Encoding::SSZSnappy,
|
||||
)],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -879,6 +932,7 @@ impl RequestType {
|
||||
RequestType::LightClientBootstrap(_) => true,
|
||||
RequestType::LightClientOptimisticUpdate => true,
|
||||
RequestType::LightClientFinalityUpdate => true,
|
||||
RequestType::LightClientUpdatesByRange(_) => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -997,6 +1051,9 @@ impl std::fmt::Display for RequestType {
|
||||
RequestType::LightClientFinalityUpdate => {
|
||||
write!(f, "Light client finality update request")
|
||||
}
|
||||
RequestType::LightClientUpdatesByRange(_) => {
|
||||
write!(f, "Light client updates by range request")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,8 @@ pub struct RPCRateLimiter {
|
||||
lc_optimistic_update_rl: Limiter<PeerId>,
|
||||
/// LightClientFinalityUpdate rate limiter.
|
||||
lc_finality_update_rl: Limiter<PeerId>,
|
||||
/// LightClientUpdatesByRange rate limiter.
|
||||
lc_updates_by_range_rl: Limiter<PeerId>,
|
||||
}
|
||||
|
||||
/// Error type for non conformant requests
|
||||
@@ -146,6 +148,8 @@ pub struct RPCRateLimiterBuilder {
|
||||
lc_optimistic_update_quota: Option<Quota>,
|
||||
/// Quota for the LightClientOptimisticUpdate protocol.
|
||||
lc_finality_update_quota: Option<Quota>,
|
||||
/// Quota for the LightClientUpdatesByRange protocol.
|
||||
lc_updates_by_range_quota: Option<Quota>,
|
||||
}
|
||||
|
||||
impl RPCRateLimiterBuilder {
|
||||
@@ -166,6 +170,7 @@ impl RPCRateLimiterBuilder {
|
||||
Protocol::LightClientBootstrap => self.lcbootstrap_quota = q,
|
||||
Protocol::LightClientOptimisticUpdate => self.lc_optimistic_update_quota = q,
|
||||
Protocol::LightClientFinalityUpdate => self.lc_finality_update_quota = q,
|
||||
Protocol::LightClientUpdatesByRange => self.lc_updates_by_range_quota = q,
|
||||
}
|
||||
self
|
||||
}
|
||||
@@ -191,6 +196,9 @@ impl RPCRateLimiterBuilder {
|
||||
let lc_finality_update_quota = self
|
||||
.lc_finality_update_quota
|
||||
.ok_or("LightClientFinalityUpdate quota not specified")?;
|
||||
let lc_updates_by_range_quota = self
|
||||
.lc_updates_by_range_quota
|
||||
.ok_or("LightClientUpdatesByRange quota not specified")?;
|
||||
|
||||
let blbrange_quota = self
|
||||
.blbrange_quota
|
||||
@@ -221,6 +229,7 @@ impl RPCRateLimiterBuilder {
|
||||
let lc_bootstrap_rl = Limiter::from_quota(lc_bootstrap_quota)?;
|
||||
let lc_optimistic_update_rl = Limiter::from_quota(lc_optimistic_update_quota)?;
|
||||
let lc_finality_update_rl = Limiter::from_quota(lc_finality_update_quota)?;
|
||||
let lc_updates_by_range_rl = Limiter::from_quota(lc_updates_by_range_quota)?;
|
||||
|
||||
// check for peers to prune every 30 seconds, starting in 30 seconds
|
||||
let prune_every = tokio::time::Duration::from_secs(30);
|
||||
@@ -241,6 +250,7 @@ impl RPCRateLimiterBuilder {
|
||||
lc_bootstrap_rl,
|
||||
lc_optimistic_update_rl,
|
||||
lc_finality_update_rl,
|
||||
lc_updates_by_range_rl,
|
||||
init_time: Instant::now(),
|
||||
})
|
||||
}
|
||||
@@ -278,6 +288,7 @@ impl RPCRateLimiter {
|
||||
light_client_bootstrap_quota,
|
||||
light_client_optimistic_update_quota,
|
||||
light_client_finality_update_quota,
|
||||
light_client_updates_by_range_quota,
|
||||
} = config;
|
||||
|
||||
Self::builder()
|
||||
@@ -300,6 +311,10 @@ impl RPCRateLimiter {
|
||||
Protocol::LightClientFinalityUpdate,
|
||||
light_client_finality_update_quota,
|
||||
)
|
||||
.set_quota(
|
||||
Protocol::LightClientUpdatesByRange,
|
||||
light_client_updates_by_range_quota,
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
@@ -332,6 +347,7 @@ impl RPCRateLimiter {
|
||||
Protocol::LightClientBootstrap => &mut self.lc_bootstrap_rl,
|
||||
Protocol::LightClientOptimisticUpdate => &mut self.lc_optimistic_update_rl,
|
||||
Protocol::LightClientFinalityUpdate => &mut self.lc_finality_update_rl,
|
||||
Protocol::LightClientUpdatesByRange => &mut self.lc_updates_by_range_rl,
|
||||
};
|
||||
check(limiter)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
use libp2p::swarm::ConnectionId;
|
||||
use types::{
|
||||
BlobSidecar, DataColumnSidecar, EthSpec, Hash256, LightClientBootstrap,
|
||||
LightClientFinalityUpdate, LightClientOptimisticUpdate, SignedBeaconBlock,
|
||||
LightClientFinalityUpdate, LightClientOptimisticUpdate, LightClientUpdate, SignedBeaconBlock,
|
||||
};
|
||||
|
||||
use crate::rpc::{
|
||||
@@ -117,6 +117,8 @@ pub enum Response<E: EthSpec> {
|
||||
LightClientOptimisticUpdate(Arc<LightClientOptimisticUpdate<E>>),
|
||||
/// A response to a LightClientFinalityUpdate request.
|
||||
LightClientFinalityUpdate(Arc<LightClientFinalityUpdate<E>>),
|
||||
/// A response to a LightClientUpdatesByRange request.
|
||||
LightClientUpdatesByRange(Option<Arc<LightClientUpdate<E>>>),
|
||||
}
|
||||
|
||||
impl<E: EthSpec> std::convert::From<Response<E>> for RpcResponse<E> {
|
||||
@@ -156,6 +158,12 @@ impl<E: EthSpec> std::convert::From<Response<E>> for RpcResponse<E> {
|
||||
Response::LightClientFinalityUpdate(f) => {
|
||||
RpcResponse::Success(RpcSuccessResponse::LightClientFinalityUpdate(f))
|
||||
}
|
||||
Response::LightClientUpdatesByRange(f) => match f {
|
||||
Some(d) => RpcResponse::Success(RpcSuccessResponse::LightClientUpdatesByRange(d)),
|
||||
None => {
|
||||
RpcResponse::StreamTermination(ResponseTermination::LightClientUpdatesByRange)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1579,6 +1579,17 @@ impl<E: EthSpec> Network<E> {
|
||||
request,
|
||||
})
|
||||
}
|
||||
RequestType::LightClientUpdatesByRange(_) => {
|
||||
metrics::inc_counter_vec(
|
||||
&metrics::TOTAL_RPC_REQUESTS,
|
||||
&["light_client_updates_by_range"],
|
||||
);
|
||||
Some(NetworkEvent::RequestReceived {
|
||||
peer_id,
|
||||
id: (connection_id, request.substream_id),
|
||||
request,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(RPCReceived::Response(id, resp)) => {
|
||||
@@ -1632,6 +1643,11 @@ impl<E: EthSpec> Network<E> {
|
||||
peer_id,
|
||||
Response::LightClientFinalityUpdate(update),
|
||||
),
|
||||
RpcSuccessResponse::LightClientUpdatesByRange(update) => self.build_response(
|
||||
id,
|
||||
peer_id,
|
||||
Response::LightClientUpdatesByRange(Some(update)),
|
||||
),
|
||||
}
|
||||
}
|
||||
Ok(RPCReceived::EndOfStream(id, termination)) => {
|
||||
@@ -1642,6 +1658,9 @@ impl<E: EthSpec> Network<E> {
|
||||
ResponseTermination::BlobsByRoot => Response::BlobsByRoot(None),
|
||||
ResponseTermination::DataColumnsByRoot => Response::DataColumnsByRoot(None),
|
||||
ResponseTermination::DataColumnsByRange => Response::DataColumnsByRange(None),
|
||||
ResponseTermination::LightClientUpdatesByRange => {
|
||||
Response::LightClientUpdatesByRange(None)
|
||||
}
|
||||
};
|
||||
self.build_response(id, peer_id, response)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user