Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/network-altair' into altair-vc
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Aug 3, 2021
2 parents 84830a8 + 68357f3 commit 86b68a4
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 37 deletions.
5 changes: 3 additions & 2 deletions beacon_node/eth2_libp2p/src/behaviour/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ use std::{
task::{Context, Poll},
};
use types::{
ChainSpec, EnrForkId, EthSpec, ForkContext, SignedBeaconBlock, Slot, SubnetId, SyncSubnetId,
consts::altair::SYNC_COMMITTEE_SUBNET_COUNT, ChainSpec, EnrForkId, EthSpec, ForkContext,
SignedBeaconBlock, Slot, SubnetId, SyncSubnetId,
};

pub mod gossipsub_scoring_parameters;
Expand Down Expand Up @@ -213,7 +214,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
filter: Self::create_whitelist_filter(
possible_fork_digests,
chain_spec.attestation_subnet_count,
chain_spec.sync_committee_subnet_count,
SYNC_COMMITTEE_SUBNET_COUNT,
),
max_subscribed_topics: 200, //TODO change this to a constant
max_subscriptions_per_request: 100, //this is according to the current go implementation
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/eth2_libp2p/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub fn gossipsub_config(fork_context: Arc<ForkContext>) -> GossipsubConfig {
let gossip_message_id = move |message: &GossipsubMessage| {
MessageId::from(
&Sha256::digest(
prefix(MESSAGE_DOMAIN_VALID_SNAPPY, &message, fork_context.clone()).as_slice(),
prefix(MESSAGE_DOMAIN_VALID_SNAPPY, message, fork_context.clone()).as_slice(),
)[..20],
)
};
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/eth2_libp2p/src/peer_manager/peer_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<T: EthSpec> PeerInfo<T> {

/// Returns if the peer is subscribed to a given `Subnet` from the gossipsub subscriptions.
pub fn on_subnet_gossipsub(&self, subnet: &Subnet) -> bool {
self.subnets.contains(&subnet)
self.subnets.contains(subnet)
}

/// Returns the seen IP addresses of the peer.
Expand Down
40 changes: 18 additions & 22 deletions beacon_node/eth2_libp2p/src/rpc/codec/ssz_snappy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl<TSpec: EthSpec> Decoder for SSZSnappyOutboundCodec<TSpec> {
if src.len() >= 4 {
let context_bytes = src.split_to(4);
let mut result = [0; 4];
result.copy_from_slice(&context_bytes.as_ref());
result.copy_from_slice(context_bytes.as_ref());
self.fork_name = Some(context_bytes_to_fork_name(
result,
self.fork_context.clone(),
Expand Down Expand Up @@ -438,19 +438,19 @@ fn handle_v1_request<T: EthSpec>(
) -> Result<Option<InboundRequest<T>>, RPCError> {
match protocol {
Protocol::Status => Ok(Some(InboundRequest::Status(StatusMessage::from_ssz_bytes(
&decoded_buffer,
decoded_buffer,
)?))),
Protocol::Goodbye => Ok(Some(InboundRequest::Goodbye(
GoodbyeReason::from_ssz_bytes(&decoded_buffer)?,
GoodbyeReason::from_ssz_bytes(decoded_buffer)?,
))),
Protocol::BlocksByRange => Ok(Some(InboundRequest::BlocksByRange(
BlocksByRangeRequest::from_ssz_bytes(&decoded_buffer)?,
BlocksByRangeRequest::from_ssz_bytes(decoded_buffer)?,
))),
Protocol::BlocksByRoot => Ok(Some(InboundRequest::BlocksByRoot(BlocksByRootRequest {
block_roots: VariableList::from_ssz_bytes(&decoded_buffer)?,
block_roots: VariableList::from_ssz_bytes(decoded_buffer)?,
}))),
Protocol::Ping => Ok(Some(InboundRequest::Ping(Ping {
data: u64::from_ssz_bytes(&decoded_buffer)?,
data: u64::from_ssz_bytes(decoded_buffer)?,
}))),

// MetaData requests return early from InboundUpgrade and do not reach the decoder.
Expand All @@ -474,10 +474,10 @@ fn handle_v2_request<T: EthSpec>(
) -> Result<Option<InboundRequest<T>>, RPCError> {
match protocol {
Protocol::BlocksByRange => Ok(Some(InboundRequest::BlocksByRange(
BlocksByRangeRequest::from_ssz_bytes(&decoded_buffer)?,
BlocksByRangeRequest::from_ssz_bytes(decoded_buffer)?,
))),
Protocol::BlocksByRoot => Ok(Some(InboundRequest::BlocksByRoot(BlocksByRootRequest {
block_roots: VariableList::from_ssz_bytes(&decoded_buffer)?,
block_roots: VariableList::from_ssz_bytes(decoded_buffer)?,
}))),
// MetaData requests return early from InboundUpgrade and do not reach the decoder.
// Handle this case just for completeness.
Expand All @@ -504,21 +504,21 @@ fn handle_v1_response<T: EthSpec>(
) -> Result<Option<RPCResponse<T>>, RPCError> {
match protocol {
Protocol::Status => Ok(Some(RPCResponse::Status(StatusMessage::from_ssz_bytes(
&decoded_buffer,
decoded_buffer,
)?))),
// This case should be unreachable as `Goodbye` has no response.
Protocol::Goodbye => Err(RPCError::InvalidData),
Protocol::BlocksByRange => Ok(Some(RPCResponse::BlocksByRange(Box::new(
SignedBeaconBlock::Base(SignedBeaconBlockBase::from_ssz_bytes(&decoded_buffer)?),
SignedBeaconBlock::Base(SignedBeaconBlockBase::from_ssz_bytes(decoded_buffer)?),
)))),
Protocol::BlocksByRoot => Ok(Some(RPCResponse::BlocksByRoot(Box::new(
SignedBeaconBlock::Base(SignedBeaconBlockBase::from_ssz_bytes(&decoded_buffer)?),
SignedBeaconBlock::Base(SignedBeaconBlockBase::from_ssz_bytes(decoded_buffer)?),
)))),
Protocol::Ping => Ok(Some(RPCResponse::Pong(Ping {
data: u64::from_ssz_bytes(&decoded_buffer)?,
data: u64::from_ssz_bytes(decoded_buffer)?,
}))),
Protocol::MetaData => Ok(Some(RPCResponse::MetaData(MetaData::V1(
MetaDataV1::from_ssz_bytes(&decoded_buffer)?,
MetaDataV1::from_ssz_bytes(decoded_buffer)?,
)))),
}
}
Expand All @@ -537,7 +537,7 @@ fn handle_v2_response<T: EthSpec>(
// MetaData does not contain context_bytes
if let Protocol::MetaData = protocol {
Ok(Some(RPCResponse::MetaData(MetaData::V2(
MetaDataV2::from_ssz_bytes(&decoded_buffer)?,
MetaDataV2::from_ssz_bytes(decoded_buffer)?,
))))
} else {
let fork_name = fork_name.take().ok_or_else(|| {
Expand All @@ -550,26 +550,22 @@ fn handle_v2_response<T: EthSpec>(
Protocol::BlocksByRange => match fork_name {
ForkName::Altair => Ok(Some(RPCResponse::BlocksByRange(Box::new(
SignedBeaconBlock::Altair(SignedBeaconBlockAltair::from_ssz_bytes(
&decoded_buffer,
decoded_buffer,
)?),
)))),

ForkName::Base => Ok(Some(RPCResponse::BlocksByRange(Box::new(
SignedBeaconBlock::Base(SignedBeaconBlockBase::from_ssz_bytes(
&decoded_buffer,
)?),
SignedBeaconBlock::Base(SignedBeaconBlockBase::from_ssz_bytes(decoded_buffer)?),
)))),
},
Protocol::BlocksByRoot => match fork_name {
ForkName::Altair => Ok(Some(RPCResponse::BlocksByRoot(Box::new(
SignedBeaconBlock::Altair(SignedBeaconBlockAltair::from_ssz_bytes(
&decoded_buffer,
decoded_buffer,
)?),
)))),
ForkName::Base => Ok(Some(RPCResponse::BlocksByRoot(Box::new(
SignedBeaconBlock::Base(SignedBeaconBlockBase::from_ssz_bytes(
&decoded_buffer,
)?),
SignedBeaconBlock::Base(SignedBeaconBlockBase::from_ssz_bytes(decoded_buffer)?),
)))),
},
_ => Err(RPCError::ErrorResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,7 @@ impl<T: BeaconChainTypes> Worker<T> {
/*
* The aggregate had no signatures and is therefore worthless.
*
* Whilst we don't gossip this attestation, this act is **not** a clear
* violation of the spec nor indication of fault.
* This is forbidden by the p2p spec. Reject the message.
*
*/
self.propagate_validation_result(message_id, peer_id, MessageAcceptance::Reject);
Expand Down Expand Up @@ -1244,8 +1243,7 @@ impl<T: BeaconChainTypes> Worker<T> {
/*
* The aggregate had no signatures and is therefore worthless.
*
* Whilst we don't gossip this message, this act is **not** a clear
* violation of the spec nor indication of fault.
* This is forbidden by the p2p spec. Reject the message.
*
*/
self.propagate_validation_result(message_id, peer_id, MessageAcceptance::Reject);
Expand Down
7 changes: 5 additions & 2 deletions beacon_node/network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use fnv::FnvHashMap;
pub use lighthouse_metrics::*;
use std::{collections::HashMap, sync::Arc};
use strum::AsStaticRef;
use types::{subnet_id::subnet_id_to_string, sync_subnet_id::sync_subnet_id_to_string, EthSpec};
use types::{
consts::altair::SYNC_COMMITTEE_SUBNET_COUNT, subnet_id::subnet_id_to_string,
sync_subnet_id::sync_subnet_id_to_string, EthSpec,
};

lazy_static! {

Expand Down Expand Up @@ -597,7 +600,7 @@ pub fn update_gossip_metrics<T: EthSpec>(
.map(|v| v.set(0));
}

for subnet_id in 0..T::default_spec().sync_committee_subnet_count {
for subnet_id in 0..SYNC_COMMITTEE_SUBNET_COUNT {
let _ = get_int_gauge(
&MESH_PEERS_PER_SYNC_SUBNET_TOPIC,
&[sync_subnet_id_to_string(subnet_id)],
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl<T: BeaconChainTypes> NetworkService<T> {

// sync committee subnet service
let sync_committee_service =
SyncCommitteeService::new(beacon_chain.clone(), &config, &network_log);
SyncCommitteeService::new(beacon_chain.clone(), config, &network_log);

// create a timer for updating network metrics
let metrics_update = tokio::time::interval(Duration::from_secs(METRIC_UPDATE_INTERVAL));
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/network/src/subnet_service/sync_subnets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ impl<T: BeaconChainTypes> SyncCommitteeService<T> {
/// Return count of all currently subscribed subnets.
#[cfg(test)]
pub fn subscription_count(&self) -> usize {
use types::consts::altair::SYNC_COMMITTEE_SUBNET_COUNT;
if self.subscribe_all_subnets {
self.beacon_chain.spec.sync_committee_subnet_count as usize
SYNC_COMMITTEE_SUBNET_COUNT as usize
} else {
self.subscriptions.len()
}
Expand Down
7 changes: 6 additions & 1 deletion beacon_node/network/src/subnet_service/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ mod attestation_service {
];

// Wait for 1 slot duration to get the unsubscription event
let events = get_events(&mut attestation_service, None, 1).await;
let events = get_events(
&mut attestation_service,
Some(5),
(MainnetEthSpec::slots_per_epoch() * 3) as u32,
)
.await;
matches::assert_matches!(
events[..3],
[
Expand Down
2 changes: 0 additions & 2 deletions consensus/types/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ pub struct ChainSpec {
pub maximum_gossip_clock_disparity_millis: u64,
pub target_aggregators_per_committee: u64,
pub attestation_subnet_count: u64,
pub sync_committee_subnet_count: u64,
pub random_subnets_per_validator: u64,
pub epochs_per_random_subnet_subscription: u64,
}
Expand Down Expand Up @@ -464,7 +463,6 @@ impl ChainSpec {
network_id: 1, // mainnet network id
attestation_propagation_slot_range: 32,
attestation_subnet_count: 64,
sync_committee_subnet_count: 4,
random_subnets_per_validator: 1,
maximum_gossip_clock_disparity_millis: 500,
target_aggregators_per_committee: 16,
Expand Down

0 comments on commit 86b68a4

Please sign in to comment.