Remove sync crate, move into network crate

This commit is contained in:
Age Manning 2019-03-19 00:05:06 +11:00
parent 8ec0688cb9
commit 41abdb7599
No known key found for this signature in database
GPG Key ID: 05EED64B79E06A93
10 changed files with 24 additions and 25 deletions

View File

@ -23,7 +23,6 @@ members = [
"beacon_node/client", "beacon_node/client",
"beacon_node/network", "beacon_node/network",
"beacon_node/rpc", "beacon_node/rpc",
"beacon_node/sync",
"beacon_node/version", "beacon_node/version",
"beacon_node/beacon_chain", "beacon_node/beacon_chain",
"beacon_node/beacon_chain/test_harness", "beacon_node/beacon_chain/test_harness",

View File

@ -11,3 +11,4 @@ pub use db;
pub use fork_choice; pub use fork_choice;
pub use parking_lot; pub use parking_lot;
pub use slot_clock; pub use slot_clock;
pub use types;

View File

@ -7,7 +7,6 @@ edition = "2018"
[dependencies] [dependencies]
beacon_chain = { path = "../beacon_chain" } beacon_chain = { path = "../beacon_chain" }
network = { path = "../network" } network = { path = "../network" }
sync = { path = "../sync" }
db = { path = "../db" } db = { path = "../db" }
fork_choice = { path = "../../eth2/fork_choice" } fork_choice = { path = "../../eth2/fork_choice" }
types = { path = "../../eth2/types" } types = { path = "../../eth2/types" }

View File

@ -9,7 +9,6 @@ beacon_chain = { path = "../beacon_chain" }
libp2p = { path = "../libp2p" } libp2p = { path = "../libp2p" }
version = { path = "../version" } version = { path = "../version" }
types = { path = "../../eth2/types" } types = { path = "../../eth2/types" }
sync = { path = "../sync" }
slog = "2.4.1" slog = "2.4.1"
futures = "0.1.25" futures = "0.1.25"
error-chain = "0.12.0" error-chain = "0.12.0"

View File

@ -1,11 +1,13 @@
use beacon_chain::BeaconChain as RawBeaconChain; use beacon_chain::BeaconChain as RawBeaconChain;
use beacon_chain::{ use beacon_chain::{
db::ClientDB, fork_choice::ForkChoice, parking_lot::RwLockReadGuard, slot_clock::SlotClock, db::ClientDB, fork_choice::ForkChoice, parking_lot::RwLockReadGuard, slot_clock::SlotClock,
CheckPoint, types::ChainSpec, CheckPoint,
}; };
/// The network's API to the beacon chain. /// The network's API to the beacon chain.
pub trait BeaconChain: Send + Sync { pub trait BeaconChain: Send + Sync {
fn get_spec(&self) -> &ChainSpec;
fn head(&self) -> RwLockReadGuard<CheckPoint>; fn head(&self) -> RwLockReadGuard<CheckPoint>;
fn finalized_head(&self) -> RwLockReadGuard<CheckPoint>; fn finalized_head(&self) -> RwLockReadGuard<CheckPoint>;
@ -17,6 +19,10 @@ where
U: SlotClock, U: SlotClock,
F: ForkChoice, F: ForkChoice,
{ {
fn get_spec(&self) -> &ChainSpec {
&self.spec
}
fn head(&self) -> RwLockReadGuard<CheckPoint> { fn head(&self) -> RwLockReadGuard<CheckPoint> {
self.head() self.head()
} }

View File

@ -4,6 +4,7 @@ pub mod error;
mod message_handler; mod message_handler;
mod messages; mod messages;
mod service; mod service;
pub mod sync;
pub use libp2p::NetworkConfig; pub use libp2p::NetworkConfig;
pub use messages::NodeMessage; pub use messages::NodeMessage;

View File

@ -2,16 +2,15 @@ use crate::beacon_chain::BeaconChain;
use crate::error; use crate::error;
use crate::messages::NodeMessage; use crate::messages::NodeMessage;
use crate::service::NetworkMessage; use crate::service::NetworkMessage;
use crate::sync::SimpleSync;
use crossbeam_channel::{unbounded as channel, Sender}; use crossbeam_channel::{unbounded as channel, Sender};
use futures::future; use futures::future;
use futures::prelude::*; use futures::prelude::*;
use libp2p::rpc;
use libp2p::{PeerId, RPCEvent}; use libp2p::{PeerId, RPCEvent};
use slog::debug; use slog::debug;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::Arc; use std::sync::Arc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use sync::SimpleSync;
use types::Hash256; use types::Hash256;
/// Timeout for establishing a HELLO handshake. /// Timeout for establishing a HELLO handshake.
@ -57,13 +56,11 @@ impl MessageHandler {
let (handler_send, handler_recv) = channel(); let (handler_send, handler_recv) = channel();
// Initialise sync and begin processing in thread // Initialise sync and begin processing in thread
//TODO: Load genesis from BeaconChain
//TODO: Initialise beacon chain
let temp_genesis = Hash256::zero();
// generate the Message handler // generate the Message handler
let sync = SimpleSync::new(temp_genesis); let sync = SimpleSync::new(beacon_chain.clone());
let mut handler = MessageHandler { let mut handler = MessageHandler {
// TODO: The handler may not need a chain, perhaps only sync?
chain: beacon_chain.clone(), chain: beacon_chain.clone(),
sync, sync,
network_send, network_send,

View File

@ -1,11 +1,15 @@
use crate::beacon_chain::BeaconChain;
use libp2p::PeerId; use libp2p::PeerId;
use std::collections::HashMap; use std::collections::HashMap;
use types::{Hash256, Slot}; use std::sync::Arc;
use types::{Epoch, Hash256, Slot};
/// Keeps track of syncing information for known connected peers. /// Keeps track of syncing information for known connected peers.
pub struct PeerSyncInfo { pub struct PeerSyncInfo {
latest_finalized_root: Hash256,
latest_finalized_epoch: Epoch,
best_root: Hash256,
best_slot: Slot, best_slot: Slot,
best_slot_hash: Hash256,
} }
/// The current syncing state. /// The current syncing state.
@ -16,18 +20,20 @@ pub enum SyncState {
} }
/// Simple Syncing protocol. /// Simple Syncing protocol.
//TODO: Decide for HELLO messages whether its better to keep current in RAM or build on the fly
//when asked.
pub struct SimpleSync { pub struct SimpleSync {
genesis_hash: Hash256,
known_peers: HashMap<PeerId, PeerSyncInfo>, known_peers: HashMap<PeerId, PeerSyncInfo>,
state: SyncState, state: SyncState,
network_id: u8,
} }
impl SimpleSync { impl SimpleSync {
pub fn new(genesis_hash: Hash256) -> Self { pub fn new(beacon_chain: Arc<BeaconChain>) -> Self {
SimpleSync { SimpleSync {
genesis_hash,
known_peers: HashMap::new(), known_peers: HashMap::new(),
state: SyncState::Idle, state: SyncState::Idle,
network_id: beacon_chain.get_spec().network_id,
} }
} }
} }

View File

@ -1,9 +0,0 @@
[package]
name = "sync"
version = "0.1.0"
authors = ["Age Manning <Age@AgeManning.com>"]
edition = "2018"
[dependencies]
types = { path = "../../eth2/types" }
libp2p = { path = "../libp2p" }