mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 02:48:03 +00:00
Split BlockImport and JustificationImport (#1521)
* Split BlockImport and JustificationImport * Remove unused trait impl * Fix compile * Fix grandpa tests * Fix network tests
This commit is contained in:
committed by
Robert Habermeier
parent
14e8be794f
commit
dd88dc6cd6
@@ -144,15 +144,20 @@ impl<Block: BlockT> ImportBlock<Block> {
|
||||
pub trait BlockImport<B: BlockT> {
|
||||
type Error: ::std::error::Error + Send + 'static;
|
||||
|
||||
/// Called by the import queue when it is started.
|
||||
fn on_start(&self, _link: &::import_queue::Link<B>) { }
|
||||
|
||||
/// Import a Block alongside the new authorities valid from this block forward
|
||||
fn import_block(
|
||||
&self,
|
||||
block: ImportBlock<B>,
|
||||
new_authorities: Option<Vec<AuthorityIdFor<B>>>,
|
||||
) -> Result<ImportResult, Self::Error>;
|
||||
}
|
||||
|
||||
/// Justification import trait
|
||||
pub trait JustificationImport<B: BlockT> {
|
||||
type Error: ::std::error::Error + Send + 'static;
|
||||
|
||||
/// Called by the import queue when it is started.
|
||||
fn on_start(&self, _link: &::import_queue::Link<B>) { }
|
||||
|
||||
/// Import a Block justification and finalize the given block.
|
||||
fn import_justification(
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
//! The `BasicQueue` and `BasicVerifier` traits allow serial queues to be
|
||||
//! instantiated simply.
|
||||
|
||||
use block_import::{ImportBlock, BlockImport, ImportResult, BlockOrigin};
|
||||
use block_import::{ImportBlock, BlockImport, JustificationImport, ImportResult, BlockOrigin};
|
||||
use std::collections::{HashSet, VecDeque};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
@@ -38,6 +38,9 @@ use error::Error as ConsensusError;
|
||||
/// Shared block import struct used by the queue.
|
||||
pub type SharedBlockImport<B> = Arc<dyn BlockImport<B, Error=ConsensusError> + Send + Sync>;
|
||||
|
||||
/// Shared justification import struct used by the queue.
|
||||
pub type SharedJustificationImport<B> = Arc<dyn JustificationImport<B, Error=ConsensusError> + Send + Sync>;
|
||||
|
||||
/// Maps to the Origin used by the network.
|
||||
pub type Origin = usize;
|
||||
|
||||
@@ -111,6 +114,7 @@ pub struct BasicQueue<B: BlockT, V: 'static + Verifier<B>> {
|
||||
data: Arc<AsyncImportQueueData<B>>,
|
||||
verifier: Arc<V>,
|
||||
block_import: SharedBlockImport<B>,
|
||||
justification_import: Option<SharedJustificationImport<B>>,
|
||||
}
|
||||
|
||||
/// Locks order: queue, queue_blocks, best_importing_number
|
||||
@@ -123,13 +127,14 @@ pub struct AsyncImportQueueData<B: BlockT> {
|
||||
}
|
||||
|
||||
impl<B: BlockT, V: Verifier<B>> BasicQueue<B, V> {
|
||||
/// Instantiate a new basic queue, with given verifier.
|
||||
pub fn new(verifier: Arc<V>, block_import: SharedBlockImport<B>) -> Self {
|
||||
/// Instantiate a new basic queue, with given verifier and justification import.
|
||||
pub fn new(verifier: Arc<V>, block_import: SharedBlockImport<B>, justification_import: Option<SharedJustificationImport<B>>) -> Self {
|
||||
Self {
|
||||
handle: Mutex::new(None),
|
||||
data: Arc::new(AsyncImportQueueData::new()),
|
||||
verifier,
|
||||
block_import,
|
||||
justification_import,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,8 +167,11 @@ impl<B: BlockT, V: 'static + Verifier<B>> ImportQueue<B> for BasicQueue<B, V> {
|
||||
let qdata = self.data.clone();
|
||||
let verifier = self.verifier.clone();
|
||||
let block_import = self.block_import.clone();
|
||||
let justification_import = self.justification_import.clone();
|
||||
*self.handle.lock() = Some(::std::thread::Builder::new().name("ImportQueue".into()).spawn(move || {
|
||||
block_import.on_start(&link);
|
||||
if let Some(justification_import) = justification_import.as_ref() {
|
||||
justification_import.on_start(&link);
|
||||
}
|
||||
import_thread(block_import, link, qdata, verifier)
|
||||
})?);
|
||||
Ok(())
|
||||
@@ -223,7 +231,9 @@ impl<B: BlockT, V: 'static + Verifier<B>> ImportQueue<B> for BasicQueue<B, V> {
|
||||
}
|
||||
|
||||
fn import_justification(&self, hash: B::Hash, number: NumberFor<B>, justification: Justification) -> bool {
|
||||
self.block_import.import_justification(hash, number, justification).is_ok()
|
||||
self.justification_import.as_ref().map(|justification_import| {
|
||||
justification_import.import_justification(hash, number, justification).is_ok()
|
||||
}).unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,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, ForkChoiceStrategy};
|
||||
pub use block_import::{BlockImport, JustificationImport, ImportBlock, BlockOrigin, ImportResult, ForkChoiceStrategy};
|
||||
|
||||
/// Trait for getting the authorities at a given block.
|
||||
pub trait Authorities<B: Block> {
|
||||
|
||||
Reference in New Issue
Block a user