Support custom fork choice rule (#1339)

* Support custom fork choice rule

* Remove unneeded reexport

* Fix network compile
This commit is contained in:
Wei Tang
2019-01-04 20:34:58 +01:00
committed by Robert Habermeier
parent 771a8127c2
commit ac1be0665e
6 changed files with 28 additions and 6 deletions
+3 -1
View File
@@ -61,7 +61,7 @@ use std::sync::Arc;
use std::time::Duration;
use codec::Encode;
use consensus_common::{Authorities, BlockImport, Environment, Error as ConsensusError, Proposer};
use consensus_common::{Authorities, BlockImport, Environment, Error as ConsensusError, Proposer, ForkChoiceStrategy};
use consensus_common::import_queue::{Verifier, BasicQueue};
use client::ChainHead;
use client::block_builder::api::BlockBuilder as BlockBuilderApi;
@@ -324,6 +324,7 @@ pub fn start_aura<B, C, E, I, SO, Error>(
body: Some(body),
finalized: false,
auxiliary: Vec::new(),
fork_choice: ForkChoiceStrategy::LongestChain,
};
if let Err(e) = block_import.import_block(import_block, None) {
@@ -524,6 +525,7 @@ impl<B: Block, C, E, MakeInherent, Inherent> Verifier<B> for AuraVerifier<C, E,
finalized: false,
justification,
auxiliary: Vec::new(),
fork_choice: ForkChoiceStrategy::LongestChain,
};
// FIXME: extract authorities - https://github.com/paritytech/substrate/issues/1019
@@ -53,6 +53,15 @@ pub enum BlockOrigin {
File,
}
/// Fork choice strategy.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum ForkChoiceStrategy {
/// Longest chain fork choice.
LongestChain,
/// Custom fork choice rule, where true indicates the new block should be the best block.
Custom(bool),
}
/// Data required to import a Block
pub struct ImportBlock<Block: BlockT> {
/// Origin of the Block
@@ -83,6 +92,8 @@ pub struct ImportBlock<Block: BlockT> {
/// Contains a list of key-value pairs. If values are `None`, the keys
/// will be deleted.
pub auxiliary: Vec<(Vec<u8>, Option<Vec<u8>>)>,
/// Fork choice strategy of this import.
pub fork_choice: ForkChoiceStrategy,
}
impl<Block: BlockT> ImportBlock<Block> {
+1 -1
View File
@@ -55,7 +55,7 @@ pub mod evaluation;
const MAX_TRANSACTIONS_SIZE: usize = 4 * 1024 * 1024;
pub use self::error::{Error, ErrorKind};
pub use block_import::{BlockImport, ImportBlock, BlockOrigin, ImportResult};
pub use block_import::{BlockImport, ImportBlock, BlockOrigin, ImportResult, ForkChoiceStrategy};
/// Trait for getting the authorities at a given block.
pub trait Authorities<B: Block> {