Complete moving network logc into beacon node

This commit is contained in:
Age Manning 2019-04-03 16:33:12 +11:00
parent 64abd0bc5b
commit 7920f8098f
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
8 changed files with 23 additions and 18 deletions

View File

@ -9,6 +9,7 @@ beacon_chain = { path = "../beacon_chain" }
network = { path = "../network" }
store = { path = "../store" }
http_server = { path = "../http_server" }
eth2-libp2p = { path = "../eth2-libp2p" }
rpc = { path = "../rpc" }
prometheus = "^0.6"
types = { path = "../../eth2/types" }

View File

@ -1,7 +1,13 @@
use clap::ArgMatches;
use eth2_libp2p::multiaddr::Protocol;
use eth2_libp2p::multiaddr::ToMultiaddr;
use eth2_libp2p::Multiaddr;
use fork_choice::ForkChoiceAlgorithm;
use http_server::HttpServerConfig;
use network::NetworkConfig;
use network::{ChainType, NetworkConfig};
use serde_derive::{Deserialize, Serialize};
use slog::error;
use std::fs;
use std::path::PathBuf;
@ -27,8 +33,9 @@ impl Default for ClientConfig {
// currently lighthouse spec
let default_spec = ChainSpec::lighthouse_testnet();
let chain_type = ChainType::from(default_spec.chain_id);
// builds a chain-specific network config
let net_conf = NetworkConfig::from(default_spec.chain_id);
let net_conf = NetworkConfig::from(chain_type);
Self {
data_dir: PathBuf::from(".lighthouse"),

View File

@ -4,6 +4,10 @@ use serde_derive::{Deserialize, Serialize};
use types::multiaddr::{Error as MultiaddrError, Multiaddr};
//use std::time::Duration;
/// The beacon node topic string to subscribe to.
pub const BEACON_PUBSUB_TOPIC: &str = "beacon_node";
pub const SHARD_TOPIC_PREFIX: &str = "attestations"; // single topic for all attestation for the moment.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
/// Network configuration for lighthouse.
@ -22,10 +26,6 @@ pub struct Config {
pub client_version: String,
/// List of extra topics to initially subscribe to as strings.
pub topics: Vec<String>,
/// Shard pubsub topic prefix.
pub shard_prefix: String,
/// The main beacon chain topic to subscribe to.
pub beacon_chain_topic: String,
}
impl Default for Config {
@ -41,8 +41,6 @@ impl Default for Config {
boot_nodes: vec![],
client_version: version::version(),
topics: Vec::new(),
beacon_chain_topic: String::from("beacon_chain"),
shard_prefix: String::from("attestations"), // single topic for all attestation for the moment.
}
}
}

View File

@ -9,7 +9,7 @@ pub mod rpc;
mod service;
pub use behaviour::PubsubMessage;
pub use config::Config as NetworkConfig;
pub use config::{ChainType, Config as NetworkConfig, BEACON_PUBSUB_TOPIC, SHARD_TOPIC_PREFIX};
pub use libp2p::floodsub::{Topic, TopicBuilder, TopicHash};
pub use libp2p::multiaddr;
pub use libp2p::Multiaddr;

View File

@ -4,6 +4,7 @@ use crate::multiaddr::Protocol;
use crate::rpc::RPCEvent;
use crate::NetworkConfig;
use crate::{TopicBuilder, TopicHash};
use crate::{BEACON_PUBSUB_TOPIC, SHARD_TOPIC_PREFIX};
use futures::prelude::*;
use futures::Stream;
use libp2p::core::{
@ -88,8 +89,8 @@ impl Service {
let mut topics = vec![];
//TODO: Handle multiple shard attestations. For now we simply use a separate topic for
//attestations
topics.push(config.shard_prefix);
topics.push(config.beacon_chain_topic);
topics.push(SHARD_TOPIC_PREFIX.to_string());
topics.push(BEACON_PUBSUB_TOPIC.to_string());
topics.append(&mut config.topics.clone());

View File

@ -4,6 +4,6 @@ pub mod message_handler;
pub mod service;
pub mod sync;
pub use eth2_libp2p::NetworkConfig;
pub use eth2_libp2p::{ChainType, NetworkConfig};
pub use service::NetworkMessage;
pub use service::Service;

View File

@ -1,6 +1,7 @@
use beacon_chain::{BeaconChain, BeaconChainTypes};
use eth2_libp2p::PubsubMessage;
use eth2_libp2p::TopicBuilder;
use eth2_libp2p::SHARD_TOPIC_PREFIX;
use futures::Future;
use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink};
use network::NetworkMessage;
@ -137,11 +138,8 @@ impl<T: BeaconChainTypes> AttestationService for AttestationServiceInstance<T> {
"type" => "valid_attestation",
);
// get the network topic to send on
let topic_string = self.chain.get_spec().shard_topic_prefix.clone();
// valid attestation, propagate to the network
let topic = TopicBuilder::new(topic_string).build();
let topic = TopicBuilder::new(SHARD_TOPIC_PREFIX).build();
let message = PubsubMessage::Attestation(attestation);
self.network_chan

View File

@ -1,6 +1,7 @@
use beacon_chain::{BeaconChain, BeaconChainTypes, BlockProcessingOutcome};
use crossbeam_channel;
use eth2_libp2p::PubsubMessage;
use eth2_libp2p::BEACON_PUBSUB_TOPIC;
use eth2_libp2p::{PubsubMessage, TopicBuilder};
use futures::Future;
use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink};
use network::NetworkMessage;
@ -105,8 +106,7 @@ impl<T: BeaconChainTypes> BeaconBlockService for BeaconBlockServiceInstance<T> {
);
// get the network topic to send on
let topic_string = self.chain.get_spec().beacon_chain_topic.clone();
let topic = types::TopicBuilder::new(topic_string).build();
let topic = TopicBuilder::new(BEACON_PUBSUB_TOPIC).build();
let message = PubsubMessage::Block(block);
// Publish the block to the p2p network via gossipsub.