Generalize the Consensus Infrastructure (#883)

* Split out Consensus
* Supply ImportQueue through network-service
  - simplify ImportQueue.import_blocks
  - remove Deadlock on import_block
  - Adding Verifier-Trait
  - Implement import_queue provisioning in service; allow cli to import
* Allow to actually customize import queue
* Consensus Gossip: Cache Message hash per Topic
This commit is contained in:
Benjamin Kampmann
2018-10-16 13:40:33 +02:00
committed by GitHub
parent a24e61cb29
commit ac4bcf879f
61 changed files with 1937 additions and 3306 deletions
+11 -40
View File
@@ -16,14 +16,10 @@
//! Client extension for tests.
use client::{self, Client};
use keyring::Keyring;
use primitives::ed25519;
use runtime_primitives::traits::{Block as BlockT, Header as HeaderT};
use client::{self, ImportBlock, Client};
use runtime_primitives::generic::BlockId;
use primitives::Blake2Hasher;
use runtime;
use bft;
/// Extension trait for a test client.
pub trait TestClient {
@@ -43,15 +39,16 @@ impl<B, E> TestClient for Client<B, E, runtime::Block>
E: client::CallExecutor<runtime::Block, Blake2Hasher>
{
fn justify_and_import(&self, origin: client::BlockOrigin, block: runtime::Block) -> client::error::Result<()> {
let authorities: [ed25519::Pair; 3] = [
Keyring::Alice.into(),
Keyring::Bob.into(),
Keyring::Charlie.into(),
];
let keys: Vec<&ed25519::Pair> = authorities.iter().collect();
let justification = fake_justify::<runtime::Block>(&block.header, &keys);
let justified = self.check_justification(block.header, justification)?;
self.import_block(origin, justified, Some(block.extrinsics), false)?;
let import = ImportBlock {
origin,
header: block.header,
external_justification: vec![],
internal_justification: vec![],
body: Some(block.extrinsics),
finalized: false,
auxiliary: Vec::new(),
};
self.import_block(import, None)?;
Ok(())
}
@@ -64,29 +61,3 @@ impl<B, E> TestClient for Client<B, E, runtime::Block>
self.block_hash(0).unwrap().unwrap()
}
}
/// Prepare fake justification for the header.
///
/// since we are in the client module we can create falsely justified
/// headers.
/// TODO: remove this in favor of custom verification pipelines for the
/// client
pub fn fake_justify<Block: BlockT>(header: &Block::Header, authorities: &[&ed25519::Pair]) -> bft::UncheckedJustification<Block::Hash> {
let hash = header.hash();
bft::UncheckedJustification::new(
hash,
authorities.iter().map(|key| {
let msg = bft::sign_message::<Block>(
::rhododendron::Vote::Commit(1, hash).into(),
key,
header.parent_hash().clone(),
);
match msg {
::rhododendron::LocalizedMessage::Vote(vote) => vote.signature,
_ => panic!("signing vote leads to signed vote"),
}
}).collect(),
1,
)
}
+1 -3
View File
@@ -20,8 +20,6 @@
#![warn(missing_docs)]
extern crate rhododendron;
extern crate substrate_bft as bft;
extern crate parity_codec as codec;
extern crate substrate_primitives as primitives;
extern crate sr_primitives as runtime_primitives;
@@ -35,7 +33,7 @@ pub mod client_ext;
pub mod trait_tests;
mod block_builder_ext;
pub use client_ext::{TestClient, fake_justify};
pub use client_ext::TestClient;
pub use block_builder_ext::BlockBuilderExt;
pub use client::blockchain;
pub use client::backend;