mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
consensus: handle justification sync for blocks authored locally (#8698)
* consensus: add trait to control justification sync process * network: implement JustificationSyncLink for NetworkService * slots: handle justification sync in slot worker * babe: fix slot worker instantiation * aura: fix slot worker instantiation * pow: handle justification sync in miner * babe: fix tests * aura: fix tests * node: fix compilation * node-template: fix compilation * consensus: rename justification sync link parameter * aura: fix test compilation * consensus: slots: move JustificationSyncLink out of on_slot
This commit is contained in:
@@ -527,20 +527,21 @@ pub fn import_queue<B, Transaction, Algorithm>(
|
||||
///
|
||||
/// `pre_runtime` is a parameter that allows a custom additional pre-runtime digest to be inserted
|
||||
/// for blocks being built. This can encode authorship information, or just be a graffiti.
|
||||
pub fn start_mining_worker<Block, C, S, Algorithm, E, SO, CAW, CIDP>(
|
||||
pub fn start_mining_worker<Block, C, S, Algorithm, E, SO, L, CIDP, CAW>(
|
||||
block_import: BoxBlockImport<Block, sp_api::TransactionFor<C, Block>>,
|
||||
client: Arc<C>,
|
||||
select_chain: S,
|
||||
algorithm: Algorithm,
|
||||
mut env: E,
|
||||
mut sync_oracle: SO,
|
||||
justification_sync_link: L,
|
||||
pre_runtime: Option<Vec<u8>>,
|
||||
create_inherent_data_providers: CIDP,
|
||||
timeout: Duration,
|
||||
build_time: Duration,
|
||||
can_author_with: CAW,
|
||||
) -> (
|
||||
Arc<Mutex<MiningWorker<Block, Algorithm, C, <E::Proposer as Proposer<Block>>::Proof>>>,
|
||||
Arc<Mutex<MiningWorker<Block, Algorithm, C, L, <E::Proposer as Proposer<Block>>::Proof>>>,
|
||||
impl Future<Output = ()>,
|
||||
) where
|
||||
Block: BlockT,
|
||||
@@ -552,14 +553,16 @@ pub fn start_mining_worker<Block, C, S, Algorithm, E, SO, CAW, CIDP>(
|
||||
E::Error: std::fmt::Debug,
|
||||
E::Proposer: Proposer<Block, Transaction = sp_api::TransactionFor<C, Block>>,
|
||||
SO: SyncOracle + Clone + Send + Sync + 'static,
|
||||
CAW: CanAuthorWith<Block> + Clone + Send + 'static,
|
||||
L: sp_consensus::JustificationSyncLink<Block>,
|
||||
CIDP: CreateInherentDataProviders<Block, ()>,
|
||||
CAW: CanAuthorWith<Block> + Clone + Send + 'static,
|
||||
{
|
||||
let mut timer = UntilImportedOrTimeout::new(client.import_notification_stream(), timeout);
|
||||
let worker = Arc::new(Mutex::new(MiningWorker::<Block, Algorithm, C, _> {
|
||||
let worker = Arc::new(Mutex::new(MiningWorker {
|
||||
build: None,
|
||||
algorithm: algorithm.clone(),
|
||||
block_import,
|
||||
justification_sync_link,
|
||||
}));
|
||||
let worker_ret = worker.clone();
|
||||
|
||||
|
||||
@@ -18,8 +18,12 @@
|
||||
|
||||
use std::{pin::Pin, time::Duration, collections::HashMap, borrow::Cow};
|
||||
use sc_client_api::ImportNotifications;
|
||||
use sp_runtime::{DigestItem, traits::Block as BlockT, generic::BlockId};
|
||||
use sp_consensus::{Proposal, BlockOrigin, BlockImportParams, import_queue::BoxBlockImport};
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, Header as HeaderT},
|
||||
DigestItem,
|
||||
};
|
||||
use futures::{prelude::*, task::{Context, Poll}};
|
||||
use futures_timer::Delay;
|
||||
use log::*;
|
||||
@@ -57,18 +61,22 @@ pub struct MiningWorker<
|
||||
Block: BlockT,
|
||||
Algorithm: PowAlgorithm<Block>,
|
||||
C: sp_api::ProvideRuntimeApi<Block>,
|
||||
Proof
|
||||
L: sp_consensus::JustificationSyncLink<Block>,
|
||||
Proof,
|
||||
> {
|
||||
pub(crate) build: Option<MiningBuild<Block, Algorithm, C, Proof>>,
|
||||
pub(crate) algorithm: Algorithm,
|
||||
pub(crate) block_import: BoxBlockImport<Block, sp_api::TransactionFor<C, Block>>,
|
||||
pub(crate) justification_sync_link: L,
|
||||
}
|
||||
|
||||
impl<Block, Algorithm, C, Proof> MiningWorker<Block, Algorithm, C, Proof> where
|
||||
impl<Block, Algorithm, C, L, Proof> MiningWorker<Block, Algorithm, C, L, Proof>
|
||||
where
|
||||
Block: BlockT,
|
||||
C: sp_api::ProvideRuntimeApi<Block>,
|
||||
Algorithm: PowAlgorithm<Block>,
|
||||
Algorithm::Difficulty: 'static + Send,
|
||||
L: sp_consensus::JustificationSyncLink<Block>,
|
||||
sp_api::TransactionFor<C, Block>: Send + 'static,
|
||||
{
|
||||
/// Get the current best hash. `None` if the worker has just started or the client is doing
|
||||
@@ -139,8 +147,11 @@ impl<Block, Algorithm, C, Proof> MiningWorker<Block, Algorithm, C, Proof> where
|
||||
Box::new(intermediate) as Box<_>,
|
||||
);
|
||||
|
||||
let header = import_block.post_header();
|
||||
match self.block_import.import_block(import_block, HashMap::default()).await {
|
||||
Ok(_) => {
|
||||
Ok(res) => {
|
||||
res.handle_justification(&header.hash(), *header.number(), &mut self.justification_sync_link);
|
||||
|
||||
info!(
|
||||
target: "pow",
|
||||
"✅ Successfully mined block on top of: {}",
|
||||
|
||||
Reference in New Issue
Block a user