mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 09:31:02 +00:00
refactor overseer into proc-macro based pattern (#2962)
This commit is contained in:
committed by
GitHub
parent
2510bfc5d7
commit
3c9104daff
+346
-1717
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,195 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Prometheus metrics related to the overseer and its channels.
|
||||
|
||||
use super::*;
|
||||
use polkadot_node_metrics::metrics::{self, prometheus};
|
||||
|
||||
/// Overseer Prometheus metrics.
|
||||
#[derive(Clone)]
|
||||
struct MetricsInner {
|
||||
activated_heads_total: prometheus::Counter<prometheus::U64>,
|
||||
deactivated_heads_total: prometheus::Counter<prometheus::U64>,
|
||||
messages_relayed_total: prometheus::Counter<prometheus::U64>,
|
||||
to_subsystem_bounded_sent: prometheus::GaugeVec<prometheus::U64>,
|
||||
to_subsystem_bounded_received: prometheus::GaugeVec<prometheus::U64>,
|
||||
to_subsystem_unbounded_sent: prometheus::GaugeVec<prometheus::U64>,
|
||||
to_subsystem_unbounded_received: prometheus::GaugeVec<prometheus::U64>,
|
||||
signals_sent: prometheus::GaugeVec<prometheus::U64>,
|
||||
signals_received: prometheus::GaugeVec<prometheus::U64>,
|
||||
}
|
||||
|
||||
|
||||
/// A sharable metrics type for usage with the overseer.
|
||||
#[derive(Default, Clone)]
|
||||
pub struct Metrics(Option<MetricsInner>);
|
||||
|
||||
impl Metrics {
|
||||
pub(crate) fn on_head_activated(&self) {
|
||||
if let Some(metrics) = &self.0 {
|
||||
metrics.activated_heads_total.inc();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn on_head_deactivated(&self) {
|
||||
if let Some(metrics) = &self.0 {
|
||||
metrics.deactivated_heads_total.inc();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn on_message_relayed(&self) {
|
||||
if let Some(metrics) = &self.0 {
|
||||
metrics.messages_relayed_total.inc();
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn channel_fill_level_snapshot(
|
||||
&self,
|
||||
collection: impl IntoIterator<Item=(&'static str, SubsystemMeterReadouts)>,
|
||||
) {
|
||||
if let Some(metrics) = &self.0 {
|
||||
collection.into_iter().for_each(
|
||||
|(name, readouts): (_, SubsystemMeterReadouts)| {
|
||||
metrics.to_subsystem_bounded_sent.with_label_values(&[name])
|
||||
.set(readouts.bounded.sent as u64);
|
||||
|
||||
metrics.to_subsystem_bounded_received.with_label_values(&[name])
|
||||
.set(readouts.bounded.received as u64);
|
||||
|
||||
metrics.to_subsystem_unbounded_sent.with_label_values(&[name])
|
||||
.set(readouts.unbounded.sent as u64);
|
||||
|
||||
metrics.to_subsystem_unbounded_received.with_label_values(&[name])
|
||||
.set(readouts.unbounded.received as u64);
|
||||
|
||||
metrics.signals_sent.with_label_values(&[name])
|
||||
.set(readouts.signals.sent as u64);
|
||||
|
||||
metrics.signals_received.with_label_values(&[name])
|
||||
.set(readouts.signals.received as u64);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl metrics::Metrics for Metrics {
|
||||
fn try_register(registry: &prometheus::Registry) -> Result<Self, prometheus::PrometheusError> {
|
||||
let metrics = MetricsInner {
|
||||
activated_heads_total: prometheus::register(
|
||||
prometheus::Counter::new(
|
||||
"parachain_activated_heads_total",
|
||||
"Number of activated heads."
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
deactivated_heads_total: prometheus::register(
|
||||
prometheus::Counter::new(
|
||||
"parachain_deactivated_heads_total",
|
||||
"Number of deactivated heads."
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
messages_relayed_total: prometheus::register(
|
||||
prometheus::Counter::new(
|
||||
"parachain_messages_relayed_total",
|
||||
"Number of messages relayed by Overseer."
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
to_subsystem_bounded_sent: prometheus::register(
|
||||
prometheus::GaugeVec::<prometheus::U64>::new(
|
||||
prometheus::Opts::new(
|
||||
"parachain_subsystem_bounded_sent",
|
||||
"Number of elements sent to subsystems' bounded queues",
|
||||
),
|
||||
&[
|
||||
"subsystem_name",
|
||||
],
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
to_subsystem_bounded_received: prometheus::register(
|
||||
prometheus::GaugeVec::<prometheus::U64>::new(
|
||||
prometheus::Opts::new(
|
||||
"parachain_subsystem_bounded_received",
|
||||
"Number of elements received by subsystems' bounded queues",
|
||||
),
|
||||
&[
|
||||
"subsystem_name",
|
||||
],
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
to_subsystem_unbounded_sent: prometheus::register(
|
||||
prometheus::GaugeVec::<prometheus::U64>::new(
|
||||
prometheus::Opts::new(
|
||||
"parachain_subsystem_unbounded_sent",
|
||||
"Number of elements sent to subsystems' unbounded queues",
|
||||
),
|
||||
&[
|
||||
"subsystem_name",
|
||||
],
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
to_subsystem_unbounded_received: prometheus::register(
|
||||
prometheus::GaugeVec::<prometheus::U64>::new(
|
||||
prometheus::Opts::new(
|
||||
"parachain_subsystem_unbounded_received",
|
||||
"Number of elements received by subsystems' unbounded queues",
|
||||
),
|
||||
&[
|
||||
"subsystem_name",
|
||||
],
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
signals_sent: prometheus::register(
|
||||
prometheus::GaugeVec::<prometheus::U64>::new(
|
||||
prometheus::Opts::new(
|
||||
"parachain_overseer_signals_sent",
|
||||
"Number of signals sent by overseer to subsystems",
|
||||
),
|
||||
&[
|
||||
"subsystem_name",
|
||||
],
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
signals_received: prometheus::register(
|
||||
prometheus::GaugeVec::<prometheus::U64>::new(
|
||||
prometheus::Opts::new(
|
||||
"parachain_overseer_signals_received",
|
||||
"Number of signals received by subsystems from overseer",
|
||||
),
|
||||
&[
|
||||
"subsystem_name",
|
||||
],
|
||||
)?,
|
||||
registry,
|
||||
)?,
|
||||
};
|
||||
Ok(Metrics(Some(metrics)))
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Metrics {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str("Metrics {{...}}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Legacy way of defining subsystems.
|
||||
//!
|
||||
//! In the future, everything should be set up using the generated
|
||||
//! overeseer builder pattern instead.
|
||||
|
||||
use polkadot_node_subsystem_types::errors::SubsystemError;
|
||||
use polkadot_overseer_gen::{
|
||||
MapSubsystem, SubsystemContext,
|
||||
Subsystem,
|
||||
SpawnedSubsystem,
|
||||
FromOverseer,
|
||||
};
|
||||
use polkadot_overseer_all_subsystems_gen::AllSubsystemsGen;
|
||||
use crate::OverseerSignal;
|
||||
use crate::AllMessages;
|
||||
|
||||
/// A dummy subsystem that implements [`Subsystem`] for all
|
||||
/// types of messages. Used for tests or as a placeholder.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct DummySubsystem;
|
||||
|
||||
impl<Context> Subsystem<Context, SubsystemError> for DummySubsystem
|
||||
where
|
||||
Context: SubsystemContext<Signal=OverseerSignal, Error=SubsystemError, AllMessages=AllMessages>,
|
||||
{
|
||||
fn start(self, mut ctx: Context) -> SpawnedSubsystem<SubsystemError> {
|
||||
let future = Box::pin(async move {
|
||||
loop {
|
||||
match ctx.recv().await {
|
||||
Err(_) => return Ok(()),
|
||||
Ok(FromOverseer::Signal(OverseerSignal::Conclude)) => return Ok(()),
|
||||
Ok(overseer_msg) => {
|
||||
tracing::debug!(
|
||||
target: "dummy-subsystem",
|
||||
"Discarding a message sent from overseer {:?}",
|
||||
overseer_msg
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
SpawnedSubsystem {
|
||||
name: "dummy-subsystem",
|
||||
future,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// This struct is passed as an argument to create a new instance of an [`Overseer`].
|
||||
///
|
||||
/// As any entity that satisfies the interface may act as a [`Subsystem`] this allows
|
||||
/// mocking in the test code:
|
||||
///
|
||||
/// Each [`Subsystem`] is supposed to implement some interface that is generic over
|
||||
/// message type that is specific to this [`Subsystem`]. At the moment not all
|
||||
/// subsystems are implemented and the rest can be mocked with the [`DummySubsystem`].
|
||||
#[derive(Debug, Clone, AllSubsystemsGen)]
|
||||
pub struct AllSubsystems<
|
||||
CV = (), CB = (), SD = (), AD = (), AR = (), BS = (), BD = (), P = (),
|
||||
RA = (), AS = (), NB = (), CA = (), CG = (), CP = (), ApD = (), ApV = (),
|
||||
GS = (),
|
||||
> {
|
||||
/// A candidate validation subsystem.
|
||||
pub candidate_validation: CV,
|
||||
/// A candidate backing subsystem.
|
||||
pub candidate_backing: CB,
|
||||
/// A statement distribution subsystem.
|
||||
pub statement_distribution: SD,
|
||||
/// An availability distribution subsystem.
|
||||
pub availability_distribution: AD,
|
||||
/// An availability recovery subsystem.
|
||||
pub availability_recovery: AR,
|
||||
/// A bitfield signing subsystem.
|
||||
pub bitfield_signing: BS,
|
||||
/// A bitfield distribution subsystem.
|
||||
pub bitfield_distribution: BD,
|
||||
/// A provisioner subsystem.
|
||||
pub provisioner: P,
|
||||
/// A runtime API subsystem.
|
||||
pub runtime_api: RA,
|
||||
/// An availability store subsystem.
|
||||
pub availability_store: AS,
|
||||
/// A network bridge subsystem.
|
||||
pub network_bridge: NB,
|
||||
/// A Chain API subsystem.
|
||||
pub chain_api: CA,
|
||||
/// A Collation Generation subsystem.
|
||||
pub collation_generation: CG,
|
||||
/// A Collator Protocol subsystem.
|
||||
pub collator_protocol: CP,
|
||||
/// An Approval Distribution subsystem.
|
||||
pub approval_distribution: ApD,
|
||||
/// An Approval Voting subsystem.
|
||||
pub approval_voting: ApV,
|
||||
/// A Connection Request Issuer subsystem.
|
||||
pub gossip_support: GS,
|
||||
}
|
||||
|
||||
impl<CV, CB, SD, AD, AR, BS, BD, P, RA, AS, NB, CA, CG, CP, ApD, ApV, GS>
|
||||
AllSubsystems<CV, CB, SD, AD, AR, BS, BD, P, RA, AS, NB, CA, CG, CP, ApD, ApV, GS>
|
||||
{
|
||||
/// Create a new instance of [`AllSubsystems`].
|
||||
///
|
||||
/// Each subsystem is set to [`DummySystem`].
|
||||
///
|
||||
///# Note
|
||||
///
|
||||
/// Because of a bug in rustc it is required that when calling this function,
|
||||
/// you provide a "random" type for the first generic parameter:
|
||||
///
|
||||
/// ```
|
||||
/// polkadot_overseer::AllSubsystems::<()>::dummy();
|
||||
/// ```
|
||||
pub fn dummy() -> AllSubsystems<
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
> {
|
||||
AllSubsystems {
|
||||
candidate_validation: DummySubsystem,
|
||||
candidate_backing: DummySubsystem,
|
||||
statement_distribution: DummySubsystem,
|
||||
availability_distribution: DummySubsystem,
|
||||
availability_recovery: DummySubsystem,
|
||||
bitfield_signing: DummySubsystem,
|
||||
bitfield_distribution: DummySubsystem,
|
||||
provisioner: DummySubsystem,
|
||||
runtime_api: DummySubsystem,
|
||||
availability_store: DummySubsystem,
|
||||
network_bridge: DummySubsystem,
|
||||
chain_api: DummySubsystem,
|
||||
collation_generation: DummySubsystem,
|
||||
collator_protocol: DummySubsystem,
|
||||
approval_distribution: DummySubsystem,
|
||||
approval_voting: DummySubsystem,
|
||||
gossip_support: DummySubsystem,
|
||||
}
|
||||
}
|
||||
|
||||
/// Reference every indidviudal subsystem.
|
||||
pub fn as_ref(&self) -> AllSubsystems<&'_ CV, &'_ CB, &'_ SD, &'_ AD, &'_ AR, &'_ BS, &'_ BD, &'_ P, &'_ RA, &'_ AS, &'_ NB, &'_ CA, &'_ CG, &'_ CP, &'_ ApD, &'_ ApV, &'_ GS> {
|
||||
AllSubsystems {
|
||||
candidate_validation: &self.candidate_validation,
|
||||
candidate_backing: &self.candidate_backing,
|
||||
statement_distribution: &self.statement_distribution,
|
||||
availability_distribution: &self.availability_distribution,
|
||||
availability_recovery: &self.availability_recovery,
|
||||
bitfield_signing: &self.bitfield_signing,
|
||||
bitfield_distribution: &self.bitfield_distribution,
|
||||
provisioner: &self.provisioner,
|
||||
runtime_api: &self.runtime_api,
|
||||
availability_store: &self.availability_store,
|
||||
network_bridge: &self.network_bridge,
|
||||
chain_api: &self.chain_api,
|
||||
collation_generation: &self.collation_generation,
|
||||
collator_protocol: &self.collator_protocol,
|
||||
approval_distribution: &self.approval_distribution,
|
||||
approval_voting: &self.approval_voting,
|
||||
gossip_support: &self.gossip_support,
|
||||
}
|
||||
}
|
||||
|
||||
/// Map each subsystem.
|
||||
pub fn map_subsystems<Mapper>(self, mapper: Mapper)
|
||||
-> AllSubsystems<
|
||||
<Mapper as MapSubsystem<CV>>::Output,
|
||||
<Mapper as MapSubsystem<CB>>::Output,
|
||||
<Mapper as MapSubsystem<SD>>::Output,
|
||||
<Mapper as MapSubsystem<AD>>::Output,
|
||||
<Mapper as MapSubsystem<AR>>::Output,
|
||||
<Mapper as MapSubsystem<BS>>::Output,
|
||||
<Mapper as MapSubsystem<BD>>::Output,
|
||||
<Mapper as MapSubsystem<P>>::Output,
|
||||
<Mapper as MapSubsystem<RA>>::Output,
|
||||
<Mapper as MapSubsystem<AS>>::Output,
|
||||
<Mapper as MapSubsystem<NB>>::Output,
|
||||
<Mapper as MapSubsystem<CA>>::Output,
|
||||
<Mapper as MapSubsystem<CG>>::Output,
|
||||
<Mapper as MapSubsystem<CP>>::Output,
|
||||
<Mapper as MapSubsystem<ApD>>::Output,
|
||||
<Mapper as MapSubsystem<ApV>>::Output,
|
||||
<Mapper as MapSubsystem<GS>>::Output,
|
||||
>
|
||||
where
|
||||
Mapper: MapSubsystem<CV>,
|
||||
Mapper: MapSubsystem<CB>,
|
||||
Mapper: MapSubsystem<SD>,
|
||||
Mapper: MapSubsystem<AD>,
|
||||
Mapper: MapSubsystem<AR>,
|
||||
Mapper: MapSubsystem<BS>,
|
||||
Mapper: MapSubsystem<BD>,
|
||||
Mapper: MapSubsystem<P>,
|
||||
Mapper: MapSubsystem<RA>,
|
||||
Mapper: MapSubsystem<AS>,
|
||||
Mapper: MapSubsystem<NB>,
|
||||
Mapper: MapSubsystem<CA>,
|
||||
Mapper: MapSubsystem<CG>,
|
||||
Mapper: MapSubsystem<CP>,
|
||||
Mapper: MapSubsystem<ApD>,
|
||||
Mapper: MapSubsystem<ApV>,
|
||||
Mapper: MapSubsystem<GS>,
|
||||
{
|
||||
AllSubsystems {
|
||||
candidate_validation: <Mapper as MapSubsystem<CV>>::map_subsystem(&mapper, self.candidate_validation),
|
||||
candidate_backing: <Mapper as MapSubsystem<CB>>::map_subsystem(&mapper, self.candidate_backing),
|
||||
statement_distribution: <Mapper as MapSubsystem<SD>>::map_subsystem(&mapper, self.statement_distribution),
|
||||
availability_distribution: <Mapper as MapSubsystem<AD>>::map_subsystem(&mapper, self.availability_distribution),
|
||||
availability_recovery: <Mapper as MapSubsystem<AR>>::map_subsystem(&mapper, self.availability_recovery),
|
||||
bitfield_signing: <Mapper as MapSubsystem<BS>>::map_subsystem(&mapper, self.bitfield_signing),
|
||||
bitfield_distribution: <Mapper as MapSubsystem<BD>>::map_subsystem(&mapper, self.bitfield_distribution),
|
||||
provisioner: <Mapper as MapSubsystem<P>>::map_subsystem(&mapper, self.provisioner),
|
||||
runtime_api: <Mapper as MapSubsystem<RA>>::map_subsystem(&mapper, self.runtime_api),
|
||||
availability_store: <Mapper as MapSubsystem<AS>>::map_subsystem(&mapper, self.availability_store),
|
||||
network_bridge: <Mapper as MapSubsystem<NB>>::map_subsystem(&mapper, self.network_bridge),
|
||||
chain_api: <Mapper as MapSubsystem<CA>>::map_subsystem(&mapper, self.chain_api),
|
||||
collation_generation: <Mapper as MapSubsystem<CG>>::map_subsystem(&mapper, self.collation_generation),
|
||||
collator_protocol: <Mapper as MapSubsystem<CP>>::map_subsystem(&mapper, self.collator_protocol),
|
||||
approval_distribution: <Mapper as MapSubsystem<ApD>>::map_subsystem(&mapper, self.approval_distribution),
|
||||
approval_voting: <Mapper as MapSubsystem<ApV>>::map_subsystem(&mapper, self.approval_voting),
|
||||
gossip_support: <Mapper as MapSubsystem<GS>>::map_subsystem(&mapper, self.gossip_support),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,23 +16,44 @@
|
||||
|
||||
use std::sync::atomic;
|
||||
use std::collections::HashMap;
|
||||
use futures::{executor, pin_mut, select, FutureExt, pending};
|
||||
use std::task::{Poll};
|
||||
use futures::{executor, pin_mut, select, FutureExt, pending, poll, stream};
|
||||
|
||||
use polkadot_primitives::v1::{CollatorPair, CandidateHash};
|
||||
use polkadot_subsystem::{messages::RuntimeApiRequest, messages::NetworkBridgeEvent, jaeger};
|
||||
use polkadot_node_primitives::{CollationResult, CollationGenerationConfig, PoV, BlockData};
|
||||
use polkadot_node_network_protocol::{PeerId, UnifiedReputationChange};
|
||||
use polkadot_node_subsystem_util::metered;
|
||||
use polkadot_node_subsystem_types::{
|
||||
ActivatedLeaf, LeafStatus,
|
||||
messages::{
|
||||
RuntimeApiRequest,
|
||||
NetworkBridgeEvent,
|
||||
},
|
||||
jaeger,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
self as overseer,
|
||||
Overseer,
|
||||
HeadSupportsParachains,
|
||||
gen::Delay,
|
||||
|
||||
};
|
||||
use metered_channel as metered;
|
||||
|
||||
use sp_core::crypto::Pair as _;
|
||||
use assert_matches::assert_matches;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
||||
type SpawnedSubsystem = crate::gen::SpawnedSubsystem<SubsystemError>;
|
||||
|
||||
struct TestSubsystem1(metered::MeteredSender<usize>);
|
||||
|
||||
impl<C> Subsystem<C> for TestSubsystem1
|
||||
where C: SubsystemContext<Message=CandidateValidationMessage>
|
||||
impl<C> overseer::Subsystem<C, SubsystemError> for TestSubsystem1
|
||||
where
|
||||
C: overseer::SubsystemContext<Message=CandidateValidationMessage,Signal=OverseerSignal,AllMessages=AllMessages>,
|
||||
|
||||
{
|
||||
fn start(self, mut ctx: C) -> SpawnedSubsystem {
|
||||
let mut sender = self.0;
|
||||
@@ -59,8 +80,9 @@ impl<C> Subsystem<C> for TestSubsystem1
|
||||
|
||||
struct TestSubsystem2(metered::MeteredSender<usize>);
|
||||
|
||||
impl<C> Subsystem<C> for TestSubsystem2
|
||||
where C: SubsystemContext<Message=CandidateBackingMessage>
|
||||
impl<C> overseer::Subsystem<C, SubsystemError> for TestSubsystem2
|
||||
where
|
||||
C: overseer::SubsystemContext<Message=CandidateBackingMessage,Signal=OverseerSignal,AllMessages=AllMessages>,
|
||||
{
|
||||
fn start(self, mut ctx: C) -> SpawnedSubsystem {
|
||||
let sender = self.0.clone();
|
||||
@@ -73,14 +95,12 @@ impl<C> Subsystem<C> for TestSubsystem2
|
||||
if c < 10 {
|
||||
let (tx, _) = oneshot::channel();
|
||||
ctx.send_message(
|
||||
AllMessages::CandidateValidation(
|
||||
CandidateValidationMessage::ValidateFromChainState(
|
||||
Default::default(),
|
||||
PoV {
|
||||
block_data: BlockData(Vec::new()),
|
||||
}.into(),
|
||||
tx,
|
||||
)
|
||||
CandidateValidationMessage::ValidateFromChainState(
|
||||
Default::default(),
|
||||
PoV {
|
||||
block_data: BlockData(Vec::new()),
|
||||
}.into(),
|
||||
tx,
|
||||
)
|
||||
).await;
|
||||
c += 1;
|
||||
@@ -107,8 +127,9 @@ impl<C> Subsystem<C> for TestSubsystem2
|
||||
|
||||
struct ReturnOnStart;
|
||||
|
||||
impl<C> Subsystem<C> for ReturnOnStart
|
||||
where C: SubsystemContext<Message=CandidateBackingMessage>
|
||||
impl<C> overseer::Subsystem<C, SubsystemError> for ReturnOnStart
|
||||
where
|
||||
C: overseer::SubsystemContext<Message=CandidateBackingMessage,Signal=OverseerSignal,AllMessages=AllMessages>,
|
||||
{
|
||||
fn start(self, mut _ctx: C) -> SpawnedSubsystem {
|
||||
SpawnedSubsystem {
|
||||
@@ -283,8 +304,9 @@ fn overseer_ends_on_subsystem_exit() {
|
||||
|
||||
struct TestSubsystem5(metered::MeteredSender<OverseerSignal>);
|
||||
|
||||
impl<C> Subsystem<C> for TestSubsystem5
|
||||
where C: SubsystemContext<Message=CandidateValidationMessage>
|
||||
impl<C> overseer::Subsystem<C, SubsystemError> for TestSubsystem5
|
||||
where
|
||||
C: overseer::SubsystemContext<Message=CandidateValidationMessage,Signal=OverseerSignal,AllMessages=AllMessages>,
|
||||
{
|
||||
fn start(self, mut ctx: C) -> SpawnedSubsystem {
|
||||
let mut sender = self.0.clone();
|
||||
@@ -314,8 +336,9 @@ impl<C> Subsystem<C> for TestSubsystem5
|
||||
|
||||
struct TestSubsystem6(metered::MeteredSender<OverseerSignal>);
|
||||
|
||||
impl<C> Subsystem<C> for TestSubsystem6
|
||||
where C: SubsystemContext<Message=CandidateBackingMessage>
|
||||
impl<C> Subsystem<C, SubsystemError> for TestSubsystem6
|
||||
where
|
||||
C: overseer::SubsystemContext<Message=CandidateBackingMessage,Signal=OverseerSignal,AllMessages=AllMessages>,
|
||||
{
|
||||
fn start(self, mut ctx: C) -> SpawnedSubsystem {
|
||||
let mut sender = self.0.clone();
|
||||
@@ -396,15 +419,15 @@ fn overseer_start_stop_works() {
|
||||
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
|
||||
hash: first_block_hash,
|
||||
number: 1,
|
||||
status: LeafStatus::Fresh,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
status: LeafStatus::Fresh,
|
||||
})),
|
||||
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
|
||||
activated: [ActivatedLeaf {
|
||||
hash: second_block_hash,
|
||||
number: 2,
|
||||
status: LeafStatus::Fresh,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
status: LeafStatus::Fresh,
|
||||
}].as_ref().into(),
|
||||
deactivated: [first_block_hash].as_ref().into(),
|
||||
}),
|
||||
@@ -412,8 +435,8 @@ fn overseer_start_stop_works() {
|
||||
activated: [ActivatedLeaf {
|
||||
hash: third_block_hash,
|
||||
number: 3,
|
||||
status: LeafStatus::Fresh,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
status: LeafStatus::Fresh,
|
||||
}].as_ref().into(),
|
||||
deactivated: [second_block_hash].as_ref().into(),
|
||||
}),
|
||||
@@ -507,14 +530,14 @@ fn overseer_finalize_works() {
|
||||
ActivatedLeaf {
|
||||
hash: first_block_hash,
|
||||
number: 1,
|
||||
status: LeafStatus::Fresh,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
status: LeafStatus::Fresh,
|
||||
},
|
||||
ActivatedLeaf {
|
||||
hash: second_block_hash,
|
||||
number: 2,
|
||||
status: LeafStatus::Fresh,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
status: LeafStatus::Fresh,
|
||||
},
|
||||
].as_ref().into(),
|
||||
..Default::default()
|
||||
@@ -606,8 +629,8 @@ fn do_not_send_empty_leaves_update_on_block_finalization() {
|
||||
ActivatedLeaf {
|
||||
hash: imported_block.hash,
|
||||
number: imported_block.number,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
status: LeafStatus::Fresh,
|
||||
span: Arc::new(jaeger::Span::Disabled)
|
||||
}
|
||||
].as_ref().into(),
|
||||
..Default::default()
|
||||
@@ -641,146 +664,6 @@ fn do_not_send_empty_leaves_update_on_block_finalization() {
|
||||
});
|
||||
}
|
||||
|
||||
// Tests that duplicate leaves have an attached 'Stale' status.
|
||||
#[test]
|
||||
fn overseer_stale_detection() {
|
||||
let spawner = sp_core::testing::TaskExecutor::new();
|
||||
|
||||
executor::block_on(async move {
|
||||
let a1_hash = [1; 32].into();
|
||||
let b1_hash = [2; 32].into();
|
||||
|
||||
let a2_hash = [3; 32].into();
|
||||
let b2_hash = [4; 32].into();
|
||||
|
||||
let first_block = BlockInfo {
|
||||
hash: a1_hash,
|
||||
parent_hash: [0; 32].into(),
|
||||
number: 1,
|
||||
};
|
||||
let second_block = BlockInfo {
|
||||
hash: b1_hash,
|
||||
parent_hash: [0; 32].into(),
|
||||
number: 1,
|
||||
};
|
||||
|
||||
let third_block = BlockInfo {
|
||||
hash: a2_hash,
|
||||
parent_hash: a1_hash,
|
||||
number: 2,
|
||||
};
|
||||
|
||||
let fourth_block = BlockInfo {
|
||||
hash: b2_hash,
|
||||
parent_hash: b1_hash,
|
||||
number: 2,
|
||||
};
|
||||
|
||||
let (tx_5, mut rx_5) = metered::channel(64);
|
||||
let (tx_6, mut rx_6) = metered::channel(64);
|
||||
let all_subsystems = AllSubsystems::<()>::dummy()
|
||||
.replace_candidate_validation(TestSubsystem5(tx_5))
|
||||
.replace_candidate_backing(TestSubsystem6(tx_6));
|
||||
|
||||
let (overseer, mut handler) = Overseer::new(
|
||||
vec![first_block.clone()],
|
||||
all_subsystems,
|
||||
None,
|
||||
MockSupportsParachains,
|
||||
spawner,
|
||||
).unwrap();
|
||||
|
||||
let overseer_fut = overseer.run().fuse();
|
||||
pin_mut!(overseer_fut);
|
||||
|
||||
let mut ss5_results = Vec::new();
|
||||
let mut ss6_results = Vec::new();
|
||||
|
||||
handler.block_imported(second_block.clone()).await;
|
||||
|
||||
// import the second block of each chain to deactivate the heads.
|
||||
handler.block_imported(third_block).await;
|
||||
handler.block_imported(fourth_block).await;
|
||||
|
||||
// import the first blocks again (emulating a revert)
|
||||
handler.block_imported(first_block).await;
|
||||
handler.block_imported(second_block).await;
|
||||
|
||||
let expected_heartbeats = vec![
|
||||
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
|
||||
hash: a1_hash,
|
||||
number: 1,
|
||||
status: LeafStatus::Fresh,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
})),
|
||||
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
|
||||
hash: b1_hash,
|
||||
number: 1,
|
||||
status: LeafStatus::Fresh,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
})),
|
||||
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
|
||||
activated: [ActivatedLeaf {
|
||||
hash: a2_hash,
|
||||
number: 2,
|
||||
status: LeafStatus::Fresh,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
}].as_ref().into(),
|
||||
deactivated: [a1_hash].as_ref().into(),
|
||||
}),
|
||||
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
|
||||
activated: [ActivatedLeaf {
|
||||
hash: b2_hash,
|
||||
number: 2,
|
||||
status: LeafStatus::Fresh,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
}].as_ref().into(),
|
||||
deactivated: [b1_hash].as_ref().into(),
|
||||
}),
|
||||
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
|
||||
hash: a1_hash,
|
||||
number: 1,
|
||||
status: LeafStatus::Stale,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
})),
|
||||
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
|
||||
hash: b1_hash,
|
||||
number: 1,
|
||||
status: LeafStatus::Stale,
|
||||
span: Arc::new(jaeger::Span::Disabled),
|
||||
})),
|
||||
];
|
||||
|
||||
loop {
|
||||
select! {
|
||||
res = overseer_fut => {
|
||||
assert!(res.is_ok());
|
||||
break;
|
||||
},
|
||||
res = rx_5.next() => {
|
||||
if let Some(res) = res {
|
||||
ss5_results.push(res);
|
||||
}
|
||||
}
|
||||
res = rx_6.next() => {
|
||||
if let Some(res) = res {
|
||||
ss6_results.push(res);
|
||||
}
|
||||
}
|
||||
complete => break,
|
||||
}
|
||||
|
||||
if ss5_results.len() == expected_heartbeats.len() &&
|
||||
ss6_results.len() == expected_heartbeats.len() {
|
||||
handler.stop().await;
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(ss5_results, expected_heartbeats);
|
||||
assert_eq!(ss6_results, expected_heartbeats);
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct CounterSubsystem {
|
||||
stop_signals_received: Arc<atomic::AtomicUsize>,
|
||||
@@ -802,10 +685,10 @@ impl CounterSubsystem {
|
||||
}
|
||||
}
|
||||
|
||||
impl<C, M> Subsystem<C> for CounterSubsystem
|
||||
where
|
||||
C: SubsystemContext<Message=M>,
|
||||
M: Send,
|
||||
impl<C, M> Subsystem<C, SubsystemError> for CounterSubsystem
|
||||
where
|
||||
C: overseer::SubsystemContext<Message=M,Signal=OverseerSignal,AllMessages=AllMessages>,
|
||||
M: Send,
|
||||
{
|
||||
fn start(self, mut ctx: C) -> SpawnedSubsystem {
|
||||
SpawnedSubsystem {
|
||||
@@ -1112,7 +995,7 @@ fn context_holds_onto_message_until_enough_signals_received() {
|
||||
let (unbounded_tx, unbounded_rx) = metered::unbounded();
|
||||
let (to_overseer_tx, _to_overseer_rx) = metered::unbounded();
|
||||
|
||||
let mut ctx = OverseerSubsystemContext::<()>::new_unmetered(
|
||||
let mut ctx = OverseerSubsystemContext::new(
|
||||
signal_rx,
|
||||
stream::select(bounded_rx, unbounded_rx),
|
||||
channels_out,
|
||||
|
||||
Reference in New Issue
Block a user