Allow for customisation of chain selection systems (#2240)

* move SelectChain trait out of client

* Extend SelectChain, move longest chain implementation into it

* Bring SelectChain into service

* implement LongestChain SelectChain

* implement longest chain for node

* update Cargo.lock's

* in between erroring tests

* deprecate ::backend and ::import_lock

* Remove unneded space

Co-Authored-By: gnunicorn <ben.kampmann@googlemail.com>

* Remove unneded space

Co-Authored-By: gnunicorn <ben.kampmann@googlemail.com>

* Fixes test compilation

* remove todo

* re-enable client test

* add doc

* fixing tests

* Clarify SelectChain Interface, intended implementation and usage

* minor components cleanups

* minor cleanups

* Update lock files

* Implement cleaner interface for SelectChain

* addressing comments

* Updating tests

* bump node runtime impl version

* address grumbles
This commit is contained in:
Benjamin Kampmann
2019-05-10 14:08:12 +02:00
committed by Gavin Wood
parent 32fdeed21c
commit 18ca0170c3
22 changed files with 717 additions and 339 deletions
+8 -9
View File
@@ -26,9 +26,8 @@ mod slots;
pub use slots::{slot_now, SlotInfo, Slots};
use client::ChainHead;
use codec::{Decode, Encode};
use consensus_common::SyncOracle;
use consensus_common::{SyncOracle, SelectChain};
use futures::prelude::*;
use futures::{
future::{self, Either},
@@ -73,7 +72,7 @@ pub fn inherent_to_common_error(err: inherents::RuntimeString) -> consensus_comm
#[deprecated(since = "1.1", note = "Please spawn a thread manually")]
pub fn start_slot_worker_thread<B, C, W, SO, SC, T, OnExit>(
slot_duration: SlotDuration<T>,
client: Arc<C>,
select_chain: C,
worker: Arc<W>,
sync_oracle: SO,
on_exit: OnExit,
@@ -81,7 +80,7 @@ pub fn start_slot_worker_thread<B, C, W, SO, SC, T, OnExit>(
) -> Result<(), consensus_common::Error>
where
B: Block + 'static,
C: ChainHead<B> + Send + Sync + 'static,
C: SelectChain<B> + Clone + 'static,
W: SlotWorker<B> + Send + Sync + 'static,
SO: SyncOracle + Send + Clone + 'static,
SC: SlotCompatible + 'static,
@@ -101,9 +100,9 @@ where
}
};
let slot_worker_future = match start_slot_worker::<_, _, _, _, _, SC, _>(
let slot_worker_future = match start_slot_worker::<_, _, _, T, _, SC, _>(
slot_duration.clone(),
client,
select_chain,
worker,
sync_oracle,
on_exit,
@@ -134,7 +133,7 @@ where
/// Start a new slot worker.
pub fn start_slot_worker<B, C, W, T, SO, SC, OnExit>(
slot_duration: SlotDuration<T>,
client: Arc<C>,
client: C,
worker: Arc<W>,
sync_oracle: SO,
on_exit: OnExit,
@@ -142,7 +141,7 @@ pub fn start_slot_worker<B, C, W, T, SO, SC, OnExit>(
) -> Result<impl Future<Item = (), Error = ()>, consensus_common::Error>
where
B: Block,
C: ChainHead<B>,
C: SelectChain<B> + Clone,
W: SlotWorker<B>,
SO: SyncOracle + Send + Clone,
SC: SlotCompatible,
@@ -173,7 +172,7 @@ where
}
let slot_num = slot_info.number;
let chain_head = match client.best_block_header() {
let chain_head = match client.best_chain() {
Ok(x) => x,
Err(e) => {
warn!(target: "slots", "Unable to author block in slot {}. \