mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 11:41:04 +00:00
Small slots refactor (#2780)
* Deprecate SlotWorker::on_start * start_slot_worker no longer needs an Arc * start_slot_worker now always succeeds * Removed on_exit parameter from start_*_worker * Minor doc * Fix node-template
This commit is contained in:
committed by
DemiMarie-parity
parent
eaa0ab014a
commit
67bdfc7d8e
@@ -65,7 +65,7 @@ use srml_aura::{
|
|||||||
};
|
};
|
||||||
use substrate_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG, CONSENSUS_WARN, CONSENSUS_INFO};
|
use substrate_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG, CONSENSUS_WARN, CONSENSUS_INFO};
|
||||||
|
|
||||||
use slots::{CheckedHeader, SlotWorker, SlotInfo, SlotCompatible, slot_now, check_equivocation};
|
use slots::{CheckedHeader, SlotData, SlotWorker, SlotInfo, SlotCompatible, slot_now, check_equivocation};
|
||||||
|
|
||||||
pub use aura_primitives::*;
|
pub use aura_primitives::*;
|
||||||
pub use consensus_common::{SyncOracle, ExtraVerification};
|
pub use consensus_common::{SyncOracle, ExtraVerification};
|
||||||
@@ -125,7 +125,7 @@ impl SlotCompatible for AuraSlotCompatible {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Start the aura worker. The returned future should be run in a tokio runtime.
|
/// Start the aura worker. The returned future should be run in a tokio runtime.
|
||||||
pub fn start_aura<B, C, SC, E, I, P, SO, Error, OnExit, H>(
|
pub fn start_aura<B, C, SC, E, I, P, SO, Error, H>(
|
||||||
slot_duration: SlotDuration,
|
slot_duration: SlotDuration,
|
||||||
local_key: Arc<P>,
|
local_key: Arc<P>,
|
||||||
client: Arc<C>,
|
client: Arc<C>,
|
||||||
@@ -133,7 +133,6 @@ pub fn start_aura<B, C, SC, E, I, P, SO, Error, OnExit, H>(
|
|||||||
block_import: Arc<I>,
|
block_import: Arc<I>,
|
||||||
env: Arc<E>,
|
env: Arc<E>,
|
||||||
sync_oracle: SO,
|
sync_oracle: SO,
|
||||||
on_exit: OnExit,
|
|
||||||
inherent_data_providers: InherentDataProviders,
|
inherent_data_providers: InherentDataProviders,
|
||||||
force_authoring: bool,
|
force_authoring: bool,
|
||||||
) -> Result<impl Future<Item=(), Error=()>, consensus_common::Error> where
|
) -> Result<impl Future<Item=(), Error=()>, consensus_common::Error> where
|
||||||
@@ -156,25 +155,26 @@ pub fn start_aura<B, C, SC, E, I, P, SO, Error, OnExit, H>(
|
|||||||
I: BlockImport<B> + Send + Sync + 'static,
|
I: BlockImport<B> + Send + Sync + 'static,
|
||||||
Error: ::std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
|
Error: ::std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
|
||||||
SO: SyncOracle + Send + Sync + Clone,
|
SO: SyncOracle + Send + Sync + Clone,
|
||||||
OnExit: Future<Item=(), Error=()>,
|
|
||||||
{
|
{
|
||||||
let worker = AuraWorker {
|
let worker = AuraWorker {
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
block_import,
|
block_import,
|
||||||
env,
|
env,
|
||||||
local_key,
|
local_key,
|
||||||
inherent_data_providers: inherent_data_providers.clone(),
|
|
||||||
sync_oracle: sync_oracle.clone(),
|
sync_oracle: sync_oracle.clone(),
|
||||||
force_authoring,
|
force_authoring,
|
||||||
};
|
};
|
||||||
slots::start_slot_worker::<_, _, _, _, _, AuraSlotCompatible, _>(
|
register_aura_inherent_data_provider(
|
||||||
|
&inherent_data_providers,
|
||||||
|
slot_duration.0.slot_duration()
|
||||||
|
)?;
|
||||||
|
Ok(slots::start_slot_worker::<_, _, _, _, _, AuraSlotCompatible>(
|
||||||
slot_duration.0,
|
slot_duration.0,
|
||||||
select_chain,
|
select_chain,
|
||||||
Arc::new(worker),
|
worker,
|
||||||
sync_oracle,
|
sync_oracle,
|
||||||
on_exit,
|
|
||||||
inherent_data_providers
|
inherent_data_providers
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AuraWorker<C, E, I, P, SO> {
|
struct AuraWorker<C, E, I, P, SO> {
|
||||||
@@ -183,7 +183,6 @@ struct AuraWorker<C, E, I, P, SO> {
|
|||||||
env: Arc<E>,
|
env: Arc<E>,
|
||||||
local_key: Arc<P>,
|
local_key: Arc<P>,
|
||||||
sync_oracle: SO,
|
sync_oracle: SO,
|
||||||
inherent_data_providers: InherentDataProviders,
|
|
||||||
force_authoring: bool,
|
force_authoring: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,13 +207,6 @@ impl<H, B, C, E, I, P, Error, SO> SlotWorker<B> for AuraWorker<C, E, I, P, SO> w
|
|||||||
{
|
{
|
||||||
type OnSlot = Box<dyn Future<Item=(), Error=consensus_common::Error> + Send>;
|
type OnSlot = Box<dyn Future<Item=(), Error=consensus_common::Error> + Send>;
|
||||||
|
|
||||||
fn on_start(
|
|
||||||
&self,
|
|
||||||
slot_duration: u64
|
|
||||||
) -> Result<(), consensus_common::Error> {
|
|
||||||
register_aura_inherent_data_provider(&self.inherent_data_providers, slot_duration)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_slot(
|
fn on_slot(
|
||||||
&self,
|
&self,
|
||||||
chain_head: B::Header,
|
chain_head: B::Header,
|
||||||
@@ -902,7 +894,7 @@ mod tests {
|
|||||||
&inherent_data_providers, slot_duration.get()
|
&inherent_data_providers, slot_duration.get()
|
||||||
).expect("Registers aura inherent data provider");
|
).expect("Registers aura inherent data provider");
|
||||||
|
|
||||||
let aura = start_aura::<_, _, _, _, _, sr25519::Pair, _, _, _, _>(
|
let aura = start_aura::<_, _, _, _, _, sr25519::Pair, _, _, _>(
|
||||||
slot_duration,
|
slot_duration,
|
||||||
Arc::new(key.clone().into()),
|
Arc::new(key.clone().into()),
|
||||||
client.clone(),
|
client.clone(),
|
||||||
@@ -910,7 +902,6 @@ mod tests {
|
|||||||
client,
|
client,
|
||||||
environ.clone(),
|
environ.clone(),
|
||||||
DummyOracle,
|
DummyOracle,
|
||||||
futures::empty(),
|
|
||||||
inherent_data_providers,
|
inherent_data_providers,
|
||||||
false,
|
false,
|
||||||
).expect("Starts aura");
|
).expect("Starts aura");
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ use futures::{Future, IntoFuture, future};
|
|||||||
use tokio::timer::Timeout;
|
use tokio::timer::Timeout;
|
||||||
use log::{error, warn, debug, info, trace};
|
use log::{error, warn, debug, info, trace};
|
||||||
|
|
||||||
use slots::{SlotWorker, SlotInfo, SlotCompatible, slot_now};
|
use slots::{SlotWorker, SlotData, SlotInfo, SlotCompatible, slot_now};
|
||||||
|
|
||||||
|
|
||||||
/// A slot duration. Create with `get_or_compute`.
|
/// A slot duration. Create with `get_or_compute`.
|
||||||
@@ -134,7 +134,7 @@ impl SlotCompatible for BabeSlotCompatible {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parameters for BABE.
|
/// Parameters for BABE.
|
||||||
pub struct BabeParams<C, E, I, SO, SC, OnExit> {
|
pub struct BabeParams<C, E, I, SO, SC> {
|
||||||
|
|
||||||
/// The configuration for BABE. Includes the slot duration, threshold, and
|
/// The configuration for BABE. Includes the slot duration, threshold, and
|
||||||
/// other parameters.
|
/// other parameters.
|
||||||
@@ -158,9 +158,6 @@ pub struct BabeParams<C, E, I, SO, SC, OnExit> {
|
|||||||
/// A sync oracle
|
/// A sync oracle
|
||||||
pub sync_oracle: SO,
|
pub sync_oracle: SO,
|
||||||
|
|
||||||
/// Exit callback.
|
|
||||||
pub on_exit: OnExit,
|
|
||||||
|
|
||||||
/// Providers for inherent data.
|
/// Providers for inherent data.
|
||||||
pub inherent_data_providers: InherentDataProviders,
|
pub inherent_data_providers: InherentDataProviders,
|
||||||
|
|
||||||
@@ -169,7 +166,7 @@ pub struct BabeParams<C, E, I, SO, SC, OnExit> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Start the babe worker. The returned future should be run in a tokio runtime.
|
/// Start the babe worker. The returned future should be run in a tokio runtime.
|
||||||
pub fn start_babe<B, C, SC, E, I, SO, Error, OnExit, H>(BabeParams {
|
pub fn start_babe<B, C, SC, E, I, SO, Error, H>(BabeParams {
|
||||||
config,
|
config,
|
||||||
local_key,
|
local_key,
|
||||||
client,
|
client,
|
||||||
@@ -177,10 +174,9 @@ pub fn start_babe<B, C, SC, E, I, SO, Error, OnExit, H>(BabeParams {
|
|||||||
block_import,
|
block_import,
|
||||||
env,
|
env,
|
||||||
sync_oracle,
|
sync_oracle,
|
||||||
on_exit,
|
|
||||||
inherent_data_providers,
|
inherent_data_providers,
|
||||||
force_authoring,
|
force_authoring,
|
||||||
}: BabeParams<C, E, I, SO, SC, OnExit>) -> Result<
|
}: BabeParams<C, E, I, SO, SC>) -> Result<
|
||||||
impl Future<Item=(), Error=()>,
|
impl Future<Item=(), Error=()>,
|
||||||
consensus_common::Error,
|
consensus_common::Error,
|
||||||
> where
|
> where
|
||||||
@@ -200,26 +196,24 @@ pub fn start_babe<B, C, SC, E, I, SO, Error, OnExit, H>(BabeParams {
|
|||||||
I: BlockImport<B> + Send + Sync + 'static,
|
I: BlockImport<B> + Send + Sync + 'static,
|
||||||
Error: std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
|
Error: std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
|
||||||
SO: SyncOracle + Send + Sync + Clone,
|
SO: SyncOracle + Send + Sync + Clone,
|
||||||
OnExit: Future<Item=(), Error=()>,
|
|
||||||
{
|
{
|
||||||
let worker = BabeWorker {
|
let worker = BabeWorker {
|
||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
block_import,
|
block_import,
|
||||||
env,
|
env,
|
||||||
local_key,
|
local_key,
|
||||||
inherent_data_providers: inherent_data_providers.clone(),
|
|
||||||
sync_oracle: sync_oracle.clone(),
|
sync_oracle: sync_oracle.clone(),
|
||||||
force_authoring,
|
force_authoring,
|
||||||
threshold: config.threshold(),
|
threshold: config.threshold(),
|
||||||
};
|
};
|
||||||
slots::start_slot_worker::<_, _, _, _, _, BabeSlotCompatible, _>(
|
register_babe_inherent_data_provider(&inherent_data_providers, config.0.slot_duration())?;
|
||||||
|
Ok(slots::start_slot_worker::<_, _, _, _, _, BabeSlotCompatible>(
|
||||||
config.0,
|
config.0,
|
||||||
select_chain,
|
select_chain,
|
||||||
Arc::new(worker),
|
worker,
|
||||||
sync_oracle,
|
sync_oracle,
|
||||||
on_exit,
|
|
||||||
inherent_data_providers
|
inherent_data_providers
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BabeWorker<C, E, I, SO> {
|
struct BabeWorker<C, E, I, SO> {
|
||||||
@@ -228,7 +222,6 @@ struct BabeWorker<C, E, I, SO> {
|
|||||||
env: Arc<E>,
|
env: Arc<E>,
|
||||||
local_key: Arc<sr25519::Pair>,
|
local_key: Arc<sr25519::Pair>,
|
||||||
sync_oracle: SO,
|
sync_oracle: SO,
|
||||||
inherent_data_providers: InherentDataProviders,
|
|
||||||
force_authoring: bool,
|
force_authoring: bool,
|
||||||
threshold: u64,
|
threshold: u64,
|
||||||
}
|
}
|
||||||
@@ -253,13 +246,6 @@ impl<Hash, H, B, C, E, I, Error, SO> SlotWorker<B> for BabeWorker<C, E, I, SO> w
|
|||||||
{
|
{
|
||||||
type OnSlot = Box<dyn Future<Item=(), Error=consensus_common::Error> + Send>;
|
type OnSlot = Box<dyn Future<Item=(), Error=consensus_common::Error> + Send>;
|
||||||
|
|
||||||
fn on_start(
|
|
||||||
&self,
|
|
||||||
slot_duration: u64
|
|
||||||
) -> Result<(), consensus_common::Error> {
|
|
||||||
register_babe_inherent_data_provider(&self.inherent_data_providers, slot_duration)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_slot(
|
fn on_slot(
|
||||||
&self,
|
&self,
|
||||||
chain_head: B::Header,
|
chain_head: B::Header,
|
||||||
@@ -985,7 +971,6 @@ mod tests {
|
|||||||
client,
|
client,
|
||||||
env: environ.clone(),
|
env: environ.clone(),
|
||||||
sync_oracle: DummyOracle,
|
sync_oracle: DummyOracle,
|
||||||
on_exit: futures::empty(),
|
|
||||||
inherent_data_providers,
|
inherent_data_providers,
|
||||||
force_authoring: false,
|
force_authoring: false,
|
||||||
}).expect("Starts babe");
|
}).expect("Starts babe");
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ use runtime_primitives::generic::BlockId;
|
|||||||
use runtime_primitives::traits::{ApiRef, Block, ProvideRuntimeApi};
|
use runtime_primitives::traits::{ApiRef, Block, ProvideRuntimeApi};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::sync::{mpsc, Arc};
|
use std::sync::mpsc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
/// A worker that should be invoked at every new slot.
|
/// A worker that should be invoked at every new slot.
|
||||||
@@ -51,7 +51,8 @@ pub trait SlotWorker<B: Block> {
|
|||||||
type OnSlot: IntoFuture<Item = (), Error = consensus_common::Error>;
|
type OnSlot: IntoFuture<Item = (), Error = consensus_common::Error>;
|
||||||
|
|
||||||
/// Called when the proposer starts.
|
/// Called when the proposer starts.
|
||||||
fn on_start(&self, slot_duration: u64) -> Result<(), consensus_common::Error>;
|
#[deprecated(note = "Not called. Please perform any initialization before calling start_slot_worker.")]
|
||||||
|
fn on_start(&self, _slot_duration: u64) -> Result<(), consensus_common::Error> { Ok(()) }
|
||||||
|
|
||||||
/// Called when a new slot is triggered.
|
/// Called when a new slot is triggered.
|
||||||
fn on_slot(&self, chain_head: B::Header, slot_info: SlotInfo) -> Self::OnSlot;
|
fn on_slot(&self, chain_head: B::Header, slot_info: SlotInfo) -> Self::OnSlot;
|
||||||
@@ -70,7 +71,7 @@ pub trait SlotCompatible {
|
|||||||
pub fn start_slot_worker_thread<B, C, W, SO, SC, T, OnExit>(
|
pub fn start_slot_worker_thread<B, C, W, SO, SC, T, OnExit>(
|
||||||
slot_duration: SlotDuration<T>,
|
slot_duration: SlotDuration<T>,
|
||||||
select_chain: C,
|
select_chain: C,
|
||||||
worker: Arc<W>,
|
worker: W,
|
||||||
sync_oracle: SO,
|
sync_oracle: SO,
|
||||||
on_exit: OnExit,
|
on_exit: OnExit,
|
||||||
inherent_data_providers: InherentDataProviders,
|
inherent_data_providers: InherentDataProviders,
|
||||||
@@ -97,29 +98,19 @@ where
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let slot_worker_future = match start_slot_worker::<_, _, _, T, _, SC, _>(
|
let slot_worker_future = start_slot_worker::<_, _, _, T, _, SC>(
|
||||||
slot_duration.clone(),
|
slot_duration.clone(),
|
||||||
select_chain,
|
select_chain,
|
||||||
worker,
|
worker,
|
||||||
sync_oracle,
|
sync_oracle,
|
||||||
on_exit,
|
|
||||||
inherent_data_providers,
|
inherent_data_providers,
|
||||||
) {
|
);
|
||||||
Ok(slot_worker_future) => {
|
|
||||||
result_sender
|
|
||||||
.send(Ok(()))
|
|
||||||
.expect("Receive is not dropped before receiving a result; qed");
|
|
||||||
slot_worker_future
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
result_sender
|
|
||||||
.send(Err(e))
|
|
||||||
.expect("Receive is not dropped before receiving a result; qed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let _ = runtime.block_on(slot_worker_future);
|
result_sender
|
||||||
|
.send(Ok(()))
|
||||||
|
.expect("Receive is not dropped before receiving a result; qed");
|
||||||
|
|
||||||
|
let _ = runtime.block_on(slot_worker_future.select(on_exit).map(|_| ()));
|
||||||
});
|
});
|
||||||
|
|
||||||
result_recv
|
result_recv
|
||||||
@@ -128,67 +119,58 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Start a new slot worker.
|
/// Start a new slot worker.
|
||||||
pub fn start_slot_worker<B, C, W, T, SO, SC, OnExit>(
|
///
|
||||||
|
/// Every time a new slot is triggered, `worker.on_slot` is called and the future it returns is
|
||||||
|
/// polled until completion, unless we are major syncing.
|
||||||
|
pub fn start_slot_worker<B, C, W, T, SO, SC>(
|
||||||
slot_duration: SlotDuration<T>,
|
slot_duration: SlotDuration<T>,
|
||||||
client: C,
|
client: C,
|
||||||
worker: Arc<W>,
|
worker: W,
|
||||||
sync_oracle: SO,
|
sync_oracle: SO,
|
||||||
on_exit: OnExit,
|
|
||||||
inherent_data_providers: InherentDataProviders,
|
inherent_data_providers: InherentDataProviders,
|
||||||
) -> Result<impl Future<Item = (), Error = ()>, consensus_common::Error>
|
) -> impl Future<Item = (), Error = ()>
|
||||||
where
|
where
|
||||||
B: Block,
|
B: Block,
|
||||||
C: SelectChain<B> + Clone,
|
C: SelectChain<B> + Clone,
|
||||||
W: SlotWorker<B>,
|
W: SlotWorker<B>,
|
||||||
SO: SyncOracle + Send + Clone,
|
SO: SyncOracle + Send + Clone,
|
||||||
SC: SlotCompatible,
|
SC: SlotCompatible,
|
||||||
OnExit: Future<Item = (), Error = ()>,
|
|
||||||
T: SlotData + Clone,
|
T: SlotData + Clone,
|
||||||
{
|
{
|
||||||
worker.on_start(slot_duration.slot_duration())?;
|
let SlotDuration(slot_duration) = slot_duration;
|
||||||
|
|
||||||
let make_authorship = move || {
|
// rather than use a timer interval, we schedule our waits ourselves
|
||||||
let client = client.clone();
|
let mut authorship = Slots::<SC>::new(slot_duration.slot_duration(), inherent_data_providers)
|
||||||
let worker = worker.clone();
|
.map_err(|e| debug!(target: "slots", "Faulty timer: {:?}", e))
|
||||||
let sync_oracle = sync_oracle.clone();
|
.for_each(move |slot_info| {
|
||||||
let SlotDuration(slot_duration) = slot_duration.clone();
|
// only propose when we are not syncing.
|
||||||
let inherent_data_providers = inherent_data_providers.clone();
|
if sync_oracle.is_major_syncing() {
|
||||||
|
debug!(target: "slots", "Skipping proposal slot due to sync.");
|
||||||
|
return Either::B(future::ok(()));
|
||||||
|
}
|
||||||
|
|
||||||
// rather than use a timer interval, we schedule our waits ourselves
|
let slot_num = slot_info.number;
|
||||||
Slots::<SC>::new(slot_duration.slot_duration(), inherent_data_providers)
|
let chain_head = match client.best_chain() {
|
||||||
.map_err(|e| debug!(target: "slots", "Faulty timer: {:?}", e))
|
Ok(x) => x,
|
||||||
.for_each(move |slot_info| {
|
Err(e) => {
|
||||||
let client = client.clone();
|
warn!(target: "slots", "Unable to author block in slot {}. \
|
||||||
let worker = worker.clone();
|
no best block header: {:?}", slot_num, e);
|
||||||
let sync_oracle = sync_oracle.clone();
|
|
||||||
|
|
||||||
// only propose when we are not syncing.
|
|
||||||
if sync_oracle.is_major_syncing() {
|
|
||||||
debug!(target: "slots", "Skipping proposal slot due to sync.");
|
|
||||||
return Either::B(future::ok(()));
|
return Either::B(future::ok(()));
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let slot_num = slot_info.number;
|
Either::A(worker.on_slot(chain_head, slot_info).into_future().map_err(
|
||||||
let chain_head = match client.best_chain() {
|
|e| warn!(target: "slots", "Encountered consensus error: {:?}", e),
|
||||||
Ok(x) => x,
|
))
|
||||||
Err(e) => {
|
});
|
||||||
warn!(target: "slots", "Unable to author block in slot {}. \
|
|
||||||
no best block header: {:?}", slot_num, e);
|
|
||||||
return Either::B(future::ok(()));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Either::A(worker.on_slot(chain_head, slot_info).into_future().map_err(
|
future::poll_fn(move ||
|
||||||
|e| warn!(target: "slots", "Encountered consensus error: {:?}", e),
|
loop {
|
||||||
))
|
let mut authorship = std::panic::AssertUnwindSafe(&mut authorship);
|
||||||
})
|
match std::panic::catch_unwind(move || authorship.poll()) {
|
||||||
};
|
Ok(Ok(Async::Ready(()))) =>
|
||||||
|
warn!(target: "slots", "Slots stream has terminated unexpectedly."),
|
||||||
let work = future::loop_fn((), move |()| {
|
Ok(Ok(Async::NotReady)) => break Ok(Async::NotReady),
|
||||||
let authorship_task = ::std::panic::AssertUnwindSafe(make_authorship());
|
|
||||||
authorship_task.catch_unwind().then(|res| {
|
|
||||||
match res {
|
|
||||||
Ok(Ok(())) => (),
|
|
||||||
Ok(Err(())) => warn!(target: "slots", "Authorship task terminated unexpectedly. Restarting"),
|
Ok(Err(())) => warn!(target: "slots", "Authorship task terminated unexpectedly. Restarting"),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if let Some(s) = e.downcast_ref::<&'static str>() {
|
if let Some(s) = e.downcast_ref::<&'static str>() {
|
||||||
@@ -198,12 +180,8 @@ where
|
|||||||
warn!(target: "slots", "Restarting authorship task");
|
warn!(target: "slots", "Restarting authorship task");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Ok(future::Loop::Continue(()))
|
)
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(work.select(on_exit).then(|_| Ok(())))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A header which has been checked
|
/// A header which has been checked
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use substrate_service::{
|
|||||||
};
|
};
|
||||||
use basic_authorship::ProposerFactory;
|
use basic_authorship::ProposerFactory;
|
||||||
use consensus::{import_queue, start_aura, AuraImportQueue, SlotDuration, NothingExtra};
|
use consensus::{import_queue, start_aura, AuraImportQueue, SlotDuration, NothingExtra};
|
||||||
|
use futures::prelude::*;
|
||||||
use substrate_client::{self as client, LongestChain};
|
use substrate_client::{self as client, LongestChain};
|
||||||
use primitives::{ed25519::Pair, Pair as PairT};
|
use primitives::{ed25519::Pair, Pair as PairT};
|
||||||
use inherents::InherentDataProviders;
|
use inherents::InherentDataProviders;
|
||||||
@@ -75,7 +76,7 @@ construct_service_factory! {
|
|||||||
let client = service.client();
|
let client = service.client();
|
||||||
let select_chain = service.select_chain()
|
let select_chain = service.select_chain()
|
||||||
.ok_or_else(|| ServiceError::SelectChainRequired)?;
|
.ok_or_else(|| ServiceError::SelectChainRequired)?;
|
||||||
executor.spawn(start_aura(
|
let aura = start_aura(
|
||||||
SlotDuration::get_or_compute(&*client)?,
|
SlotDuration::get_or_compute(&*client)?,
|
||||||
key.clone(),
|
key.clone(),
|
||||||
client.clone(),
|
client.clone(),
|
||||||
@@ -83,10 +84,10 @@ construct_service_factory! {
|
|||||||
client,
|
client,
|
||||||
proposer,
|
proposer,
|
||||||
service.network(),
|
service.network(),
|
||||||
service.on_exit(),
|
|
||||||
service.config.custom.inherent_data_providers.clone(),
|
service.config.custom.inherent_data_providers.clone(),
|
||||||
service.config.force_authoring,
|
service.config.force_authoring,
|
||||||
)?);
|
)?;
|
||||||
|
executor.spawn(aura.select(service.on_exit()).then(|_| Ok(())));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(service)
|
Ok(service)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ use consensus::{import_queue, start_aura, AuraImportQueue, SlotDuration, Nothing
|
|||||||
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
|
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
|
||||||
use node_executor;
|
use node_executor;
|
||||||
use primitives::{Pair as PairT, ed25519};
|
use primitives::{Pair as PairT, ed25519};
|
||||||
|
use futures::prelude::*;
|
||||||
use node_primitives::Block;
|
use node_primitives::Block;
|
||||||
use node_runtime::{GenesisConfig, RuntimeApi};
|
use node_runtime::{GenesisConfig, RuntimeApi};
|
||||||
use substrate_service::{
|
use substrate_service::{
|
||||||
@@ -92,7 +93,7 @@ construct_service_factory! {
|
|||||||
let client = service.client();
|
let client = service.client();
|
||||||
let select_chain = service.select_chain()
|
let select_chain = service.select_chain()
|
||||||
.ok_or(ServiceError::SelectChainRequired)?;
|
.ok_or(ServiceError::SelectChainRequired)?;
|
||||||
executor.spawn(start_aura(
|
let aura = start_aura(
|
||||||
SlotDuration::get_or_compute(&*client)?,
|
SlotDuration::get_or_compute(&*client)?,
|
||||||
key.clone(),
|
key.clone(),
|
||||||
client,
|
client,
|
||||||
@@ -100,10 +101,10 @@ construct_service_factory! {
|
|||||||
block_import.clone(),
|
block_import.clone(),
|
||||||
proposer,
|
proposer,
|
||||||
service.network(),
|
service.network(),
|
||||||
service.on_exit(),
|
|
||||||
service.config.custom.inherent_data_providers.clone(),
|
service.config.custom.inherent_data_providers.clone(),
|
||||||
service.config.force_authoring,
|
service.config.force_authoring,
|
||||||
)?);
|
)?;
|
||||||
|
executor.spawn(aura.select(service.on_exit()).then(|_| Ok(())));
|
||||||
|
|
||||||
info!("Running Grandpa session as Authority {}", key.public());
|
info!("Running Grandpa session as Authority {}", key.public());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user