V0.11.0 network update (#976)

* Adjust RPC methods to match v0.11.1

* Adds fork handling for gossipsub topics

* Update gossipsub topics to v0.11.0
This commit is contained in:
Age Manning
2020-04-01 17:20:32 +11:00
parent 5eb4c7d682
commit 88cecd6fb8
19 changed files with 247 additions and 226 deletions

View File

@@ -11,7 +11,7 @@ use crate::service::NetworkMessage;
use beacon_chain::{AttestationType, BeaconChain, BeaconChainTypes};
use eth2_libp2p::{
rpc::{RPCError, RPCErrorResponse, RPCRequest, RPCResponse, RequestId, ResponseTermination},
MessageId, PeerId, PubsubData, PubsubMessage, RPCEvent,
MessageId, PeerId, PubsubMessage, RPCEvent,
};
use futures::future::Future;
use futures::stream::Stream;
@@ -217,9 +217,9 @@ impl<T: BeaconChainTypes> Router<T> {
peer_id: PeerId,
gossip_message: PubsubMessage<T::EthSpec>,
) {
match gossip_message.data {
match gossip_message {
// Attestations should never reach the router.
PubsubData::AggregateAndProofAttestation(aggregate_and_proof) => {
PubsubMessage::AggregateAndProofAttestation(aggregate_and_proof) => {
if self
.processor
.should_forward_aggregate_attestation(&aggregate_and_proof)
@@ -232,7 +232,7 @@ impl<T: BeaconChainTypes> Router<T> {
AttestationType::Aggregated,
);
}
PubsubData::Attestation(subnet_attestation) => {
PubsubMessage::Attestation(subnet_attestation) => {
if self
.processor
.should_forward_attestation(&subnet_attestation.1)
@@ -245,7 +245,7 @@ impl<T: BeaconChainTypes> Router<T> {
AttestationType::Unaggregated { should_store: true },
);
}
PubsubData::BeaconBlock(block) => match self.processor.should_forward_block(block) {
PubsubMessage::BeaconBlock(block) => match self.processor.should_forward_block(block) {
Ok(verified_block) => {
self.propagate_message(id, peer_id.clone());
self.processor.on_block_gossip(peer_id, verified_block);
@@ -255,19 +255,19 @@ impl<T: BeaconChainTypes> Router<T> {
"error" => format!("{:?}", e));
}
},
PubsubData::VoluntaryExit(_exit) => {
PubsubMessage::VoluntaryExit(_exit) => {
// TODO: Apply more sophisticated validation
self.propagate_message(id, peer_id.clone());
// TODO: Handle exits
debug!(self.log, "Received a voluntary exit"; "peer_id" => format!("{}", peer_id) );
}
PubsubData::ProposerSlashing(_proposer_slashing) => {
PubsubMessage::ProposerSlashing(_proposer_slashing) => {
// TODO: Apply more sophisticated validation
self.propagate_message(id, peer_id.clone());
// TODO: Handle proposer slashings
debug!(self.log, "Received a proposer slashing"; "peer_id" => format!("{}", peer_id) );
}
PubsubData::AttesterSlashing(_attester_slashing) => {
PubsubMessage::AttesterSlashing(_attester_slashing) => {
// TODO: Apply more sophisticated validation
self.propagate_message(id, peer_id.clone());
// TODO: Handle attester slashings

View File

@@ -25,7 +25,7 @@ pub(crate) const FUTURE_SLOT_TOLERANCE: u64 = 1;
/// Keeps track of syncing information for known connected peers.
#[derive(Clone, Copy, Debug)]
pub struct PeerSyncInfo {
fork_version: [u8; 4],
fork_digest: [u8; 4],
pub finalized_root: Hash256,
pub finalized_epoch: Epoch,
pub head_root: Hash256,
@@ -35,7 +35,7 @@ pub struct PeerSyncInfo {
impl From<StatusMessage> for PeerSyncInfo {
fn from(status: StatusMessage) -> PeerSyncInfo {
PeerSyncInfo {
fork_version: status.fork_version,
fork_digest: status.fork_digest,
finalized_root: status.finalized_root,
finalized_epoch: status.finalized_epoch,
head_root: status.head_root,
@@ -123,7 +123,7 @@ impl<T: BeaconChainTypes> Processor<T> {
self.log,
"Sending Status Request";
"peer" => format!("{:?}", peer_id),
"fork_version" => format!("{:?}", status_message.fork_version),
"fork_digest" => format!("{:?}", status_message.fork_digest),
"finalized_root" => format!("{:?}", status_message.finalized_root),
"finalized_epoch" => format!("{:?}", status_message.finalized_epoch),
"head_root" => format!("{}", status_message.head_root),
@@ -147,7 +147,7 @@ impl<T: BeaconChainTypes> Processor<T> {
self.log,
"Received Status Request";
"peer" => format!("{:?}", peer_id),
"fork_version" => format!("{:?}", status.fork_version),
"fork_digest" => format!("{:?}", status.fork_digest),
"finalized_root" => format!("{:?}", status.finalized_root),
"finalized_epoch" => format!("{:?}", status.finalized_epoch),
"head_root" => format!("{}", status.head_root),
@@ -193,12 +193,14 @@ impl<T: BeaconChainTypes> Processor<T> {
let start_slot = |epoch: Epoch| epoch.start_slot(T::EthSpec::slots_per_epoch());
if local.fork_version != remote.fork_version {
if local.fork_digest != remote.fork_digest {
// The node is on a different network/fork, disconnect them.
debug!(
self.log, "Handshake Failure";
"peer" => format!("{:?}", peer_id),
"reason" => "network_id"
"reason" => "incompatible forks",
"our_fork" => hex::encode(local.fork_digest),
"their_fork" => hex::encode(remote.fork_digest)
);
self.network
@@ -631,8 +633,9 @@ pub(crate) fn status_message<T: BeaconChainTypes>(
) -> Option<StatusMessage> {
let head_info = beacon_chain.head_info().ok()?;
// TODO: Update fork digest calculation
Some(StatusMessage {
fork_version: head_info.fork.current_version,
fork_digest: head_info.fork.current_version,
finalized_root: head_info.finalized_checkpoint.root,
finalized_epoch: head_info.finalized_checkpoint.epoch,
head_root: head_info.block_root,

View File

@@ -8,7 +8,7 @@ use crate::{
use beacon_chain::{BeaconChain, BeaconChainTypes};
use eth2_libp2p::Service as LibP2PService;
use eth2_libp2p::{rpc::RPCRequest, Enr, Libp2pEvent, MessageId, NetworkGlobals, PeerId, Swarm};
use eth2_libp2p::{PubsubData, PubsubMessage, RPCEvent};
use eth2_libp2p::{PubsubMessage, RPCEvent};
use futures::prelude::*;
use futures::Stream;
use rest_types::ValidatorSubscription;
@@ -217,15 +217,13 @@ fn spawn_service<T: BeaconChainTypes>(
if !should_send {
info!(log, "Random filter did not publish messages");
} else {
let mut unique_topics = Vec::new();
let mut topic_kinds = Vec::new();
for message in &messages {
for topic in message.topics() {
if !unique_topics.contains(&topic) {
unique_topics.push(topic);
if !topic_kinds.contains(&message.kind()) {
topic_kinds.push(message.kind());
}
}
}
debug!(log, "Sending pubsub messages"; "count" => messages.len(), "topics" => format!("{:?}", unique_topics));
debug!(log, "Sending pubsub messages"; "count" => messages.len(), "topics" => format!("{:?}", topic_kinds));
service.libp2p.swarm.publish(messages);
}
}
@@ -310,9 +308,9 @@ fn spawn_service<T: BeaconChainTypes>(
..
} => {
match message.data {
match message {
// attestation information gets processed in the attestation service
PubsubData::Attestation(ref subnet_and_attestation) => {
PubsubMessage::Attestation(ref subnet_and_attestation) => {
let subnet = &subnet_and_attestation.0;
let attestation = &subnet_and_attestation.1;
// checks if we have an aggregator for the slot. If so, we process

View File

@@ -43,7 +43,7 @@ impl<T: EthSpec> SyncNetworkContext<T> {
self.log,
"Sending Status Request";
"peer" => format!("{:?}", peer_id),
"fork_version" => format!("{:?}", status_message.fork_version),
"fork_digest" => format!("{:?}", status_message.fork_digest),
"finalized_root" => format!("{:?}", status_message.finalized_root),
"finalized_epoch" => format!("{:?}", status_message.finalized_epoch),
"head_root" => format!("{}", status_message.head_root),

View File

@@ -9,7 +9,7 @@ use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
use std::hash::{Hash, Hasher};
use std::ops::Sub;
use types::{EthSpec, Hash256, SignedBeaconBlock, Slot};
use types::{EthSpec, SignedBeaconBlock, Slot};
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct BatchId(pub u64);
@@ -41,8 +41,6 @@ pub struct Batch<T: EthSpec> {
pub start_slot: Slot,
/// The requested end slot of batch, exclusive.
pub end_slot: Slot,
/// The hash of the chain root to requested from the peer.
pub head_root: Hash256,
/// The peer that was originally assigned to the batch.
pub original_peer: PeerId,
/// The peer that is currently assigned to the batch.
@@ -61,18 +59,11 @@ pub struct Batch<T: EthSpec> {
impl<T: EthSpec> Eq for Batch<T> {}
impl<T: EthSpec> Batch<T> {
pub fn new(
id: BatchId,
start_slot: Slot,
end_slot: Slot,
head_root: Hash256,
peer_id: PeerId,
) -> Self {
pub fn new(id: BatchId, start_slot: Slot, end_slot: Slot, peer_id: PeerId) -> Self {
Batch {
id,
start_slot,
end_slot,
head_root,
original_peer: peer_id.clone(),
current_peer: peer_id,
retries: 0,
@@ -84,7 +75,6 @@ impl<T: EthSpec> Batch<T> {
pub fn to_blocks_by_range_request(&self) -> BlocksByRangeRequest {
BlocksByRangeRequest {
head_block_root: self.head_root,
start_slot: self.start_slot.into(),
count: std::cmp::min(BLOCKS_PER_BATCH, self.end_slot.sub(self.start_slot).into()),
step: 1,

View File

@@ -449,7 +449,6 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
"end_slot" => batch.end_slot,
"id" => *batch.id,
"peer" => format!("{}", batch.current_peer),
"head_root"=> format!("{}", batch.head_root),
"retries" => batch.retries,
"re-processes" => batch.reprocess_retries);
self.send_batch(network, batch);
@@ -578,8 +577,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
"start_slot" => batch.start_slot,
"end_slot" => batch.end_slot,
"id" => *batch.id,
"peer" => format!("{:?}", batch.current_peer),
"head_root"=> format!("{}", batch.head_root));
"peer" => format!("{:?}", batch.current_peer));
self.send_batch(network, batch);
ProcessingResult::KeepChain
}
@@ -603,8 +601,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
"start_slot" => batch.start_slot,
"end_slot" => batch.end_slot,
"id" => *batch.id,
"peer" => format!("{}", batch.current_peer),
"head_root"=> format!("{}", batch.head_root));
"peer" => format!("{}", batch.current_peer));
// send the batch
self.send_batch(network, batch);
return true;
@@ -675,7 +672,6 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
batch_id,
batch_start_slot,
batch_end_slot,
self.target_head_root,
peer_id,
))
}