Complete moving network logc into beacon node

This commit is contained in:
Age Manning 2019-04-03 16:33:12 +11:00
parent dd3a4f0b43
commit c1d609902a
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" } network = { path = "../network" }
store = { path = "../store" } store = { path = "../store" }
http_server = { path = "../http_server" } http_server = { path = "../http_server" }
eth2-libp2p = { path = "../eth2-libp2p" }
rpc = { path = "../rpc" } rpc = { path = "../rpc" }
prometheus = "^0.6" prometheus = "^0.6"
types = { path = "../../eth2/types" } types = { path = "../../eth2/types" }

View File

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

View File

@ -4,6 +4,10 @@ use serde_derive::{Deserialize, Serialize};
use types::multiaddr::{Error as MultiaddrError, Multiaddr}; use types::multiaddr::{Error as MultiaddrError, Multiaddr};
//use std::time::Duration; //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)] #[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)] #[serde(default)]
/// Network configuration for lighthouse. /// Network configuration for lighthouse.
@ -22,10 +26,6 @@ pub struct Config {
pub client_version: String, pub client_version: String,
/// List of extra topics to initially subscribe to as strings. /// List of extra topics to initially subscribe to as strings.
pub topics: Vec<String>, 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 { impl Default for Config {
@ -41,8 +41,6 @@ impl Default for Config {
boot_nodes: vec![], boot_nodes: vec![],
client_version: version::version(), client_version: version::version(),
topics: Vec::new(), 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; mod service;
pub use behaviour::PubsubMessage; 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::floodsub::{Topic, TopicBuilder, TopicHash};
pub use libp2p::multiaddr; pub use libp2p::multiaddr;
pub use libp2p::Multiaddr; pub use libp2p::Multiaddr;

View File

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

View File

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

View File

@ -1,6 +1,7 @@
use beacon_chain::{BeaconChain, BeaconChainTypes}; use beacon_chain::{BeaconChain, BeaconChainTypes};
use eth2_libp2p::PubsubMessage; use eth2_libp2p::PubsubMessage;
use eth2_libp2p::TopicBuilder; use eth2_libp2p::TopicBuilder;
use eth2_libp2p::SHARD_TOPIC_PREFIX;
use futures::Future; use futures::Future;
use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink}; use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink};
use network::NetworkMessage; use network::NetworkMessage;
@ -137,11 +138,8 @@ impl<T: BeaconChainTypes> AttestationService for AttestationServiceInstance<T> {
"type" => "valid_attestation", "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 // 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); let message = PubsubMessage::Attestation(attestation);
self.network_chan self.network_chan

View File

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