mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 17:47:56 +00:00
core, node: use grandpa block import for locally sealed aura blocks (#1167)
* core, node: use grandpa block import for locally sealed aura blocks * core: impl DerefMut for FullComponents * node: take grandpa_import_setup from service config
This commit is contained in:
committed by
Robert Habermeier
parent
675c3b0500
commit
b7e0db725d
@@ -146,17 +146,19 @@ impl<Hash, AuthorityId> CompatibleDigestItem for generic::DigestItem<Hash, Autho
|
||||
}
|
||||
|
||||
/// Start the aura worker. This should be run in a tokio runtime.
|
||||
pub fn start_aura<B, C, E, SO, Error>(
|
||||
pub fn start_aura<B, C, E, I, SO, Error>(
|
||||
config: Config,
|
||||
client: Arc<C>,
|
||||
block_import: Arc<I>,
|
||||
env: Arc<E>,
|
||||
sync_oracle: SO,
|
||||
)
|
||||
-> impl Future<Item=(),Error=()> where
|
||||
B: Block,
|
||||
C: Authorities<B, Error=Error> + BlockImport<B, Error=Error> + ChainHead<B>,
|
||||
C: Authorities<B, Error=Error> + ChainHead<B>,
|
||||
E: Environment<B, Error=Error>,
|
||||
E::Proposer: Proposer<B, Error=Error>,
|
||||
I: BlockImport<B, Error=Error>,
|
||||
SO: SyncOracle + Send + Clone,
|
||||
DigestItemFor<B>: CompatibleDigestItem,
|
||||
Error: ::std::error::Error + Send + 'static + From<::consensus_common::Error>,
|
||||
@@ -164,6 +166,7 @@ pub fn start_aura<B, C, E, SO, Error>(
|
||||
let make_authorship = move || {
|
||||
let config = config.clone();
|
||||
let client = client.clone();
|
||||
let block_import = block_import.clone();
|
||||
let env = env.clone();
|
||||
let sync_oracle = sync_oracle.clone();
|
||||
|
||||
@@ -225,7 +228,7 @@ pub fn start_aura<B, C, E, SO, Error>(
|
||||
}
|
||||
};
|
||||
|
||||
let block_import = client.clone();
|
||||
let block_import = block_import.clone();
|
||||
Either::A(proposal_work
|
||||
.map(move |b| {
|
||||
let (header, body) = b.deconstruct();
|
||||
@@ -542,6 +545,7 @@ mod tests {
|
||||
local_key: Some(Arc::new(key.clone().into())),
|
||||
slot_duration: SLOT_DURATION
|
||||
},
|
||||
client.clone(),
|
||||
client,
|
||||
environ.clone(),
|
||||
DummyOracle,
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Substrate service components.
|
||||
|
||||
use std::{sync::Arc, net::SocketAddr, marker::PhantomData, ops::Deref};
|
||||
use std::{sync::Arc, net::SocketAddr, marker::PhantomData, ops::Deref, ops::DerefMut};
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use tokio::runtime::TaskExecutor;
|
||||
use chain_spec::{ChainSpec, Properties};
|
||||
@@ -369,6 +369,12 @@ impl<Factory: ServiceFactory> Deref for FullComponents<Factory> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<Factory: ServiceFactory> DerefMut for FullComponents<Factory> {
|
||||
fn deref_mut(&mut self) -> &mut Service<Self> {
|
||||
&mut self.service
|
||||
}
|
||||
}
|
||||
|
||||
impl<Factory: ServiceFactory> Components for FullComponents<Factory> {
|
||||
type Factory = Factory;
|
||||
type Executor = FullExecutor<Factory>;
|
||||
|
||||
@@ -310,10 +310,6 @@ impl<Components> Service<Components>
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn config(&self) -> &FactoryFullConfiguration<Components::Factory> {
|
||||
&self.config
|
||||
}
|
||||
}
|
||||
|
||||
impl<Components> Service<Components> where Components: components::Components {
|
||||
|
||||
@@ -50,7 +50,7 @@ pub struct NodeConfig<F: substrate_service::ServiceFactory> {
|
||||
|
||||
// FIXME: rather than putting this on the config, let's have an actual intermediate setup state
|
||||
// https://github.com/paritytech/substrate/issues/1134
|
||||
pub grandpa_link_half: Option<grandpa::LinkHalfForService<F>>,
|
||||
pub grandpa_import_setup: Option<(Arc<grandpa::BlockImportForService<F>>, grandpa::LinkHalfForService<F>)>,
|
||||
}
|
||||
|
||||
impl<F> Default for NodeConfig<F> where F: substrate_service::ServiceFactory {
|
||||
@@ -58,7 +58,7 @@ impl<F> Default for NodeConfig<F> where F: substrate_service::ServiceFactory {
|
||||
NodeConfig {
|
||||
grandpa_authority: false,
|
||||
grandpa_authority_only: false,
|
||||
grandpa_link_half: None
|
||||
grandpa_import_setup: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,18 +79,19 @@ construct_service_factory! {
|
||||
{ |config: FactoryFullConfiguration<Self>, executor: TaskExecutor|
|
||||
FullComponents::<Factory>::new(config, executor) },
|
||||
AuthoritySetup = {
|
||||
|service: Self::FullService, executor: TaskExecutor, key: Arc<Pair>| {
|
||||
|mut service: Self::FullService, executor: TaskExecutor, key: Arc<Pair>| {
|
||||
let (block_import, link_half) = service.config.custom.grandpa_import_setup.take()
|
||||
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
|
||||
|
||||
if service.config.custom.grandpa_authority {
|
||||
info!("Running Grandpa session as Authority {}", key.public());
|
||||
let link_half = service.config().custom.grandpa_link_half.as_ref().take()
|
||||
.expect("Link Half is present for Full Services or setup failed before. qed");
|
||||
let grandpa_fut = grandpa::run_grandpa(
|
||||
grandpa::Config {
|
||||
gossip_duration: Duration::new(4, 0), // FIXME: make this available through chainspec?
|
||||
local_key: Some(key.clone()),
|
||||
name: Some(service.config().name.clone())
|
||||
name: Some(service.config.name.clone())
|
||||
},
|
||||
(*link_half).clone(),
|
||||
link_half,
|
||||
grandpa::NetworkBridge::new(service.network())
|
||||
)?;
|
||||
|
||||
@@ -104,6 +105,7 @@ construct_service_factory! {
|
||||
slot_duration: AURA_SLOT_DURATION,
|
||||
},
|
||||
service.client(),
|
||||
block_import.clone(),
|
||||
service.proposer(),
|
||||
service.network(),
|
||||
));
|
||||
@@ -116,14 +118,16 @@ construct_service_factory! {
|
||||
FullImportQueue = AuraImportQueue<Self::Block, grandpa::BlockImportForService<Self>, NothingExtra>
|
||||
{ |config: &mut FactoryFullConfiguration<Self> , client: Arc<FullClient<Self>>| {
|
||||
let (block_import, link_half) = grandpa::block_import::<_, _, _, ClientWithApi, FullClient<Self>>(client.clone(), client)?;
|
||||
config.custom.grandpa_link_half = Some(link_half);
|
||||
let block_import = Arc::new(block_import);
|
||||
|
||||
config.custom.grandpa_import_setup = Some((block_import.clone(), link_half));
|
||||
|
||||
Ok(import_queue(
|
||||
AuraConfig {
|
||||
local_key: None,
|
||||
slot_duration: 5
|
||||
},
|
||||
Arc::new(block_import),
|
||||
block_import,
|
||||
NothingExtra,
|
||||
))
|
||||
}},
|
||||
|
||||
Reference in New Issue
Block a user