Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
38 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
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
extract out BlockImport trait
  • Loading branch information
rphmeier committed Feb 12, 2018
commit 017fd515ed7c323e032fc12007c336ee72c09e63
53 changes: 30 additions & 23 deletions substrate/bft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ pub trait Proposer: Sized {
fn evaluate(&self, proposal: &Block) -> bool;
}

/// Block import trait.
pub trait BlockImport {
/// Import a block alongside its corresponding justification.
fn import_block(&self, block: Block, justification: Justification);
}

impl<B, E> BlockImport for Client<B, E>
where
B: Backend,
E: CodeExecutor,
client::error::Error: From<<B::State as state_machine::backend::Backend>::Error>
{
fn import_block(&self, block: Block, _justification: Justification) {
// TODO: use justification.
let _ = self.import_block(block.header, Some(block.transactions));
}
}


/// Instance of BFT agreement.
struct BftInstance<P> {
key: Arc<ed25519::Pair>,
Expand Down Expand Up @@ -218,20 +237,14 @@ impl Sink for Output {

/// A future that resolves either when canceled (witnessing a block from the network at same height)
/// or when agreement completes.
pub struct BftFuture<P: Proposer, B: Backend, X: CodeExecutor> {
pub struct BftFuture<P: Proposer, I> {
inner: generic::Agreement<BftInstance<P>, Input, Output>,
cancel: Arc<AtomicBool>,
send_task: Option<oneshot::Sender<task::Task>>,
client: Arc<Client<B, X>>,
import: Arc<I>,
}

impl<P, B, X> Future for BftFuture<P, B, X>
where
P: Proposer,
B: Backend,
X: CodeExecutor,
client::error::Error: From<<B::State as state_machine::backend::Backend>::Error>,
{
impl<P: Proposer, I: BlockImport> Future for BftFuture<P, I> {
type Item = ();
type Error = ();

Expand All @@ -249,14 +262,10 @@ impl<P, B, X> Future for BftFuture<P, B, X>
// TODO: handle this error, at least by logging.
let committed = try_ready!(self.inner.poll().map_err(|_| ()));

// If we didn't see the justification (very unlikely),
// If we didn't see the proposal (very unlikely),
// we will get the block from the network later.
if let Some(justified_block) = committed.candidate {
// TODO: import justification alongside.xw
let _ = self.client.import_block(
justified_block.header,
Some(justified_block.transactions),
);
self.import.import_block(justified_block, committed.justification)
}

Ok(Async::Ready(()))
Expand Down Expand Up @@ -285,8 +294,8 @@ 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, B: Backend, X: CodeExecutor> {
client: Arc<Client<B, X>>,
pub struct BftService<P, E, I> {
import: Arc<I>,
executor: E,
live_agreements: Mutex<HashMap<HeaderHash, AgreementHandle>>,
timer: Timer,
Expand All @@ -295,13 +304,11 @@ pub struct BftService<P, E, B: Backend, X: CodeExecutor> {
_marker: ::std::marker::PhantomData<P>,
}

impl<P, E, B, X> BftService<P, E, B, X>
impl<P, E, I> BftService<P, E, I>
where
P: Proposer,
E: Executor<BftFuture<P, B, X>>,
B: Backend,
X: CodeExecutor,
client::error::Error: From<<B::State as state_machine::backend::Backend>::Error>,
E: Executor<BftFuture<P, I>>,
I: BlockImport,
{
/// Signal that a valid block with the given header has been imported.
///
Expand Down Expand Up @@ -343,7 +350,7 @@ impl<P, E, B, X> BftService<P, E, B, X>
inner: agreement,
cancel: cancel.clone(),
send_task: Some(tx),
client: self.client.clone(),
import: self.import.clone(),
}).map_err(|e| e.kind())?;

{
Expand Down