mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
Merge branch 'unstable' into gloas-parent-envelope-unknown-lookup
This commit is contained in:
@@ -11,7 +11,7 @@ use std::io;
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::sync::{Arc, LazyLock};
|
use std::sync::{Arc, LazyLock};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use strum::{AsRefStr, Display, EnumString, IntoStaticStr};
|
use strum::{AsRefStr, Display, EnumIter, EnumString, IntoStaticStr};
|
||||||
use tokio_util::{
|
use tokio_util::{
|
||||||
codec::Framed,
|
codec::Framed,
|
||||||
compat::{Compat, FuturesAsyncReadCompatExt},
|
compat::{Compat, FuturesAsyncReadCompatExt},
|
||||||
@@ -329,7 +329,7 @@ pub enum Encoding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// All valid protocol name and version combinations.
|
/// All valid protocol name and version combinations.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, EnumIter)]
|
||||||
pub enum SupportedProtocol {
|
pub enum SupportedProtocol {
|
||||||
StatusV1,
|
StatusV1,
|
||||||
StatusV2,
|
StatusV2,
|
||||||
@@ -499,6 +499,10 @@ impl<E: EthSpec> UpgradeInfo for RPCProtocol<E> {
|
|||||||
SupportedProtocol::LightClientFinalityUpdateV1,
|
SupportedProtocol::LightClientFinalityUpdateV1,
|
||||||
Encoding::SSZSnappy,
|
Encoding::SSZSnappy,
|
||||||
));
|
));
|
||||||
|
supported_protocols.push(ProtocolId::new(
|
||||||
|
SupportedProtocol::LightClientUpdatesByRangeV1,
|
||||||
|
Encoding::SSZSnappy,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
supported_protocols
|
supported_protocols
|
||||||
}
|
}
|
||||||
@@ -1133,3 +1137,101 @@ impl RPCError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use libp2p::core::UpgradeInfo;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use strum::IntoEnumIterator;
|
||||||
|
use types::{Hash256, Slot};
|
||||||
|
|
||||||
|
type E = MainnetEthSpec;
|
||||||
|
|
||||||
|
/// Whether this protocol should appear in `currently_supported()` for the given context.
|
||||||
|
///
|
||||||
|
/// Uses an exhaustive match so that adding a new `SupportedProtocol` variant
|
||||||
|
/// causes a compile error until this function is updated.
|
||||||
|
fn expected_in_currently_supported(
|
||||||
|
protocol: SupportedProtocol,
|
||||||
|
fork_context: &ForkContext,
|
||||||
|
) -> bool {
|
||||||
|
use SupportedProtocol::*;
|
||||||
|
match protocol {
|
||||||
|
StatusV1 | StatusV2 | GoodbyeV1 | PingV1 | BlocksByRangeV1 | BlocksByRangeV2
|
||||||
|
| BlocksByRootV1 | BlocksByRootV2 | MetaDataV1 | MetaDataV2 => true,
|
||||||
|
|
||||||
|
BlobsByRangeV1 | BlobsByRootV1 => fork_context.fork_exists(ForkName::Deneb),
|
||||||
|
|
||||||
|
DataColumnsByRootV1 | DataColumnsByRangeV1 | MetaDataV3 => {
|
||||||
|
fork_context.spec.is_peer_das_scheduled()
|
||||||
|
}
|
||||||
|
|
||||||
|
PayloadEnvelopesByRangeV1 | PayloadEnvelopesByRootV1 => {
|
||||||
|
fork_context.fork_exists(ForkName::Gloas)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Light client protocols are not in currently_supported()
|
||||||
|
LightClientBootstrapV1
|
||||||
|
| LightClientOptimisticUpdateV1
|
||||||
|
| LightClientFinalityUpdateV1
|
||||||
|
| LightClientUpdatesByRangeV1 => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether this protocol should appear in `protocol_info()` when light client server is
|
||||||
|
/// enabled.
|
||||||
|
///
|
||||||
|
/// Uses an exhaustive match so that adding a new `SupportedProtocol` variant
|
||||||
|
/// causes a compile error until this function is updated.
|
||||||
|
fn expected_in_protocol_info(protocol: SupportedProtocol, fork_context: &ForkContext) -> bool {
|
||||||
|
use SupportedProtocol::*;
|
||||||
|
match protocol {
|
||||||
|
LightClientBootstrapV1
|
||||||
|
| LightClientOptimisticUpdateV1
|
||||||
|
| LightClientFinalityUpdateV1
|
||||||
|
| LightClientUpdatesByRangeV1 => true,
|
||||||
|
|
||||||
|
_ => expected_in_currently_supported(protocol, fork_context),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn all_protocols_registered() {
|
||||||
|
for fork in ForkName::list_all() {
|
||||||
|
let spec = fork.make_genesis_spec(E::default_spec());
|
||||||
|
let fork_context = Arc::new(ForkContext::new::<E>(Slot::new(0), Hash256::ZERO, &spec));
|
||||||
|
|
||||||
|
let currently_supported: HashSet<SupportedProtocol> =
|
||||||
|
SupportedProtocol::currently_supported(&fork_context)
|
||||||
|
.into_iter()
|
||||||
|
.map(|pid| pid.versioned_protocol)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let rpc_protocol = RPCProtocol::<E> {
|
||||||
|
fork_context: fork_context.clone(),
|
||||||
|
max_rpc_size: spec.max_payload_size as usize,
|
||||||
|
enable_light_client_server: true,
|
||||||
|
phantom: PhantomData,
|
||||||
|
};
|
||||||
|
let protocol_info: HashSet<SupportedProtocol> = rpc_protocol
|
||||||
|
.protocol_info()
|
||||||
|
.into_iter()
|
||||||
|
.map(|pid| pid.versioned_protocol)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
for protocol in SupportedProtocol::iter() {
|
||||||
|
assert_eq!(
|
||||||
|
currently_supported.contains(&protocol),
|
||||||
|
expected_in_currently_supported(protocol, &fork_context),
|
||||||
|
"{protocol:?} registration mismatch in currently_supported() at {fork:?}"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
protocol_info.contains(&protocol),
|
||||||
|
expected_in_protocol_info(protocol, &fork_context),
|
||||||
|
"{protocol:?} registration mismatch in protocol_info() at {fork:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ impl ProtoNode {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
node.payload_timeliness_votes.num_set_bits() > E::ptc_size() / 2
|
node.payload_timeliness_votes.num_set_bits() > E::payload_timely_threshold()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_payload_data_available<E: EthSpec>(&self) -> bool {
|
pub fn is_payload_data_available<E: EthSpec>(&self) -> bool {
|
||||||
@@ -224,8 +224,8 @@ impl ProtoNode {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(gloas): add function on EthSpec for DATA_AVAILABILITY_TIMELY_THRESHOLD
|
node.payload_data_availability_votes.num_set_bits()
|
||||||
node.payload_data_availability_votes.num_set_bits() > E::ptc_size() / 2
|
> E::data_availability_timely_threshold()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -448,6 +448,11 @@ pub trait EthSpec: 'static + Default + Sync + Send + Clone + Debug + PartialEq +
|
|||||||
fn payload_timely_threshold() -> usize {
|
fn payload_timely_threshold() -> usize {
|
||||||
Self::PTCSize::to_usize() / 2
|
Self::PTCSize::to_usize() / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the `DATA_AVAILABILITY_TIMELY_THRESHOLD` constant (PTC_SIZE / 2).
|
||||||
|
fn data_availability_timely_threshold() -> usize {
|
||||||
|
Self::PTCSize::to_usize() / 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Macro to inherit some type values from another EthSpec.
|
/// Macro to inherit some type values from another EthSpec.
|
||||||
|
|||||||
Reference in New Issue
Block a user