Skip to content

Commit

Permalink
Fix some network and consensus modules bug (paritytech#23)
Browse files Browse the repository at this point in the history
* Trim network module

* Format code and add client import stream

* Fix block import notify network

* Fix validator AUTHORITY roles
  • Loading branch information
gguoss committed Sep 14, 2018
1 parent a1ea731 commit bc2945c
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 128 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions consensus/src/evaluation.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright 2018 Chainpool.

//! ChainX block evaluation and evaluation errors.
use chainx_runtime::{Block as ChainXGenericBlock, CheckedBlock};
use chainx_primitives::{Block, Hash, BlockNumber, Timestamp};

use super::MAX_TRANSACTIONS_SIZE;

use codec::{Decode, Encode};
use chainx_runtime::{Block as ChainXGenericBlock, CheckedBlock};
use chainx_primitives::{Block, Hash, BlockNumber, Timestamp};

error_chain! {
links {
Expand Down
52 changes: 26 additions & 26 deletions consensus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
// Copyright 2018 Chainpool.
extern crate substrate_bft as bft;
extern crate substrate_codec as codec;
extern crate substrate_primitives as primitives;
extern crate substrate_runtime_support as runtime_support;

extern crate substrate_runtime_primitives as runtime_primitives;
extern crate substrate_runtime_support as runtime_support;
extern crate substrate_primitives as primitives;
extern crate substrate_client as client;
extern crate substrate_network;
extern crate substrate_codec as codec;
extern crate substrate_extrinsic_pool;
extern crate substrate_bft as bft;
extern crate substrate_network;

extern crate chainx_runtime;
extern crate chainx_primitives;
extern crate chainx_api;
extern crate chainx_runtime;
extern crate chainx_pool;
extern crate chainx_api;

extern crate exit_future;
extern crate tokio;
extern crate rhododendron;
extern crate exit_future;
extern crate parking_lot;
#[macro_use]
extern crate error_chain;
#[macro_use]
extern crate futures;
extern crate ed25519;
extern crate tokio;
#[macro_use]
extern crate log;
extern crate ed25519;
extern crate parking_lot;

mod evaluation;
mod error;
mod dynamic_inclusion;
mod offline_tracker;
mod evaluation;
mod service;
mod dynamic_inclusion;
mod error;

use std::sync::Arc;
use tokio::timer::{Delay, Interval};
use std::time::{Duration, Instant};
use tokio::runtime::TaskExecutor;
use parking_lot::RwLock;
use futures::prelude::*;
use futures::future;
use std::sync::Arc;

use codec::{Decode, Encode};
use primitives::AuthorityId;
use tokio::runtime::TaskExecutor;
use tokio::timer::{Delay, Interval};
use chainx_primitives::{CandidateReceipt, BlockId, Hash, Block, Header, AccountId, BlockNumber,
Timestamp, SessionKey};
use chainx_api::ChainXApi;

use futures::prelude::*;
use futures::future;
use parking_lot::RwLock;
use chainx_primitives::{CandidateReceipt, BlockId, Hash, Block, Header, AccountId, BlockNumber, Timestamp, SessionKey};
use chainx_api::ChainXApi;

pub use self::error::{ErrorKind, Error};
pub use self::offline_tracker::OfflineTracker;
pub use service::Service;
use dynamic_inclusion::DynamicInclusion;
pub use self::error::{ErrorKind, Error};
pub use service::Service;

pub type TransactionPool = substrate_extrinsic_pool::Pool<chainx_pool::PoolApi>;
/// Shared offline validator tracker.
pub type SharedOfflineTracker = Arc<RwLock<OfflineTracker>>;
pub type TransactionPool = substrate_extrinsic_pool::Pool<chainx_pool::PoolApi>;

// block size limit.
const MAX_TRANSACTIONS_SIZE: usize = 4 * 1024 * 1024;
Expand Down
13 changes: 6 additions & 7 deletions consensus/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
// Copyright 2018 Chainpool.

//! Consensus service.

/// Consensus service. A long running service that manages BFT agreement over the network.
///
/// This uses a handle to an underlying thread pool to dispatch heavy work
/// such as candidate verification while performing event-driven work
/// on a local event loop.

use std::thread;
use std::time::{Duration, Instant};
use std::sync::Arc;
use std::thread;

use bft::{self, BftService};
use client::{BlockchainEvents, ChainHead, BlockBody};
use super::{Network, ProposerFactory};
use ed25519;
use futures::prelude::*;
use error;

use tokio::executor::current_thread::TaskExecutor as LocalThreadHandle;
use tokio::runtime::TaskExecutor as ThreadPoolHandle;
use tokio::runtime::current_thread::Runtime as LocalRuntime;
use tokio::runtime::TaskExecutor as ThreadPoolHandle;
use tokio::timer::{Delay, Interval};
use futures::prelude::*;

use super::{Network, ProposerFactory};
use error;
use chainx_primitives::{Block, Header};
use bft::{self, BftService};
use chainx_api::ChainXApi;
use TransactionPool;

Expand Down
15 changes: 7 additions & 8 deletions network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ version = "0.1.0"
authors = ["Chainpool <https://www.chainx.org>"]

[dependencies]
parking_lot = "0.4"
chainx-api = { path = "../api" }
chainx-consensus = { path = "../consensus" }
chainx-primitives = { path = "../primitives" }
substrate-bft = { git = "https://github.com/chainx-org/substrate" }
substrate-codec = { git = "https://github.com/chainx-org/substrate" }
substrate-codec-derive = { git = "https://github.com/chainx-org/substrate" }
substrate-network = { git = "https://github.com/chainx-org/substrate" }
substrate-primitives = { git = "https://github.com/chainx-org/substrate" }
substrate-network = { git = "https://github.com/chainx-org/substrate" }
substrate-codec = { git = "https://github.com/chainx-org/substrate" }
substrate-bft = { git = "https://github.com/chainx-org/substrate" }
chainx-primitives = { path = "../primitives" }
chainx-consensus = { path = "../consensus" }
chainx-api = { path = "../api" }
ed25519 = { git = "https://github.com/chainx-org/substrate" }
rhododendron = "0.3"
futures = "0.1"
tokio = "0.1.7"
log = "0.4"
rhododendron = "0.3"
17 changes: 6 additions & 11 deletions network/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@
//! This fulfills the `chainx_consensus::Network` trait, providing a hook to be called
//! each time consensus begins on a new chain head.

use bft;
use ed25519;
use substrate_network::{self as net, generic_message as msg};
use substrate_network::consensus_gossip::ConsensusMessage;

use chainx_primitives::{Block, Hash, SessionKey};
use chainx_api::ChainXApi;
use chainx_consensus::Network;
use chainx_primitives::{Block, Hash, SessionKey};

use tokio::runtime::TaskExecutor;
use futures::prelude::*;
use futures::sync::mpsc;

use std::sync::Arc;
use ed25519;
use bft;

use tokio::runtime::TaskExecutor;
use parking_lot::Mutex;

use super::{NetworkService, Knowledge, CurrentConsensus};
use super::{NetworkService, CurrentConsensus};

/// Sink for output BFT messages.
pub struct BftSink<E> {
Expand Down Expand Up @@ -287,15 +285,12 @@ impl<P: ChainXApi + Send + Sync + 'static> Network for ConsensusNetwork<P> {

let (bft_send, bft_recv) = mpsc::unbounded();

let knowledge = Arc::new(Mutex::new(Knowledge::new()));

let local_session_key = key.public().into();
let local_id = key.public().into();
let process_task = self.network.with_spec(|spec, ctx| {
spec.new_consensus(
ctx,
CurrentConsensus {
knowledge,
parent_hash,
local_session_key,
},
Expand Down
Loading

0 comments on commit bc2945c

Please sign in to comment.