Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
482a074
reshuffle consensus libraries
rphmeier Feb 8, 2018
917b092
polkadot-useful type definitions for statement table
rphmeier Feb 8, 2018
8e2fd3c
begin BftService
rphmeier Feb 10, 2018
776cf13
Merge branch 'master' into rh-split-bft-table
rphmeier Feb 10, 2018
6abfed4
primary selection logic
rphmeier Feb 12, 2018
fc18524
bft service implementation without I/O
rphmeier Feb 12, 2018
017fd51
extract out `BlockImport` trait
rphmeier Feb 12, 2018
25990ee
Merge branch 'master' into rh-split-bft-table
rphmeier Feb 12, 2018
c33c3ff
allow bft primitives to compile on wasm
rphmeier Feb 12, 2018
acab9a3
Block builder (substrate)
gavofyork Feb 12, 2018
1830fa7
take polkadot-consensus down to the core.
rphmeier Feb 12, 2018
767a9d9
test for preemption
rphmeier Feb 12, 2018
7fc4b4d
fix test build
rphmeier Feb 12, 2018
9acd3f9
Fix wasm build
gavofyork Feb 12, 2018
ca5900f
Bulid on any block
gavofyork Feb 13, 2018
d11cfe1
Test for block builder.
gavofyork Feb 13, 2018
b973ccc
Block import tests for client.
gavofyork Feb 13, 2018
ec61865
Tidy ups
gavofyork Feb 13, 2018
23638cd
clean up block builder instantiation
rphmeier Feb 15, 2018
dda6d24
Merge branch 'rh-split-bft-table' into rh-justification-verification
rphmeier Feb 15, 2018
340ce39
justification verification logic
rphmeier Feb 15, 2018
170b0d1
JustifiedHeader and import
rphmeier Feb 15, 2018
6a1a851
Propert block generation for tests
arkpar Feb 15, 2018
1352765
network and tablerouter trait
rphmeier Feb 15, 2018
2758503
use statement import to drive creation of further statements
rphmeier Feb 15, 2018
a1247bd
Fixed rpc tests
arkpar Feb 15, 2018
a1a19b6
custom error type for consensus
rphmeier Feb 15, 2018
40a9496
create proposer
rphmeier Feb 15, 2018
9e4f273
asynchronous proposal evaluation
rphmeier Feb 15, 2018
673fc2c
Merge branch 'master' into rh-justification-verification
rphmeier Feb 15, 2018
8636b77
Merge branch 'rh-justification-verification' into rh-polkadot-propose
rphmeier Feb 15, 2018
a5c09c8
inherent transactions in polkadot runtime
rphmeier Feb 16, 2018
7b1a563
fix tests to match real polkadot block constraints
rphmeier Feb 16, 2018
8d08573
implicitly generate inherent functions
rphmeier Feb 16, 2018
2abbe6c
add inherent transaction functionality to block body
rphmeier Feb 20, 2018
5bace3a
Merge branch 'master' into rh-polkadot-propose
rphmeier Feb 20, 2018
a87afa7
block builder logic for polkadot
rphmeier Feb 20, 2018
e891649
some tests for the polkadot API
rphmeier Feb 20, 2018
5b3556c
avoid redundancy in native code compatibility check
rphmeier Feb 21, 2018
ad8a576
helper for extracting nonce
rphmeier Feb 21, 2018
40b5e4c
transaction pool implementation
rphmeier Feb 21, 2018
760aeff
transaction pool
rphmeier Feb 23, 2018
198ff7b
integrate transaction pool with proposer
rphmeier Feb 23, 2018
3d052fb
Merge branch 'master' into rh-transaction-pool
rphmeier Feb 25, 2018
fd8e624
indentation
rphmeier Feb 25, 2018
8458389
kill storage keys module
rphmeier Feb 25, 2018
81ff2ad
accept new transactions to replace old
rphmeier Mar 1, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allow bft primitives to compile on wasm
  • Loading branch information
rphmeier committed Feb 12, 2018
commit c33c3ff8c54484e7e73c6f737c71033dd7cdfff9
1 change: 1 addition & 0 deletions Cargo.lock

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

Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions substrate/bft/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ substrate-state-machine = { path = "../state-machine" }
ed25519 = { path = "../ed25519" }
tokio-timer = "0.1.2"
parking_lot = "0.4"
error-chain = "0.11"
57 changes: 57 additions & 0 deletions substrate/bft/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2017 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Error types in the BFT service.

error_chain! {
errors {
/// Missing state at block with given Id.
StateUnavailable(b: ::client::BlockId) {
description("State missing at given block."),
display("State unavailable at block {:?}", b),
}

/// I/O terminated unexpectedly
IoTerminated {
description("I/O terminated unexpectedly."),
display("I/O terminated unexpectedly."),
}

/// Unable to schedule wakeup.
FaultyTimer {
description("Faulty timer: unable to schedule wakeup"),
display("Faulty timer: unable to schedule wakeup"),
}

/// Unable to propose a block.
CannotPropose {
description("Unable to create block proposal."),
display("Unable to create block proposal."),
}

/// Error dispatching the agreement future onto the executor.
Executor(e: ::futures::future::ExecuteErrorKind) {
description("Unable to dispatch agreement future"),
display("Unable to dispatch agreement future: {:?}", e),
}
}
}

impl From<::generic::InputStreamConcluded> for Error {
fn from(_: ::generic::InputStreamConcluded) -> Error {
ErrorKind::IoTerminated.into()
}
}
6 changes: 4 additions & 2 deletions substrate/bft/src/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ use std::hash::Hash;

use futures::{future, Future, Stream, Sink, Poll, Async, AsyncSink};

use accumulator::State;
use self::accumulator::State;

pub use accumulator::{Accumulator, Justification, PrepareJustification, UncheckedJustification};
pub use self::accumulator::{Accumulator, Justification, PrepareJustification, UncheckedJustification};

mod accumulator;

#[cfg(test)]
mod tests;
Expand Down
58 changes: 31 additions & 27 deletions substrate/bft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! BFT Agreement based on a rotating proposer in different rounds.

mod accumulator;
pub mod error;
pub mod generic;

extern crate substrate_codec as codec;
Expand All @@ -30,11 +30,14 @@ extern crate parking_lot;
#[macro_use]
extern crate futures;

#[macro_use]
extern crate error_chain;

use std::collections::HashMap;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};

use client::Client;
use client::{BlockId, Client};
use client::backend::Backend;
use codec::Slicable;
use ed25519::Signature;
Expand All @@ -43,12 +46,13 @@ use primitives::AuthorityId;
use state_machine::CodeExecutor;

use futures::{stream, task, Async, Sink, Future};
use futures::future::{Executor, ExecuteErrorKind};
use futures::future::Executor;
use futures::sync::oneshot;
use tokio_timer::Timer;
use parking_lot::Mutex;

pub use generic::InputStreamConcluded;
pub use error::{Error, ErrorKind};

/// Messages over the proposal.
/// Each message carries an associated round number.
Expand All @@ -74,23 +78,6 @@ pub type Committed = generic::Committed<Block, HeaderHash, Signature>;
/// Communication between BFT participants.
pub type Communication = generic::Communication<Block, HeaderHash, AuthorityId, Signature>;

/// Errors that can occur during agreement.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Error {
/// Io streams terminated.
IoTerminated,
/// Timer failed to fire.
FaultyTimer,
/// Unable to propose for some reason.
CannotPropose,
}

impl From<InputStreamConcluded> for Error {
fn from(_: InputStreamConcluded) -> Error {
Error::IoTerminated
}
}

/// Logic for a proposer.
///
/// This will encapsulate creation and evaluation of proposals at a specific
Expand All @@ -115,6 +102,12 @@ pub trait BlockImport {
fn import_block(&self, block: Block, justification: Justification);
}

/// Trait for getting the authorities at a given block.
pub trait Authorities {
/// Get the authorities at the given block.
fn authorities(&self, at: &BlockId) -> Result<Vec<AuthorityId>, Error>;
}

impl<B, E> BlockImport for Client<B, E>
where
B: Backend,
Expand All @@ -127,6 +120,17 @@ impl<B, E> BlockImport for Client<B, E>
}
}

impl<B, E> Authorities for Client<B, E>
where
B: Backend,
E: CodeExecutor,
client::error::Error: From<<B::State as state_machine::backend::Backend>::Error>
{
fn authorities(&self, at: &BlockId) -> Result<Vec<AuthorityId>, Error> {
self.authorities_at(at).map_err(|_| ErrorKind::StateUnavailable(*at).into())
}
}


/// Instance of BFT agreement.
struct BftInstance<P> {
Expand Down Expand Up @@ -213,7 +217,7 @@ impl<P: Proposer> generic::Context for BftInstance<P> {
.saturating_mul(self.round_timeout_multiplier);

Box::new(self.timer.sleep(Duration::from_secs(timeout))
.map_err(|_| Error::FaultyTimer))
.map_err(|_| ErrorKind::FaultyTimer.into()))
}
}

Expand Down Expand Up @@ -295,7 +299,7 @@ impl Drop for AgreementHandle {
/// The BftService kicks off the agreement process on top of any blocks it
/// is notified of.
pub struct BftService<P, E, I> {
import: Arc<I>,
client: Arc<I>,
executor: E,
live_agreements: Mutex<HashMap<HeaderHash, AgreementHandle>>,
timer: Timer,
Expand All @@ -308,21 +312,21 @@ impl<P, E, I> BftService<P, E, I>
where
P: Proposer,
E: Executor<BftFuture<P, I>>,
I: BlockImport,
I: BlockImport + Authorities,
{
/// Signal that a valid block with the given header has been imported.
///
/// This will begin the consensus process to build a block on top of it.
/// If the executor fails to run the future, an error will be returned.
pub fn build_upon(&self, header: &Header) -> Result<(), ExecuteErrorKind> {
pub fn build_upon(&self, header: &Header) -> Result<(), Error> {
let parent_hash = header.parent_hash.clone();
let hash = header.hash();
let mut _preempted_consensus = None;

let proposer = P::init(header, self.key.clone());

// TODO: check key is one of the authorities.
let authorities = Vec::new();
let authorities = self.client.authorities(&BlockId::Hash(hash))?;
let n = authorities.len();
let max_faulty = n.saturating_sub(1) / 3;

Expand Down Expand Up @@ -350,8 +354,8 @@ impl<P, E, I> BftService<P, E, I>
inner: agreement,
cancel: cancel.clone(),
send_task: Some(tx),
import: self.import.clone(),
}).map_err(|e| e.kind())?;
import: self.client.clone(),
}).map_err(|e| e.kind()).map_err(ErrorKind::Executor)?;

{
let mut live = self.live_agreements.lock();
Expand Down
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions substrate/primitives/src/bft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use block::{Block, HeaderHash};
use codec::{Slicable, Input};
use rstd::vec::Vec;

#[derive(Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(Debug))]
Expand Down
1 change: 1 addition & 0 deletions substrate/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl Header {
}

/// Get the blake2-256 hash of this header.
#[cfg(feature = "std")]
pub fn hash(&self) -> HeaderHash {
::hashing::blake2_256(Slicable::encode(self).as_slice()).into()
}
Expand Down
Binary file not shown.
Binary file not shown.