mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-20 17:25:41 +00:00
overseer becomes orchestra (#5542)
* rename overseer-gen to orchestra Also drop `gum` and use `tracing`. * make orchestra compile as standalone * introduce Spawner trait to split from sp_core Finalizes the independence of orchestra from polkadot-overseer * slip of the pen * other fixins * remove unused import * Update node/overseer/orchestra/proc-macro/src/impl_builder.rs Co-authored-by: Vsevolod Stakhov <vsevolod.stakhov@parity.io> * Update node/overseer/orchestra/proc-macro/src/impl_builder.rs Co-authored-by: Vsevolod Stakhov <vsevolod.stakhov@parity.io> * orchestra everywhere * leaky data * Bump scale-info from 2.1.1 to 2.1.2 (#5552) Bumps [scale-info](https://github.com/paritytech/scale-info) from 2.1.1 to 2.1.2. - [Release notes](https://github.com/paritytech/scale-info/releases) - [Changelog](https://github.com/paritytech/scale-info/blob/master/CHANGELOG.md) - [Commits](https://github.com/paritytech/scale-info/compare/v2.1.1...v2.1.2) --- updated-dependencies: - dependency-name: scale-info dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add missing markdown code block delimiter (#5555) * bitfield-signing: remove util::jobs usage (#5523) * Switch to pooling copy-on-write instantiation strategy for WASM (companion for Substrate#11232) (#5337) * Switch to pooling copy-on-write instantiation strategy for WASM * Fix compilation of `polkadot-test-service` * Update comments * Move `max_memory_size` to `Semantics` * Rename `WasmInstantiationStrategy` to `WasmtimeInstantiationStrategy` * Update a safety comment * update lockfile for {"substrate"} Co-authored-by: parity-processbot <> * Fix build Co-authored-by: Vsevolod Stakhov <vsevolod.stakhov@parity.io> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Malte Kliemann <mail@maltekliemann.com> Co-authored-by: Chris Sosnin <48099298+slumber@users.noreply.github.com> Co-authored-by: Koute <koute@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
d9eff4ecd4
commit
450ca2baca
@@ -15,10 +15,11 @@ polkadot-node-primitives = { path = "../primitives" }
|
||||
polkadot-node-subsystem-types = { path = "../subsystem-types" }
|
||||
polkadot-node-metrics = { path = "../metrics" }
|
||||
polkadot-primitives = { path = "../../primitives" }
|
||||
polkadot-overseer-gen = { path = "./overseer-gen" }
|
||||
orchestra = { path = "./orchestra" }
|
||||
gum = { package = "tracing-gum", path = "../gum" }
|
||||
lru = "0.7"
|
||||
parity-util-mem = { version = "0.11.0", default-features = false }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
[dev-dependencies]
|
||||
metered-channel = { path = "../metered-channel" }
|
||||
@@ -30,4 +31,4 @@ test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../pri
|
||||
|
||||
[features]
|
||||
default = []
|
||||
expand = ["polkadot-overseer-gen/expand"]
|
||||
expand = ["orchestra/expand"]
|
||||
|
||||
@@ -28,7 +28,7 @@ use polkadot_node_subsystem_types::messages::CandidateValidationMessage;
|
||||
use polkadot_overseer::{
|
||||
self as overseer,
|
||||
dummy::dummy_overseer_builder,
|
||||
gen::{FromOverseer, SpawnedSubsystem},
|
||||
gen::{FromOrchestra, SpawnedSubsystem},
|
||||
HeadSupportsParachains, SubsystemError,
|
||||
};
|
||||
use polkadot_primitives::v2::{CandidateReceipt, Hash};
|
||||
@@ -50,7 +50,7 @@ impl Subsystem1 {
|
||||
'louy: loop {
|
||||
match ctx.try_recv().await {
|
||||
Ok(Some(msg)) => {
|
||||
if let FromOverseer::Communication { msg } = msg {
|
||||
if let FromOrchestra::Communication { msg } = msg {
|
||||
gum::info!("msg {:?}", msg);
|
||||
}
|
||||
continue 'louy
|
||||
|
||||
+7
-9
@@ -1,30 +1,28 @@
|
||||
[package]
|
||||
name = "polkadot-overseer-gen"
|
||||
name = "orchestra"
|
||||
version = "0.9.22"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2021"
|
||||
description = "Generate an overseer including builder pattern and message wrapper from a single struct."
|
||||
description = "Generate an orchestra of subsystems from a single struct."
|
||||
license = "MIT OR Apache-2.0"
|
||||
autoexamples = false
|
||||
|
||||
[dependencies]
|
||||
gum = { package = "tracing-gum", path = "../../gum" }
|
||||
tracing = "0.1.34"
|
||||
futures = "0.3"
|
||||
async-trait = "0.1"
|
||||
thiserror = "1"
|
||||
metered = { package = "metered-channel", path = "../../metered-channel" }
|
||||
polkadot-overseer-gen-proc-macro = { path = "./proc-macro" }
|
||||
polkadot-node-network-protocol = { path = "../../network/protocol"}
|
||||
# trait SpawnNamed
|
||||
polkadot-node-primitives = { path = "../../primitives" }
|
||||
orchestra-proc-macro = { path = "./proc-macro" }
|
||||
futures-timer = "3.0.2"
|
||||
pin-project = "1.0"
|
||||
dyn-clonable = "0.9"
|
||||
|
||||
[dev-dependencies]
|
||||
trybuild = "1.0.61"
|
||||
rustversion = "1.0.6"
|
||||
|
||||
|
||||
|
||||
[[example]]
|
||||
name = "duo"
|
||||
crate-type = ["bin"]
|
||||
@@ -35,4 +33,4 @@ crate-type = ["bin"]
|
||||
|
||||
[features]
|
||||
default = []
|
||||
expand = ["polkadot-overseer-gen-proc-macro/expand"]
|
||||
expand = ["orchestra-proc-macro/expand"]
|
||||
+19
-19
@@ -1,6 +1,7 @@
|
||||
# overseer pattern
|
||||
# orchestra
|
||||
|
||||
The overseer pattern is a partial actor pattern
|
||||
The orchestra pattern is a partial actor pattern, with a global orchestrator regarding
|
||||
relevant work items.
|
||||
|
||||
## proc-macro
|
||||
|
||||
@@ -9,8 +10,8 @@ where at it's core it creates and spawns a set of subsystems, which are purely
|
||||
declarative.
|
||||
|
||||
```rust
|
||||
#[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)]
|
||||
pub struct Overseer {
|
||||
#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)]
|
||||
pub struct Opera {
|
||||
#[subsystem(MsgA, sends: [MsgB])]
|
||||
sub_a: AwesomeSubSysA,
|
||||
|
||||
@@ -23,24 +24,25 @@ declarative.
|
||||
being consumed by that particular subsystem. Each of those subsystems is required to implement the subsystem
|
||||
trait with the correct trait bounds. Commonly this is achieved
|
||||
by using `#[subsystem]` and `#[contextbounds]` macro.
|
||||
* `#[contextbounds(Foo, error=Yikes, prefix=wherethetraitsat)]` can applied to `impl`-blocks and `fn`-blocks. It will add additional trait bounds for the generic `Context` with `Context: FooContextTrait` for `<Context as FooContextTrait>::Sender: FooSenderTrait` besides a few more. Note that `Foo` here references the name of the subsystem as declared in `#[overlord(..)]` macro.
|
||||
* `#[contextbounds(Foo, error=Yikes, prefix=wherethetraitsat)]` can applied to `impl`-blocks and `fn`-blocks. It will add additional trait bounds for the generic `Context` with `Context: FooContextTrait` for `<Context as FooContextTrait>::Sender: FooSenderTrait` besides a few more. Note that `Foo` here references the name of the subsystem as declared in `#[orchestra(..)]` macro.
|
||||
* `#[subsystem(Foo, error=Yikes, prefix=wherethetraitsat)]` is a extension to the above, implementing `trait Subsystem<Context, Yikes>`.
|
||||
* `error=` tells the overseer to use the user provided
|
||||
* `error=` tells the orchestra to use the user provided
|
||||
error type, if not provided a builtin one is used. Note that this is the one error type used throughout all calls, so make sure it does impl `From<E>` for all other error types `E` that are relevant to your application.
|
||||
* `event=` declares an external event type, that injects certain events
|
||||
into the overseer, without participating in the subsystem pattern.
|
||||
* `signal=` defines a signal type to be used for the overseer. This is a shared "clock" for all subsystems.
|
||||
into the orchestra, without participating in the subsystem pattern.
|
||||
* `signal=` defines a signal type to be used for the orchestra. This is a shared "tick" or "clock" for all subsystems.
|
||||
* `gen=` defines a wrapping `enum` type that is used to wrap all messages that can be consumed by _any_ subsystem.
|
||||
|
||||
```rust
|
||||
/// Execution context, always requred.
|
||||
/// Execution context, always required.
|
||||
pub struct DummyCtx;
|
||||
|
||||
/// Task spawner, always required.
|
||||
/// Task spawner, always required
|
||||
/// and must implement `trait orchestra::Spawner`.
|
||||
pub struct DummySpawner;
|
||||
|
||||
fn main() {
|
||||
let _overseer = Overseer::builder()
|
||||
let _orchestra = Opera::builder()
|
||||
.sub_a(AwesomeSubSysA::default())
|
||||
.sub_b(AwesomeSubSysB::default())
|
||||
.spawner(DummySpawner)
|
||||
@@ -48,7 +50,7 @@ into the overseer, without participating in the subsystem pattern.
|
||||
}
|
||||
```
|
||||
|
||||
In the shown `main`, the overseer is created by means of a generated, compile time erroring
|
||||
In the shown `main`, the orchestra is created by means of a generated, compile time erroring
|
||||
builder pattern.
|
||||
|
||||
The builder requires all subsystems, baggage fields (additional struct data) and spawner to be
|
||||
@@ -61,11 +63,11 @@ for the specific struct field. Therefore, if you see a compile time error that b
|
||||
not set prior to the `build` call.
|
||||
|
||||
To exclude subsystems from such a check, one can set `wip` attribute on some subsystem that
|
||||
is not ready to be included in the Overseer:
|
||||
is not ready to be included in the Orchestra:
|
||||
|
||||
```rust
|
||||
#[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)]
|
||||
pub struct Overseer {
|
||||
#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)]
|
||||
pub struct Opera {
|
||||
#[subsystem(MsgA, sends: MsgB)]
|
||||
sub_a: AwesomeSubSysA,
|
||||
|
||||
@@ -78,13 +80,11 @@ Baggage fields can be initialized more than one time, however, it is not true fo
|
||||
subsystems must be initialized only once (another compile time check) or be _replaced_ by
|
||||
a special setter like method `replace_<subsystem>`.
|
||||
|
||||
A task spawner and subsystem context are required to be defined with `SpawnNamed` and respectively `SubsystemContext` implemented.
|
||||
A task spawner and subsystem context are required to be defined with `Spawner` and respectively `SubsystemContext` implemented.
|
||||
|
||||
## Debugging
|
||||
|
||||
As always, debugging is notoriously annoying with bugged proc-macros.
|
||||
|
||||
Therefore [`expander`](https://github.com/drahnr/expander) is employed to yield better
|
||||
error messages. Enable with `--feature=polkadot-overseer-gen/expand` or
|
||||
`--feature=polkadot-overseer/expand` from the root of the project or
|
||||
make `"expand"` part of the default feature set.
|
||||
error messages. Enable with `--feature=orchestra/expand`.
|
||||
+4
-4
@@ -10,12 +10,12 @@ Previously, there was no way to limit and hence reason about a subset of subsyst
|
||||
|
||||
## Decision
|
||||
|
||||
Annotate the `#[overlord]` inner `#[subsystem(..)]` annotation
|
||||
Annotate the `#[orchestra]` inner `#[subsystem(..)]` annotation
|
||||
with an aditional set of outgoing messages and enforce this via more fine grained trait bounds on the `Sender` and `<Context>::Sender` bounds.
|
||||
|
||||
## Consequences
|
||||
|
||||
* A graph will be spawn for every compilation under the `OUT_DIR` of the crate where `#[overlord]` is specified.
|
||||
* Each subsystem has a consuming message which is often referred to as generic `M` (no change on that, is as before), but now we have trait `AssociateOutgoing { type OutgoingMessages = ..; }` which defines an outgoing helper `enum` that is generated with an ident constructed as `${Subsystem}OutgoingMessages` where `${Subsystem}` is the subsystem identifier as used in the overseer declaration. `${Subsystem}OutgoingMessages` is used throughout everywhere to constrain the outgoing messages (commonly referred to as `OutgoingMessage` generic bounded by `${Subsystem}OutgoingMessages: From<OutgoingMessage>` or `::OutgoingMessages: From`. It's what allows the construction of the graph and compile time verification.
|
||||
* `${Subsystem}SenderTrait` and `${Subsystem}ContextTrait` are accumulation traits or wrapper traits, that combine over all annotated M or `OutgoingMessages` from the overseer declaration or their respective outgoing types. It is usage convenience and assures consistency within a subsystem while also maintaining a single source of truth for which messages can be sent by a particular subsystem. Note that this is sidestepped for the test subsystem, which may consume `gen=AllMessages`, the global message wrapper type.
|
||||
* A graph will be spawn for every compilation under the `OUT_DIR` of the crate where `#[orchestra]` is specified.
|
||||
* Each subsystem has a consuming message which is often referred to as generic `M` (no change on that, is as before), but now we have trait `AssociateOutgoing { type OutgoingMessages = ..; }` which defines an outgoing helper `enum` that is generated with an ident constructed as `${Subsystem}OutgoingMessages` where `${Subsystem}` is the subsystem identifier as used in the orchestra declaration. `${Subsystem}OutgoingMessages` is used throughout everywhere to constrain the outgoing messages (commonly referred to as `OutgoingMessage` generic bounded by `${Subsystem}OutgoingMessages: From<OutgoingMessage>` or `::OutgoingMessages: From`. It's what allows the construction of the graph and compile time verification.
|
||||
* `${Subsystem}SenderTrait` and `${Subsystem}ContextTrait` are accumulation traits or wrapper traits, that combine over all annotated M or `OutgoingMessages` from the orchestra declaration or their respective outgoing types. It is usage convenience and assures consistency within a subsystem while also maintaining a single source of truth for which messages can be sent by a particular subsystem. Note that this is sidestepped for the test subsystem, which may consume `gen=AllMessages`, the global message wrapper type.
|
||||
* `Job`-based subsystems, being on their way out, are patched, but they now are generic over the `Sender` type, leaking that type.
|
||||
+12
-12
@@ -1,8 +1,8 @@
|
||||
#![allow(dead_code)] // overseer events are not used
|
||||
#![allow(dead_code)] // orchestra events are not used
|
||||
|
||||
//! A dummy to be used with cargo expand
|
||||
|
||||
use polkadot_overseer_gen::{self as overseer, SpawnNamed, *};
|
||||
use orchestra::{self as orchestra, Spawner, *};
|
||||
use std::collections::HashMap;
|
||||
mod misc;
|
||||
|
||||
@@ -12,7 +12,7 @@ pub use self::misc::*;
|
||||
#[derive(Default)]
|
||||
pub struct AwesomeSubSys;
|
||||
|
||||
#[overseer::subsystem(Awesome, error=Yikes)]
|
||||
#[orchestra::subsystem(Awesome, error=Yikes)]
|
||||
impl<Context> AwesomeSubSys {
|
||||
fn start(self, mut ctx: Context) -> SpawnedSubsystem<Yikes> {
|
||||
let mut sender = ctx.sender().clone();
|
||||
@@ -30,7 +30,7 @@ impl<Context> AwesomeSubSys {
|
||||
#[derive(Default)]
|
||||
pub struct Fortified;
|
||||
|
||||
#[overseer::subsystem(GoblinTower, error=Yikes)]
|
||||
#[orchestra::subsystem(GoblinTower, error=Yikes)]
|
||||
impl<Context> Fortified {
|
||||
fn start(self, mut ctx: Context) -> SpawnedSubsystem<Yikes> {
|
||||
let mut sender = ctx.sender().clone();
|
||||
@@ -45,7 +45,7 @@ impl<Context> Fortified {
|
||||
}
|
||||
}
|
||||
|
||||
#[overlord(signal=SigSigSig, event=EvX, error=Yikes, gen=AllMessages)]
|
||||
#[orchestra(signal=SigSigSig, event=EvX, error=Yikes, gen=AllMessages)]
|
||||
struct Duo<T> {
|
||||
#[subsystem(consumes: MsgStrukt, sends: [Plinko])]
|
||||
sub0: Awesome,
|
||||
@@ -62,7 +62,7 @@ fn main() {
|
||||
use futures::{executor, pin_mut};
|
||||
|
||||
executor::block_on(async move {
|
||||
let (overseer, _handle): (Duo<_, f64>, _) = Duo::builder()
|
||||
let (orchestra, _handle): (Duo<_, f64>, _) = Duo::builder()
|
||||
.sub0(AwesomeSubSys::default())
|
||||
.plinkos(Fortified::default())
|
||||
.i_like_pi(::std::f64::consts::PI)
|
||||
@@ -72,18 +72,18 @@ fn main() {
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(overseer.i_like_pi.floor() as i8, 3);
|
||||
assert_eq!(overseer.i_like_generic.floor() as i8, 42);
|
||||
assert_eq!(overseer.i_like_hash.len() as i8, 0);
|
||||
assert_eq!(orchestra.i_like_pi.floor() as i8, 3);
|
||||
assert_eq!(orchestra.i_like_generic.floor() as i8, 42);
|
||||
assert_eq!(orchestra.i_like_hash.len() as i8, 0);
|
||||
|
||||
let overseer_fut = overseer
|
||||
let orchestra_fut = orchestra
|
||||
.running_subsystems
|
||||
.into_future()
|
||||
.timeout(std::time::Duration::from_millis(300))
|
||||
.fuse();
|
||||
|
||||
pin_mut!(overseer_fut);
|
||||
pin_mut!(orchestra_fut);
|
||||
|
||||
overseer_fut.await
|
||||
orchestra_fut.await
|
||||
});
|
||||
}
|
||||
+6
-6
@@ -1,4 +1,4 @@
|
||||
use polkadot_overseer_gen::{SpawnNamed, *};
|
||||
use orchestra::{Spawner, *};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum SigSigSig {
|
||||
@@ -9,7 +9,7 @@ pub enum SigSigSig {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DummySpawner;
|
||||
|
||||
impl SpawnNamed for DummySpawner {
|
||||
impl Spawner for DummySpawner {
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
task_name: &'static str,
|
||||
@@ -50,14 +50,14 @@ impl std::fmt::Display for Yikes {
|
||||
|
||||
impl std::error::Error for Yikes {}
|
||||
|
||||
impl From<polkadot_overseer_gen::OverseerError> for Yikes {
|
||||
fn from(_: polkadot_overseer_gen::OverseerError) -> Yikes {
|
||||
impl From<orchestra::OrchestraError> for Yikes {
|
||||
fn from(_: orchestra::OrchestraError) -> Yikes {
|
||||
Yikes
|
||||
}
|
||||
}
|
||||
|
||||
impl From<polkadot_overseer_gen::mpsc::SendError> for Yikes {
|
||||
fn from(_: polkadot_overseer_gen::mpsc::SendError) -> Yikes {
|
||||
impl From<orchestra::mpsc::SendError> for Yikes {
|
||||
fn from(_: orchestra::mpsc::SendError) -> Yikes {
|
||||
Yikes
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -1,13 +1,13 @@
|
||||
#![allow(dead_code)] // overseer events are not used
|
||||
#![allow(dead_code)] // orchestra events are not used
|
||||
|
||||
//! A minimal demo to be used with cargo expand.
|
||||
|
||||
use polkadot_overseer_gen::{self as overseer, SpawnNamed, *};
|
||||
use orchestra::{self as orchestra, Spawner, *};
|
||||
mod misc;
|
||||
|
||||
pub use self::misc::*;
|
||||
|
||||
#[overlord(signal=SigSigSig, event=EvX, error=Yikes, gen=AllMessages)]
|
||||
#[orchestra(signal=SigSigSig, event=EvX, error=Yikes, gen=AllMessages)]
|
||||
struct Solo<T> {
|
||||
#[subsystem(consumes: Plinko, sends: [MsgStrukt])]
|
||||
goblin_tower: GoblinTower,
|
||||
@@ -16,7 +16,7 @@ struct Solo<T> {
|
||||
#[derive(Default)]
|
||||
pub struct Fortified;
|
||||
|
||||
#[overseer::subsystem(GoblinTower, error=Yikes)]
|
||||
#[orchestra::subsystem(GoblinTower, error=Yikes)]
|
||||
impl<Context> Fortified {
|
||||
fn start(self, mut ctx: Context) -> SpawnedSubsystem<Yikes> {
|
||||
let mut sender = ctx.sender().clone();
|
||||
@@ -35,20 +35,20 @@ fn main() {
|
||||
use futures::{executor, pin_mut};
|
||||
|
||||
executor::block_on(async move {
|
||||
let (overseer, _handle): (Solo<_>, _) = Solo::builder()
|
||||
let (orchestra, _handle): (Solo<_>, _) = Solo::builder()
|
||||
.goblin_tower(Fortified::default())
|
||||
.spawner(DummySpawner)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let overseer_fut = overseer
|
||||
let orchestra_fut = orchestra
|
||||
.running_subsystems
|
||||
.into_future()
|
||||
.timeout(std::time::Duration::from_millis(300))
|
||||
.fuse();
|
||||
|
||||
pin_mut!(overseer_fut);
|
||||
pin_mut!(orchestra_fut);
|
||||
|
||||
overseer_fut.await
|
||||
orchestra_fut.await
|
||||
});
|
||||
}
|
||||
+8
-7
@@ -1,9 +1,10 @@
|
||||
[package]
|
||||
name = "polkadot-overseer-gen-proc-macro"
|
||||
name = "orchestra-proc-macro"
|
||||
version = "0.9.22"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2021"
|
||||
description = "Generate an overseer including builder pattern and message wrapper from a single annotated struct definition."
|
||||
description = "Generate an orchestra of subsystems from a single annotated struct definition."
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
@@ -20,16 +21,16 @@ expander = { version = "0.0.6", default-features = false }
|
||||
petgraph = "0.6.0"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_matches = "1.5.0"
|
||||
polkadot-overseer-gen = { path = "../" }
|
||||
assert_matches = "1.5"
|
||||
orchestra = { path = "../" }
|
||||
thiserror = "1"
|
||||
gum = { package = "tracing-gum", path = "../../../gum" }
|
||||
tracing = "0.1"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
# write the expanded version to a `overlord-expansion.[a-f0-9]{10}.rs`
|
||||
# write the expanded version to a `orchestra-expansion.[a-f0-9]{10}.rs`
|
||||
# in the `OUT_DIR` as defined by `cargo` for the `expander` crate.
|
||||
expand = []
|
||||
# Create directional message consuming / outgoing graph.
|
||||
# Generates: `${OUT_DIR}/${overseer|lowercase}-subsystem-messaging.dot`
|
||||
# Generates: `${OUT_DIR}/${orchestra|lowercase}-subsystem-messaging.dot`
|
||||
graph = []
|
||||
+47
-47
@@ -26,16 +26,16 @@ fn recollect_without_idx<T: Clone>(x: &[T], idx: usize) -> Vec<T> {
|
||||
v
|
||||
}
|
||||
|
||||
/// Implement a builder pattern for the `Overseer`-type,
|
||||
/// which acts as the gateway to constructing the overseer.
|
||||
/// Implement a builder pattern for the `Orchestra`-type,
|
||||
/// which acts as the gateway to constructing the orchestra.
|
||||
///
|
||||
/// Elements tagged with `wip` are not covered here.
|
||||
pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
let overseer_name = info.overseer_name.clone();
|
||||
let builder = format_ident!("{}Builder", overseer_name);
|
||||
let handle = format_ident!("{}Handle", overseer_name);
|
||||
let connector = format_ident!("{}Connector", overseer_name);
|
||||
let subsystem_ctx_name = format_ident!("{}SubsystemContext", overseer_name);
|
||||
pub(crate) fn impl_builder(info: &OrchestraInfo) -> proc_macro2::TokenStream {
|
||||
let orchestra_name = info.orchestra_name.clone();
|
||||
let builder = format_ident!("{}Builder", orchestra_name);
|
||||
let handle = format_ident!("{}Handle", orchestra_name);
|
||||
let connector = format_ident!("{}Connector", orchestra_name);
|
||||
let subsystem_ctx_name = format_ident!("{}SubsystemContext", orchestra_name);
|
||||
|
||||
let subsystem_name = &info.subsystem_names_without_wip();
|
||||
let subsystem_generics = &info.subsystem_generic_types();
|
||||
@@ -83,7 +83,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
|
||||
// Helpers to use within quote! macros
|
||||
let spawner_where_clause: syn::TypeParam = parse_quote! {
|
||||
S: #support_crate ::SpawnNamed + Send
|
||||
S: #support_crate ::Spawner
|
||||
};
|
||||
|
||||
// Field names and real types
|
||||
@@ -305,7 +305,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
|
||||
let event = &info.extern_event_ty;
|
||||
let initialized_builder = format_ident!("Initialized{}", builder);
|
||||
// The direct generics as expected by the `Overseer<_,_,..>`, without states
|
||||
// The direct generics as expected by the `Orchestra<_,_,..>`, without states
|
||||
let initialized_builder_generics = quote! {
|
||||
S, #( #baggage_generic_ty, )* #( #subsystem_generics, )*
|
||||
};
|
||||
@@ -336,7 +336,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
/// Convenience alias.
|
||||
type SubsystemInitFn<T> = Box<dyn FnOnce(#handle) -> ::std::result::Result<T, #error_ty> >;
|
||||
|
||||
/// Type for the initialized field of the overseer builder
|
||||
/// Type for the initialized field of the orchestra builder
|
||||
pub enum Init<T> {
|
||||
/// Defer initialization to a point where the `handle` is available.
|
||||
Fn(SubsystemInitFn<T>),
|
||||
@@ -344,7 +344,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
/// Also used for baggage fields
|
||||
Value(T),
|
||||
}
|
||||
/// Type marker for the uninitialized field of the overseer builder.
|
||||
/// Type marker for the uninitialized field of the orchestra builder.
|
||||
/// `PhantomData` is used for type hinting when creating uninitialized
|
||||
/// builder, e.g. to avoid specifying the generics when instantiating
|
||||
/// the `FooBuilder` when calling `Foo::builder()`
|
||||
@@ -352,10 +352,10 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
pub struct Missing<T>(::core::marker::PhantomData<T>);
|
||||
|
||||
/// Trait used to mark fields status in a builder
|
||||
trait OverseerFieldState<T> {}
|
||||
trait OrchestraFieldState<T> {}
|
||||
|
||||
impl<T> OverseerFieldState<T> for Init<T> {}
|
||||
impl<T> OverseerFieldState<T> for Missing<T> {}
|
||||
impl<T> OrchestraFieldState<T> for Init<T> {}
|
||||
impl<T> OrchestraFieldState<T> for Missing<T> {}
|
||||
|
||||
impl<T> ::std::default::Default for Missing<T> {
|
||||
fn default() -> Self {
|
||||
@@ -363,11 +363,11 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S #(, #baggage_generic_ty )*> #overseer_name <S #(, #baggage_generic_ty)*>
|
||||
impl<S #(, #baggage_generic_ty )*> #orchestra_name <S #(, #baggage_generic_ty)*>
|
||||
where
|
||||
#spawner_where_clause,
|
||||
{
|
||||
/// Create a new overseer utilizing the builder.
|
||||
/// Create a new orchestra utilizing the builder.
|
||||
pub fn builder< #( #subsystem_generics),* >() ->
|
||||
#builder<Missing<S> #(, Missing< #field_type > )* >
|
||||
where
|
||||
@@ -379,7 +379,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
};
|
||||
|
||||
ts.extend(quote! {
|
||||
/// Handle for an overseer.
|
||||
/// Handle for an orchestra.
|
||||
pub type #handle = #support_crate ::metered::MeteredSender< #event >;
|
||||
|
||||
/// External connector.
|
||||
@@ -390,16 +390,16 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
///
|
||||
/// For subsystems, use the `_with` variants of the builder.
|
||||
handle: #handle,
|
||||
/// The side consumed by the `spawned` side of the overseer pattern.
|
||||
/// The side consumed by the `spawned` side of the orchestra pattern.
|
||||
consumer: #support_crate ::metered::MeteredReceiver < #event >,
|
||||
}
|
||||
|
||||
impl #connector {
|
||||
/// Obtain access to the overseer handle.
|
||||
/// Obtain access to the orchestra handle.
|
||||
pub fn as_handle_mut(&mut self) -> &mut #handle {
|
||||
&mut self.handle
|
||||
}
|
||||
/// Obtain access to the overseer handle.
|
||||
/// Obtain access to the orchestra handle.
|
||||
pub fn as_handle(&self) -> &#handle {
|
||||
&self.handle
|
||||
}
|
||||
@@ -440,7 +440,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
)*
|
||||
spawner: InitStateSpawner,
|
||||
// user provided runtime overrides,
|
||||
// if `None`, the `overlord(message_capacity=123,..)` is used
|
||||
// if `None`, the `orchestra(message_capacity=123,..)` is used
|
||||
// or the default value.
|
||||
channel_capacity: Option<usize>,
|
||||
signal_capacity: Option<usize>,
|
||||
@@ -455,7 +455,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
// explicitly assure the required traits are implemented
|
||||
fn trait_from_must_be_implemented<E>()
|
||||
where
|
||||
E: std::error::Error + Send + Sync + 'static + From<#support_crate ::OverseerError>
|
||||
E: ::std::error::Error + Send + Sync + 'static + From<#support_crate ::OrchestraError>
|
||||
{}
|
||||
|
||||
trait_from_must_be_implemented::< #error_ty >();
|
||||
@@ -530,7 +530,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
ts.extend(quote! {
|
||||
/// Type used to represent a builder where all fields are initialized and the overseer could be constructed.
|
||||
/// Type used to represent a builder where all fields are initialized and the orchestra could be constructed.
|
||||
pub type #initialized_builder<#initialized_builder_generics> = #builder<Init<S>, #( Init<#field_type>, )*>;
|
||||
|
||||
// A builder specialization where all fields are set
|
||||
@@ -539,18 +539,18 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
#spawner_where_clause,
|
||||
#builder_where_clause
|
||||
{
|
||||
/// Complete the construction and create the overseer type.
|
||||
/// Complete the construction and create the orchestra type.
|
||||
pub fn build(self)
|
||||
-> ::std::result::Result<(#overseer_name<S, #( #baggage_generic_ty, )*>, #handle), #error_ty> {
|
||||
-> ::std::result::Result<(#orchestra_name<S, #( #baggage_generic_ty, )*>, #handle), #error_ty> {
|
||||
let connector = #connector ::with_event_capacity(
|
||||
self.signal_capacity.unwrap_or(SIGNAL_CHANNEL_CAPACITY)
|
||||
);
|
||||
self.build_with_connector(connector)
|
||||
}
|
||||
|
||||
/// Complete the construction and create the overseer type based on an existing `connector`.
|
||||
/// Complete the construction and create the orchestra type based on an existing `connector`.
|
||||
pub fn build_with_connector(self, connector: #connector)
|
||||
-> ::std::result::Result<(#overseer_name<S, #( #baggage_generic_ty, )*>, #handle), #error_ty>
|
||||
-> ::std::result::Result<(#orchestra_name<S, #( #baggage_generic_ty, )*>, #handle), #error_ty>
|
||||
{
|
||||
let #connector {
|
||||
handle: events_tx,
|
||||
@@ -559,8 +559,8 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
|
||||
let handle = events_tx.clone();
|
||||
|
||||
let (to_overseer_tx, to_overseer_rx) = #support_crate ::metered::unbounded::<
|
||||
ToOverseer
|
||||
let (to_orchestra_tx, to_orchestra_rx) = #support_crate ::metered::unbounded::<
|
||||
ToOrchestra
|
||||
>();
|
||||
|
||||
#(
|
||||
@@ -618,11 +618,11 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
signal_rx,
|
||||
message_rx,
|
||||
channels_out.clone(),
|
||||
to_overseer_tx.clone(),
|
||||
to_orchestra_tx.clone(),
|
||||
#subsystem_name_str_literal
|
||||
);
|
||||
|
||||
let #subsystem_name: OverseenSubsystem< #consumes > =
|
||||
let #subsystem_name: OrchestratedSubsystem< #consumes > =
|
||||
spawn::<_,_, #blocking, _, _, _>(
|
||||
&mut spawner,
|
||||
#channel_name_tx,
|
||||
@@ -637,8 +637,8 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
|
||||
use #support_crate ::StreamExt;
|
||||
|
||||
let to_overseer_rx = to_overseer_rx.fuse();
|
||||
let overseer = #overseer_name {
|
||||
let to_orchestra_rx = to_orchestra_rx.fuse();
|
||||
let orchestra = #orchestra_name {
|
||||
#(
|
||||
#subsystem_name,
|
||||
)*
|
||||
@@ -653,10 +653,10 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
spawner,
|
||||
running_subsystems,
|
||||
events_rx,
|
||||
to_overseer_rx,
|
||||
to_orchestra_rx,
|
||||
};
|
||||
|
||||
Ok((overseer, handle))
|
||||
Ok((orchestra, handle))
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -667,7 +667,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
ts
|
||||
}
|
||||
|
||||
pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
pub(crate) fn impl_task_kind(info: &OrchestraInfo) -> proc_macro2::TokenStream {
|
||||
let signal = &info.extern_signal_ty;
|
||||
let error_ty = &info.extern_error_ty;
|
||||
let support_crate = info.support_crate_name();
|
||||
@@ -676,13 +676,13 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
/// Task kind to launch.
|
||||
pub trait TaskKind {
|
||||
/// Spawn a task, it depends on the implementer if this is blocking or not.
|
||||
fn launch_task<S: SpawnNamed>(spawner: &mut S, task_name: &'static str, subsystem_name: &'static str, future: BoxFuture<'static, ()>);
|
||||
fn launch_task<S: Spawner>(spawner: &mut S, task_name: &'static str, subsystem_name: &'static str, future: BoxFuture<'static, ()>);
|
||||
}
|
||||
|
||||
#[allow(missing_docs)]
|
||||
struct Regular;
|
||||
impl TaskKind for Regular {
|
||||
fn launch_task<S: SpawnNamed>(spawner: &mut S, task_name: &'static str, subsystem_name: &'static str, future: BoxFuture<'static, ()>) {
|
||||
fn launch_task<S: Spawner>(spawner: &mut S, task_name: &'static str, subsystem_name: &'static str, future: BoxFuture<'static, ()>) {
|
||||
spawner.spawn(task_name, Some(subsystem_name), future)
|
||||
}
|
||||
}
|
||||
@@ -690,7 +690,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
#[allow(missing_docs)]
|
||||
struct Blocking;
|
||||
impl TaskKind for Blocking {
|
||||
fn launch_task<S: SpawnNamed>(spawner: &mut S, task_name: &'static str, subsystem_name: &'static str, future: BoxFuture<'static, ()>) {
|
||||
fn launch_task<S: Spawner>(spawner: &mut S, task_name: &'static str, subsystem_name: &'static str, future: BoxFuture<'static, ()>) {
|
||||
spawner.spawn_blocking(task_name, Some(subsystem_name), future)
|
||||
}
|
||||
}
|
||||
@@ -706,13 +706,13 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
s: SubSys,
|
||||
subsystem_name: &'static str,
|
||||
futures: &mut #support_crate ::FuturesUnordered<BoxFuture<'static, ::std::result::Result<(), #error_ty> >>,
|
||||
) -> ::std::result::Result<OverseenSubsystem<M>, #error_ty >
|
||||
) -> ::std::result::Result<OrchestratedSubsystem<M>, #error_ty >
|
||||
where
|
||||
S: #support_crate ::SpawnNamed,
|
||||
S: #support_crate ::Spawner,
|
||||
M: std::fmt::Debug + Send + 'static,
|
||||
TK: TaskKind,
|
||||
Ctx: #support_crate ::SubsystemContext<Message=M>,
|
||||
E: std::error::Error + Send + Sync + 'static + From<#support_crate ::OverseerError>,
|
||||
E: ::std::error::Error + Send + Sync + 'static + ::std::convert::From<#support_crate ::OrchestraError>,
|
||||
SubSys: #support_crate ::Subsystem<Ctx, E>,
|
||||
{
|
||||
let #support_crate ::SpawnedSubsystem::<E> { future, name } = s.start(ctx);
|
||||
@@ -721,9 +721,9 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
|
||||
let fut = Box::pin(async move {
|
||||
if let Err(e) = future.await {
|
||||
#support_crate ::gum::error!(subsystem=name, err = ?e, "subsystem exited with error");
|
||||
#support_crate ::tracing::error!(subsystem=name, err = ?e, "subsystem exited with error");
|
||||
} else {
|
||||
#support_crate ::gum::debug!(subsystem=name, "subsystem exited without an error");
|
||||
#support_crate ::tracing::debug!(subsystem=name, "subsystem exited without an error");
|
||||
}
|
||||
let _ = tx.send(());
|
||||
});
|
||||
@@ -732,7 +732,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
|
||||
futures.push(Box::pin(
|
||||
rx.map(|e| {
|
||||
gum::warn!(err = ?e, "dropping error");
|
||||
#support_crate ::tracing::warn!(err = ?e, "dropping error");
|
||||
Ok(())
|
||||
})
|
||||
));
|
||||
@@ -749,7 +749,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
name,
|
||||
});
|
||||
|
||||
Ok(OverseenSubsystem {
|
||||
Ok(OrchestratedSubsystem {
|
||||
instance,
|
||||
})
|
||||
}
|
||||
+6
-6
@@ -20,7 +20,7 @@ use syn::Result;
|
||||
use super::*;
|
||||
|
||||
/// Implement the helper type `ChannelsOut` and `MessagePacket<T>`.
|
||||
pub(crate) fn impl_channels_out_struct(info: &OverseerInfo) -> Result<proc_macro2::TokenStream> {
|
||||
pub(crate) fn impl_channels_out_struct(info: &OrchestraInfo) -> Result<proc_macro2::TokenStream> {
|
||||
let message_wrapper = info.message_wrapper.clone();
|
||||
|
||||
let channel_name = &info.channel_names_without_wip("");
|
||||
@@ -36,7 +36,7 @@ pub(crate) fn impl_channels_out_struct(info: &OverseerInfo) -> Result<proc_macro
|
||||
let ts = quote! {
|
||||
/// Collection of channels to the individual subsystems.
|
||||
///
|
||||
/// Naming is from the point of view of the overseer.
|
||||
/// Naming is from the point of view of the orchestra.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ChannelsOut {
|
||||
#(
|
||||
@@ -84,13 +84,13 @@ pub(crate) fn impl_channels_out_struct(info: &OverseerInfo) -> Result<proc_macro
|
||||
#[allow(unreachable_patterns)]
|
||||
// And everything that's not WIP but no subsystem consumes it
|
||||
unused_msg => {
|
||||
#support_crate :: gum :: warn!("Nothing consumes {:?}", unused_msg);
|
||||
#support_crate :: tracing :: warn!("Nothing consumes {:?}", unused_msg);
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(subsystem_name) = res {
|
||||
#support_crate ::gum::debug!(
|
||||
#support_crate ::tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
"Failed to send (bounded) a message to {} subsystem",
|
||||
subsystem_name
|
||||
@@ -123,13 +123,13 @@ pub(crate) fn impl_channels_out_struct(info: &OverseerInfo) -> Result<proc_macro
|
||||
// And everything that's not WIP but no subsystem consumes it
|
||||
#[allow(unreachable_patterns)]
|
||||
unused_msg => {
|
||||
#support_crate :: gum :: warn!("Nothing consumes {:?}", unused_msg);
|
||||
#support_crate :: tracing :: warn!("Nothing consumes {:?}", unused_msg);
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
|
||||
if let Err(subsystem_name) = res {
|
||||
#support_crate ::gum::debug!(
|
||||
#support_crate ::tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
"Failed to send_unbounded a message to {} subsystem",
|
||||
subsystem_name
|
||||
+1
-1
@@ -20,7 +20,7 @@ use syn::{spanned::Spanned, Result};
|
||||
use super::*;
|
||||
|
||||
/// Generates the wrapper type enum.
|
||||
pub(crate) fn impl_message_wrapper_enum(info: &OverseerInfo) -> Result<proc_macro2::TokenStream> {
|
||||
pub(crate) fn impl_message_wrapper_enum(info: &OrchestraInfo) -> Result<proc_macro2::TokenStream> {
|
||||
let consumes = info.any_message();
|
||||
let consumes_variant = info.variant_names();
|
||||
|
||||
+23
-23
@@ -18,9 +18,9 @@ use quote::quote;
|
||||
|
||||
use super::*;
|
||||
|
||||
pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
pub(crate) fn impl_orchestra_struct(info: &OrchestraInfo) -> proc_macro2::TokenStream {
|
||||
let message_wrapper = &info.message_wrapper.clone();
|
||||
let overseer_name = info.overseer_name.clone();
|
||||
let orchestra_name = info.orchestra_name.clone();
|
||||
let subsystem_name = &info.subsystem_names_without_wip();
|
||||
let support_crate = info.support_crate_name();
|
||||
|
||||
@@ -34,7 +34,7 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr
|
||||
|
||||
let where_clause = quote! {
|
||||
where
|
||||
S: #support_crate ::SpawnNamed,
|
||||
S: #support_crate ::Spawner,
|
||||
};
|
||||
// TODO add `where ..` clauses for baggage types
|
||||
// TODO <https://github.com/paritytech/polkadot/issues/3427>
|
||||
@@ -53,25 +53,25 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr
|
||||
let signal_channel_capacity = info.signal_channel_capacity;
|
||||
|
||||
let log_target =
|
||||
syn::LitStr::new(overseer_name.to_string().to_lowercase().as_str(), overseer_name.span());
|
||||
syn::LitStr::new(orchestra_name.to_string().to_lowercase().as_str(), orchestra_name.span());
|
||||
|
||||
let ts = quote! {
|
||||
/// Capacity of a bounded message channel between overseer and subsystem
|
||||
/// Capacity of a bounded message channel between orchestra and subsystem
|
||||
/// but also for bounded channels between two subsystems.
|
||||
const CHANNEL_CAPACITY: usize = #message_channel_capacity;
|
||||
|
||||
/// Capacity of a signal channel between a subsystem and the overseer.
|
||||
/// Capacity of a signal channel between a subsystem and the orchestra.
|
||||
const SIGNAL_CHANNEL_CAPACITY: usize = #signal_channel_capacity;
|
||||
|
||||
/// The log target tag.
|
||||
const LOG_TARGET: &'static str = #log_target;
|
||||
|
||||
/// The overseer.
|
||||
pub struct #overseer_name #generics {
|
||||
/// The orchestra.
|
||||
pub struct #orchestra_name #generics {
|
||||
|
||||
#(
|
||||
/// A subsystem instance.
|
||||
#subsystem_name: OverseenSubsystem< #consumes >,
|
||||
#subsystem_name: OrchestratedSubsystem< #consumes >,
|
||||
)*
|
||||
|
||||
#(
|
||||
@@ -88,15 +88,15 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr
|
||||
>,
|
||||
|
||||
/// Gather running subsystems' outbound streams into one.
|
||||
to_overseer_rx: #support_crate ::stream::Fuse<
|
||||
#support_crate ::metered::UnboundedMeteredReceiver< #support_crate ::ToOverseer >
|
||||
to_orchestra_rx: #support_crate ::stream::Fuse<
|
||||
#support_crate ::metered::UnboundedMeteredReceiver< #support_crate ::ToOrchestra >
|
||||
>,
|
||||
|
||||
/// Events that are sent to the overseer from the outside world.
|
||||
/// Events that are sent to the orchestra from the outside world.
|
||||
events_rx: #support_crate ::metered::MeteredReceiver< #event_ty >,
|
||||
}
|
||||
|
||||
impl #generics #overseer_name #generics #where_clause {
|
||||
impl #generics #orchestra_name #generics #where_clause {
|
||||
/// Send the given signal, a termination signal, to all subsystems
|
||||
/// and wait for all subsystems to go down.
|
||||
///
|
||||
@@ -141,7 +141,7 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr
|
||||
match message {
|
||||
#(
|
||||
#message_wrapper :: #consumes_variant ( inner ) =>
|
||||
OverseenSubsystem::< #consumes >::send_message2(&mut self. #subsystem_name, inner, origin ).await?,
|
||||
OrchestratedSubsystem::< #consumes >::send_message2(&mut self. #subsystem_name, inner, origin ).await?,
|
||||
)*
|
||||
// subsystems that are still work in progress
|
||||
#(
|
||||
@@ -152,7 +152,7 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr
|
||||
// And everything that's not WIP but no subsystem consumes it
|
||||
#[allow(unreachable_patterns)]
|
||||
unused_msg => {
|
||||
#support_crate :: gum :: warn!("Nothing consumes {:?}", unused_msg);
|
||||
#support_crate :: tracing :: warn!("Nothing consumes {:?}", unused_msg);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -163,7 +163,7 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr
|
||||
-> Vec<Output>
|
||||
where
|
||||
#(
|
||||
Mapper: MapSubsystem<&'a OverseenSubsystem< #consumes >, Output=Output>,
|
||||
Mapper: MapSubsystem<&'a OrchestratedSubsystem< #consumes >, Output=Output>,
|
||||
)*
|
||||
{
|
||||
vec![
|
||||
@@ -184,27 +184,27 @@ pub(crate) fn impl_overseer_struct(info: &OverseerInfo) -> proc_macro2::TokenStr
|
||||
ts
|
||||
}
|
||||
|
||||
pub(crate) fn impl_overseen_subsystem(info: &OverseerInfo) -> proc_macro2::TokenStream {
|
||||
pub(crate) fn impl_orchestrated_subsystem(info: &OrchestraInfo) -> proc_macro2::TokenStream {
|
||||
let signal = &info.extern_signal_ty;
|
||||
let error_ty = &info.extern_error_ty;
|
||||
let support_crate = info.support_crate_name();
|
||||
|
||||
let ts = quote::quote! {
|
||||
/// A subsystem that the overseer oversees.
|
||||
/// A subsystem that the orchestrator orchestrates.
|
||||
///
|
||||
/// Ties together the [`Subsystem`] itself and it's running instance
|
||||
/// (which may be missing if the [`Subsystem`] is not running at the moment
|
||||
/// for whatever reason).
|
||||
///
|
||||
/// [`Subsystem`]: trait.Subsystem.html
|
||||
pub struct OverseenSubsystem<M> {
|
||||
pub struct OrchestratedSubsystem<M> {
|
||||
/// The instance.
|
||||
pub instance: std::option::Option<
|
||||
#support_crate ::SubsystemInstance<M, #signal>
|
||||
>,
|
||||
}
|
||||
|
||||
impl<M> OverseenSubsystem<M> {
|
||||
impl<M> OrchestratedSubsystem<M> {
|
||||
/// Send a message to the wrapped subsystem.
|
||||
///
|
||||
/// If the inner `instance` is `None`, nothing is happening.
|
||||
@@ -218,14 +218,14 @@ pub(crate) fn impl_overseen_subsystem(info: &OverseerInfo) -> proc_macro2::Token
|
||||
}).timeout(MESSAGE_TIMEOUT).await
|
||||
{
|
||||
None => {
|
||||
#support_crate ::gum::error!(
|
||||
#support_crate ::tracing::error!(
|
||||
target: LOG_TARGET,
|
||||
%origin,
|
||||
"Subsystem {} appears unresponsive.",
|
||||
instance.name,
|
||||
);
|
||||
Err(#error_ty :: from(
|
||||
#support_crate ::OverseerError::SubsystemStalled(instance.name)
|
||||
#support_crate ::OrchestraError::SubsystemStalled(instance.name)
|
||||
))
|
||||
}
|
||||
Some(res) => res.map_err(Into::into),
|
||||
@@ -245,7 +245,7 @@ pub(crate) fn impl_overseen_subsystem(info: &OverseerInfo) -> proc_macro2::Token
|
||||
match instance.tx_signal.send(signal).timeout(SIGNAL_TIMEOUT).await {
|
||||
None => {
|
||||
Err(#error_ty :: from(
|
||||
#support_crate ::OverseerError::SubsystemStalled(instance.name)
|
||||
#support_crate ::OrchestraError::SubsystemStalled(instance.name)
|
||||
))
|
||||
}
|
||||
Some(res) => {
|
||||
+32
-32
@@ -52,11 +52,11 @@ fn graphviz(
|
||||
}
|
||||
|
||||
/// Generates all subsystem types and related accumulation traits.
|
||||
pub(crate) fn impl_subsystem_types_all(info: &OverseerInfo) -> Result<TokenStream> {
|
||||
pub(crate) fn impl_subsystem_types_all(info: &OrchestraInfo) -> Result<TokenStream> {
|
||||
let mut ts = TokenStream::new();
|
||||
|
||||
let overseer_name = &info.overseer_name;
|
||||
let span = overseer_name.span();
|
||||
let orchestra_name = &info.orchestra_name;
|
||||
let span = orchestra_name.span();
|
||||
let all_messages_wrapper = &info.message_wrapper;
|
||||
let support_crate = info.support_crate_name();
|
||||
let signal_ty = &info.extern_signal_ty;
|
||||
@@ -125,7 +125,7 @@ pub(crate) fn impl_subsystem_types_all(info: &OverseerInfo) -> Result<TokenStrea
|
||||
// And everything that's not WIP but no subsystem consumes it
|
||||
#[allow(unreachable_patterns)]
|
||||
unused_msg => {
|
||||
#support_crate :: gum :: warn!("Nothing consumes {:?}", unused_msg);
|
||||
#support_crate :: tracing :: warn!("Nothing consumes {:?}", unused_msg);
|
||||
#all_messages_wrapper :: Empty
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ pub(crate) fn impl_subsystem_types_all(info: &OverseerInfo) -> Result<TokenStrea
|
||||
// Dump the graph to file.
|
||||
if cfg!(feature = "graph") || true {
|
||||
let path = std::path::PathBuf::from(env!("OUT_DIR"))
|
||||
.join(overseer_name.to_string().to_lowercase() + "-subsystem-messaging.dot");
|
||||
.join(orchestra_name.to_string().to_lowercase() + "-subsystem-messaging.dot");
|
||||
if let Err(e) = std::fs::OpenOptions::new()
|
||||
.truncate(true)
|
||||
.create(true)
|
||||
@@ -151,8 +151,8 @@ pub(crate) fn impl_subsystem_types_all(info: &OverseerInfo) -> Result<TokenStrea
|
||||
}
|
||||
}
|
||||
|
||||
let subsystem_sender_name = &Ident::new(&(overseer_name.to_string() + "Sender"), span);
|
||||
let subsystem_ctx_name = &Ident::new(&(overseer_name.to_string() + "SubsystemContext"), span);
|
||||
let subsystem_sender_name = &Ident::new(&(orchestra_name.to_string() + "Sender"), span);
|
||||
let subsystem_ctx_name = &Ident::new(&(orchestra_name.to_string() + "SubsystemContext"), span);
|
||||
ts.extend(impl_subsystem_context(info, &subsystem_sender_name, &subsystem_ctx_name));
|
||||
|
||||
ts.extend(impl_associate_outgoing_messages_trait(&all_messages_wrapper));
|
||||
@@ -300,7 +300,7 @@ pub(crate) fn impl_subsystem_sender(
|
||||
// Create the same for a wrapping enum:
|
||||
//
|
||||
// 1. subsystem specific `*OutgoingMessages`-type
|
||||
// 2. overseer-global-`AllMessages`-type
|
||||
// 2. orchestra-global-`AllMessages`-type
|
||||
let wrapped = |outgoing_wrapper: &TokenStream| {
|
||||
quote! {
|
||||
#[#support_crate ::async_trait]
|
||||
@@ -436,32 +436,32 @@ pub(crate) fn impl_subsystem_context_trait_for(
|
||||
type Sender = #subsystem_sender_name < #outgoing_wrapper >;
|
||||
type Error = #error_ty;
|
||||
|
||||
async fn try_recv(&mut self) -> ::std::result::Result<Option<FromOverseer< Self::Message, #signal>>, ()> {
|
||||
async fn try_recv(&mut self) -> ::std::result::Result<Option<FromOrchestra< Self::Message, #signal>>, ()> {
|
||||
match #support_crate ::poll!(self.recv()) {
|
||||
#support_crate ::Poll::Ready(msg) => Ok(Some(msg.map_err(|_| ())?)),
|
||||
#support_crate ::Poll::Pending => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
async fn recv(&mut self) -> ::std::result::Result<FromOverseer<Self::Message, #signal>, #error_ty> {
|
||||
async fn recv(&mut self) -> ::std::result::Result<FromOrchestra<Self::Message, #signal>, #error_ty> {
|
||||
loop {
|
||||
// If we have a message pending an overseer signal, we only poll for signals
|
||||
// If we have a message pending an orchestra signal, we only poll for signals
|
||||
// in the meantime.
|
||||
if let Some((needs_signals_received, msg)) = self.pending_incoming.take() {
|
||||
if needs_signals_received <= self.signals_received.load() {
|
||||
return Ok( #support_crate ::FromOverseer::Communication { msg });
|
||||
return Ok( #support_crate ::FromOrchestra::Communication { msg });
|
||||
} else {
|
||||
self.pending_incoming = Some((needs_signals_received, msg));
|
||||
|
||||
// wait for next signal.
|
||||
let signal = self.signals.next().await
|
||||
.ok_or(#support_crate ::OverseerError::Context(
|
||||
.ok_or(#support_crate ::OrchestraError::Context(
|
||||
"Signal channel is terminated and empty."
|
||||
.to_owned()
|
||||
))?;
|
||||
|
||||
self.signals_received.inc();
|
||||
return Ok( #support_crate ::FromOverseer::Signal(signal))
|
||||
return Ok( #support_crate ::FromOrchestra::Signal(signal))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,19 +471,19 @@ pub(crate) fn impl_subsystem_context_trait_for(
|
||||
let pending_incoming = &mut self.pending_incoming;
|
||||
|
||||
// Otherwise, wait for the next signal or incoming message.
|
||||
let from_overseer = #support_crate ::futures::select_biased! {
|
||||
let from_orchestra = #support_crate ::futures::select_biased! {
|
||||
signal = await_signal => {
|
||||
let signal = signal
|
||||
.ok_or( #support_crate ::OverseerError::Context(
|
||||
.ok_or( #support_crate ::OrchestraError::Context(
|
||||
"Signal channel is terminated and empty."
|
||||
.to_owned()
|
||||
))?;
|
||||
|
||||
#support_crate ::FromOverseer::Signal(signal)
|
||||
#support_crate ::FromOrchestra::Signal(signal)
|
||||
}
|
||||
msg = await_message => {
|
||||
let packet = msg
|
||||
.ok_or( #support_crate ::OverseerError::Context(
|
||||
.ok_or( #support_crate ::OrchestraError::Context(
|
||||
"Message channel is terminated and empty."
|
||||
.to_owned()
|
||||
))?;
|
||||
@@ -494,16 +494,16 @@ pub(crate) fn impl_subsystem_context_trait_for(
|
||||
continue;
|
||||
} else {
|
||||
// we know enough to return this message.
|
||||
#support_crate ::FromOverseer::Communication { msg: packet.message}
|
||||
#support_crate ::FromOrchestra::Communication { msg: packet.message}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let #support_crate ::FromOverseer::Signal(_) = from_overseer {
|
||||
if let #support_crate ::FromOrchestra::Signal(_) = from_orchestra {
|
||||
self.signals_received.inc();
|
||||
}
|
||||
|
||||
return Ok(from_overseer);
|
||||
return Ok(from_orchestra);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,22 +514,22 @@ pub(crate) fn impl_subsystem_context_trait_for(
|
||||
fn spawn(&mut self, name: &'static str, s: Pin<Box<dyn Future<Output = ()> + Send>>)
|
||||
-> ::std::result::Result<(), #error_ty>
|
||||
{
|
||||
self.to_overseer.unbounded_send(#support_crate ::ToOverseer::SpawnJob {
|
||||
self.to_orchestra.unbounded_send(#support_crate ::ToOrchestra::SpawnJob {
|
||||
name,
|
||||
subsystem: Some(self.name()),
|
||||
s,
|
||||
}).map_err(|_| #support_crate ::OverseerError::TaskSpawn(name))?;
|
||||
}).map_err(|_| #support_crate ::OrchestraError::TaskSpawn(name))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn spawn_blocking(&mut self, name: &'static str, s: Pin<Box<dyn Future<Output = ()> + Send>>)
|
||||
-> ::std::result::Result<(), #error_ty>
|
||||
{
|
||||
self.to_overseer.unbounded_send(#support_crate ::ToOverseer::SpawnBlockingJob {
|
||||
self.to_orchestra.unbounded_send(#support_crate ::ToOrchestra::SpawnBlockingJob {
|
||||
name,
|
||||
subsystem: Some(self.name()),
|
||||
s,
|
||||
}).map_err(|_| #support_crate ::OverseerError::TaskSpawn(name))?;
|
||||
}).map_err(|_| #support_crate ::OrchestraError::TaskSpawn(name))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -539,7 +539,7 @@ pub(crate) fn impl_subsystem_context_trait_for(
|
||||
/// Implement the additional subsystem accumulation traits, for simplified usage,
|
||||
/// i.e. `${Subsystem}SenderTrait` and `${Subsystem}ContextTrait`.
|
||||
pub(crate) fn impl_per_subsystem_helper_traits(
|
||||
info: &OverseerInfo,
|
||||
info: &OrchestraInfo,
|
||||
subsystem_ctx_name: &Ident,
|
||||
subsystem_ctx_trait: &Ident,
|
||||
subsystem_sender_name: &Ident,
|
||||
@@ -645,7 +645,7 @@ pub(crate) fn impl_per_subsystem_helper_traits(
|
||||
///
|
||||
/// Note: The generated `fn new` is used by the [builder pattern](../impl_builder.rs).
|
||||
pub(crate) fn impl_subsystem_context(
|
||||
info: &OverseerInfo,
|
||||
info: &OrchestraInfo,
|
||||
subsystem_sender_name: &Ident,
|
||||
subsystem_ctx_name: &Ident,
|
||||
) -> TokenStream {
|
||||
@@ -657,7 +657,7 @@ pub(crate) fn impl_subsystem_context(
|
||||
/// It can be used by [`Subsystem`] to communicate with other [`Subsystem`]s
|
||||
/// or to spawn it's [`SubsystemJob`]s.
|
||||
///
|
||||
/// [`Overseer`]: struct.Overseer.html
|
||||
/// [`Orchestra`]: struct.Orchestra.html
|
||||
/// [`Subsystem`]: trait.Subsystem.html
|
||||
/// [`SubsystemJob`]: trait.SubsystemJob.html
|
||||
#[derive(Debug)]
|
||||
@@ -666,8 +666,8 @@ pub(crate) fn impl_subsystem_context(
|
||||
signals: #support_crate ::metered::MeteredReceiver< #signal_ty >,
|
||||
messages: SubsystemIncomingMessages< M >,
|
||||
to_subsystems: #subsystem_sender_name < <M as AssociateOutgoing>::OutgoingMessages >,
|
||||
to_overseer: #support_crate ::metered::UnboundedMeteredSender<
|
||||
#support_crate ::ToOverseer
|
||||
to_orchestra: #support_crate ::metered::UnboundedMeteredSender<
|
||||
#support_crate ::ToOrchestra
|
||||
>,
|
||||
signals_received: SignalsReceived,
|
||||
pending_incoming: Option<(usize, M)>,
|
||||
@@ -683,7 +683,7 @@ pub(crate) fn impl_subsystem_context(
|
||||
signals: #support_crate ::metered::MeteredReceiver< #signal_ty >,
|
||||
messages: SubsystemIncomingMessages< M >,
|
||||
to_subsystems: ChannelsOut,
|
||||
to_overseer: #support_crate ::metered::UnboundedMeteredSender<#support_crate:: ToOverseer>,
|
||||
to_orchestra: #support_crate ::metered::UnboundedMeteredSender<#support_crate:: ToOrchestra>,
|
||||
name: &'static str
|
||||
) -> Self {
|
||||
let signals_received = SignalsReceived::default();
|
||||
@@ -695,7 +695,7 @@ pub(crate) fn impl_subsystem_context(
|
||||
signals_received: signals_received.clone(),
|
||||
_phantom: ::core::marker::PhantomData::default(),
|
||||
},
|
||||
to_overseer,
|
||||
to_orchestra,
|
||||
signals_received,
|
||||
pending_incoming: None,
|
||||
name
|
||||
+7
-7
@@ -20,9 +20,9 @@ use syn::{parse_quote, spanned::Spanned, Path};
|
||||
mod impl_builder;
|
||||
mod impl_channels_out;
|
||||
mod impl_message_wrapper;
|
||||
mod impl_overseer;
|
||||
mod impl_orchestra;
|
||||
mod impl_subsystem_ctx_sender;
|
||||
mod overseer;
|
||||
mod orchestra;
|
||||
mod parse;
|
||||
mod subsystem;
|
||||
|
||||
@@ -32,11 +32,11 @@ mod tests;
|
||||
use impl_builder::*;
|
||||
use impl_channels_out::*;
|
||||
use impl_message_wrapper::*;
|
||||
use impl_overseer::*;
|
||||
use impl_orchestra::*;
|
||||
use impl_subsystem_ctx_sender::*;
|
||||
use parse::*;
|
||||
|
||||
use self::{overseer::*, subsystem::*};
|
||||
use self::{orchestra::*, subsystem::*};
|
||||
|
||||
/// Obtain the support crate `Path` as `TokenStream`.
|
||||
pub(crate) fn support_crate() -> Result<Path, proc_macro_crate::Error> {
|
||||
@@ -44,7 +44,7 @@ pub(crate) fn support_crate() -> Result<Path, proc_macro_crate::Error> {
|
||||
parse_quote! {crate}
|
||||
} else {
|
||||
use proc_macro_crate::{crate_name, FoundCrate};
|
||||
let crate_name = crate_name("polkadot-overseer-gen")?;
|
||||
let crate_name = crate_name("orchestra")?;
|
||||
match crate_name {
|
||||
FoundCrate::Itself => parse_quote! {crate},
|
||||
FoundCrate::Name(name) => Ident::new(&name, Span::call_site()).into(),
|
||||
@@ -53,13 +53,13 @@ pub(crate) fn support_crate() -> Result<Path, proc_macro_crate::Error> {
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn overlord(
|
||||
pub fn orchestra(
|
||||
attr: proc_macro::TokenStream,
|
||||
item: proc_macro::TokenStream,
|
||||
) -> proc_macro::TokenStream {
|
||||
let attr: TokenStream = attr.into();
|
||||
let item: TokenStream = item.into();
|
||||
impl_overseer_gen(attr, item)
|
||||
impl_orchestra_gen(attr, item)
|
||||
.unwrap_or_else(|err| err.to_compile_error())
|
||||
.into()
|
||||
}
|
||||
+9
-9
@@ -19,21 +19,21 @@ use syn::{parse2, Result};
|
||||
|
||||
use super::{parse::*, *};
|
||||
|
||||
pub(crate) fn impl_overseer_gen(
|
||||
pub(crate) fn impl_orchestra_gen(
|
||||
attr: TokenStream,
|
||||
orig: TokenStream,
|
||||
) -> Result<proc_macro2::TokenStream> {
|
||||
let args: OverseerAttrArgs = parse2(attr)?;
|
||||
let args: OrchestraAttrArgs = parse2(attr)?;
|
||||
let message_wrapper = args.message_wrapper;
|
||||
|
||||
let of: OverseerGuts = parse2(orig)?;
|
||||
let of: OrchestraGuts = parse2(orig)?;
|
||||
|
||||
let support_crate = support_crate().expect("The crate this macro is run for, includes the proc-macro support as dependency, otherwise it could not be run in the first place. qed");
|
||||
let info = OverseerInfo {
|
||||
let info = OrchestraInfo {
|
||||
support_crate,
|
||||
subsystems: of.subsystems,
|
||||
baggage: of.baggage,
|
||||
overseer_name: of.name,
|
||||
orchestra_name: of.name,
|
||||
message_wrapper,
|
||||
message_channel_capacity: args.message_channel_capacity,
|
||||
signal_channel_capacity: args.signal_channel_capacity,
|
||||
@@ -43,17 +43,17 @@ pub(crate) fn impl_overseer_gen(
|
||||
outgoing_ty: args.outgoing_ty,
|
||||
};
|
||||
|
||||
let mut additive = impl_overseer_struct(&info);
|
||||
let mut additive = impl_orchestra_struct(&info);
|
||||
additive.extend(impl_builder(&info));
|
||||
|
||||
additive.extend(impl_overseen_subsystem(&info));
|
||||
additive.extend(impl_orchestrated_subsystem(&info));
|
||||
additive.extend(impl_channels_out_struct(&info));
|
||||
additive.extend(impl_subsystem_types_all(&info)?);
|
||||
|
||||
additive.extend(impl_message_wrapper_enum(&info)?);
|
||||
|
||||
let ts = expander::Expander::new("overlord-expansion")
|
||||
.add_comment("Generated overseer code by `#[overlord(..)]`".to_owned())
|
||||
let ts = expander::Expander::new("orchestra-expansion")
|
||||
.add_comment("Generated orchestra code by `#[orchestra(..)]`".to_owned())
|
||||
.dry(!cfg!(feature = "expand"))
|
||||
.verbose(true)
|
||||
// once all our needed format options are available on stable
|
||||
+3
-3
@@ -26,14 +26,14 @@ mod kw {
|
||||
syn::custom_keyword!(prefix);
|
||||
}
|
||||
|
||||
mod parse_overseer_attr;
|
||||
mod parse_overseer_struct;
|
||||
mod parse_orchestra_attr;
|
||||
mod parse_orchestra_struct;
|
||||
|
||||
mod parse_subsystem_attr;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub(crate) use self::{parse_overseer_attr::*, parse_overseer_struct::*};
|
||||
pub(crate) use self::{parse_orchestra_attr::*, parse_orchestra_struct::*};
|
||||
|
||||
pub(crate) use self::parse_subsystem_attr::*;
|
||||
+25
-25
@@ -26,9 +26,9 @@ use syn::{
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
enum OverseerAttrItem {
|
||||
enum OrchestraAttrItem {
|
||||
ExternEventType { tag: kw::event, eq_token: Token![=], value: Path },
|
||||
ExternOverseerSignalType { tag: kw::signal, eq_token: Token![=], value: Path },
|
||||
ExternOrchestraSignalType { tag: kw::signal, eq_token: Token![=], value: Path },
|
||||
ExternErrorType { tag: kw::error, eq_token: Token![=], value: Path },
|
||||
OutgoingType { tag: kw::outgoing, eq_token: Token![=], value: Path },
|
||||
MessageWrapperName { tag: kw::gen, eq_token: Token![=], value: Ident },
|
||||
@@ -36,13 +36,13 @@ enum OverseerAttrItem {
|
||||
MessageChannelCapacity { tag: kw::message_capacity, eq_token: Token![=], value: usize },
|
||||
}
|
||||
|
||||
impl ToTokens for OverseerAttrItem {
|
||||
impl ToTokens for OrchestraAttrItem {
|
||||
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
|
||||
let ts = match self {
|
||||
Self::ExternEventType { tag, eq_token, value } => {
|
||||
quote! { #tag #eq_token, #value }
|
||||
},
|
||||
Self::ExternOverseerSignalType { tag, eq_token, value } => {
|
||||
Self::ExternOrchestraSignalType { tag, eq_token, value } => {
|
||||
quote! { #tag #eq_token, #value }
|
||||
},
|
||||
Self::ExternErrorType { tag, eq_token, value } => {
|
||||
@@ -65,47 +65,47 @@ impl ToTokens for OverseerAttrItem {
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for OverseerAttrItem {
|
||||
impl Parse for OrchestraAttrItem {
|
||||
fn parse(input: &ParseBuffer) -> Result<Self> {
|
||||
let lookahead = input.lookahead1();
|
||||
if lookahead.peek(kw::event) {
|
||||
Ok(OverseerAttrItem::ExternEventType {
|
||||
Ok(OrchestraAttrItem::ExternEventType {
|
||||
tag: input.parse::<kw::event>()?,
|
||||
eq_token: input.parse()?,
|
||||
value: input.parse()?,
|
||||
})
|
||||
} else if lookahead.peek(kw::signal) {
|
||||
Ok(OverseerAttrItem::ExternOverseerSignalType {
|
||||
Ok(OrchestraAttrItem::ExternOrchestraSignalType {
|
||||
tag: input.parse::<kw::signal>()?,
|
||||
eq_token: input.parse()?,
|
||||
value: input.parse()?,
|
||||
})
|
||||
} else if lookahead.peek(kw::error) {
|
||||
Ok(OverseerAttrItem::ExternErrorType {
|
||||
Ok(OrchestraAttrItem::ExternErrorType {
|
||||
tag: input.parse::<kw::error>()?,
|
||||
eq_token: input.parse()?,
|
||||
value: input.parse()?,
|
||||
})
|
||||
} else if lookahead.peek(kw::outgoing) {
|
||||
Ok(OverseerAttrItem::OutgoingType {
|
||||
Ok(OrchestraAttrItem::OutgoingType {
|
||||
tag: input.parse::<kw::outgoing>()?,
|
||||
eq_token: input.parse()?,
|
||||
value: input.parse()?,
|
||||
})
|
||||
} else if lookahead.peek(kw::gen) {
|
||||
Ok(OverseerAttrItem::MessageWrapperName {
|
||||
Ok(OrchestraAttrItem::MessageWrapperName {
|
||||
tag: input.parse::<kw::gen>()?,
|
||||
eq_token: input.parse()?,
|
||||
value: input.parse()?,
|
||||
})
|
||||
} else if lookahead.peek(kw::signal_capacity) {
|
||||
Ok(OverseerAttrItem::SignalChannelCapacity {
|
||||
Ok(OrchestraAttrItem::SignalChannelCapacity {
|
||||
tag: input.parse::<kw::signal_capacity>()?,
|
||||
eq_token: input.parse()?,
|
||||
value: input.parse::<LitInt>()?.base10_parse::<usize>()?,
|
||||
})
|
||||
} else if lookahead.peek(kw::message_capacity) {
|
||||
Ok(OverseerAttrItem::MessageChannelCapacity {
|
||||
Ok(OrchestraAttrItem::MessageChannelCapacity {
|
||||
tag: input.parse::<kw::message_capacity>()?,
|
||||
eq_token: input.parse()?,
|
||||
value: input.parse::<LitInt>()?.base10_parse::<usize>()?,
|
||||
@@ -118,7 +118,7 @@ impl Parse for OverseerAttrItem {
|
||||
|
||||
/// Attribute arguments
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct OverseerAttrArgs {
|
||||
pub(crate) struct OrchestraAttrArgs {
|
||||
pub(crate) message_wrapper: Ident,
|
||||
pub(crate) extern_event_ty: Path,
|
||||
pub(crate) extern_signal_ty: Path,
|
||||
@@ -137,7 +137,7 @@ macro_rules! extract_variant {
|
||||
};
|
||||
($unique:expr, $variant:ident) => {
|
||||
$unique.values().find_map(|item| {
|
||||
if let OverseerAttrItem::$variant { value, .. } = item {
|
||||
if let OrchestraAttrItem::$variant { value, .. } = item {
|
||||
Some(value.clone())
|
||||
} else {
|
||||
None
|
||||
@@ -146,21 +146,21 @@ macro_rules! extract_variant {
|
||||
};
|
||||
}
|
||||
|
||||
impl Parse for OverseerAttrArgs {
|
||||
impl Parse for OrchestraAttrArgs {
|
||||
fn parse(input: &ParseBuffer) -> Result<Self> {
|
||||
let items: Punctuated<OverseerAttrItem, Token![,]> =
|
||||
input.parse_terminated(OverseerAttrItem::parse)?;
|
||||
let items: Punctuated<OrchestraAttrItem, Token![,]> =
|
||||
input.parse_terminated(OrchestraAttrItem::parse)?;
|
||||
|
||||
let mut unique = HashMap::<
|
||||
std::mem::Discriminant<OverseerAttrItem>,
|
||||
OverseerAttrItem,
|
||||
std::mem::Discriminant<OrchestraAttrItem>,
|
||||
OrchestraAttrItem,
|
||||
RandomState,
|
||||
>::default();
|
||||
for item in items {
|
||||
if let Some(first) = unique.insert(std::mem::discriminant(&item), item.clone()) {
|
||||
let mut e = Error::new(
|
||||
item.span(),
|
||||
format!("Duplicate definition of overseer generation type found"),
|
||||
format!("Duplicate definition of orchestra generation type found"),
|
||||
);
|
||||
e.combine(Error::new(first.span(), "previously defined here."));
|
||||
return Err(e)
|
||||
@@ -172,13 +172,13 @@ impl Parse for OverseerAttrArgs {
|
||||
let message_channel_capacity =
|
||||
extract_variant!(unique, MessageChannelCapacity; default = 1024_usize);
|
||||
|
||||
let error = extract_variant!(unique, ExternErrorType; err = "Must declare the overseer error type via `error=..`.")?;
|
||||
let event = extract_variant!(unique, ExternEventType; err = "Must declare the overseer event type via `event=..`.")?;
|
||||
let signal = extract_variant!(unique, ExternOverseerSignalType; err = "Must declare the overseer signal type via `signal=..`.")?;
|
||||
let message_wrapper = extract_variant!(unique, MessageWrapperName; err = "Must declare the overseer generated wrapping message type via `gen=..`.")?;
|
||||
let error = extract_variant!(unique, ExternErrorType; err = "Must declare the orchestra error type via `error=..`.")?;
|
||||
let event = extract_variant!(unique, ExternEventType; err = "Must declare the orchestra event type via `event=..`.")?;
|
||||
let signal = extract_variant!(unique, ExternOrchestraSignalType; err = "Must declare the orchestra signal type via `signal=..`.")?;
|
||||
let message_wrapper = extract_variant!(unique, MessageWrapperName; err = "Must declare the orchestra generated wrapping message type via `gen=..`.")?;
|
||||
let outgoing = extract_variant!(unique, OutgoingType);
|
||||
|
||||
Ok(OverseerAttrArgs {
|
||||
Ok(OrchestraAttrArgs {
|
||||
signal_channel_capacity,
|
||||
message_channel_capacity,
|
||||
extern_event_ty: event,
|
||||
+9
-9
@@ -261,8 +261,8 @@ pub(crate) struct BaggageField {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct OverseerInfo {
|
||||
/// Where the support crate `::polkadot_overseer_gen` lives.
|
||||
pub(crate) struct OrchestraInfo {
|
||||
/// Where the support crate `::orchestra` lives.
|
||||
pub(crate) support_crate: Path,
|
||||
|
||||
/// Fields annotated with `#[subsystem(..)]`.
|
||||
@@ -272,9 +272,9 @@ pub(crate) struct OverseerInfo {
|
||||
pub(crate) baggage: Vec<BaggageField>,
|
||||
/// Name of the wrapping enum for all messages, defaults to `AllMessages`.
|
||||
pub(crate) message_wrapper: Ident,
|
||||
/// Name of the overseer struct, used as a prefix for
|
||||
/// Name of the orchestra struct, used as a prefix for
|
||||
/// almost all generated types.
|
||||
pub(crate) overseer_name: Ident,
|
||||
pub(crate) orchestra_name: Ident,
|
||||
|
||||
/// Size of the bounded channel.
|
||||
pub(crate) message_channel_capacity: usize,
|
||||
@@ -295,7 +295,7 @@ pub(crate) struct OverseerInfo {
|
||||
pub(crate) extern_error_ty: Path,
|
||||
}
|
||||
|
||||
impl OverseerInfo {
|
||||
impl OrchestraInfo {
|
||||
pub(crate) fn support_crate_name(&self) -> &Path {
|
||||
&self.support_crate
|
||||
}
|
||||
@@ -389,15 +389,15 @@ impl OverseerInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/// Internals of the overseer.
|
||||
/// Internals of the orchestra.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct OverseerGuts {
|
||||
pub(crate) struct OrchestraGuts {
|
||||
pub(crate) name: Ident,
|
||||
pub(crate) subsystems: Vec<SubSysField>,
|
||||
pub(crate) baggage: Vec<BaggageField>,
|
||||
}
|
||||
|
||||
impl OverseerGuts {
|
||||
impl OrchestraGuts {
|
||||
pub(crate) fn parse_fields(
|
||||
name: Ident,
|
||||
baggage_generics: HashSet<Ident>,
|
||||
@@ -497,7 +497,7 @@ impl OverseerGuts {
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for OverseerGuts {
|
||||
impl Parse for OrchestraGuts {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
let ds: ItemStruct = input.parse()?;
|
||||
match ds.fields {
|
||||
+4
-4
@@ -29,13 +29,13 @@ use syn::{
|
||||
enum SubsystemAttrItem {
|
||||
/// Error type provided by the user.
|
||||
Error { tag: kw::error, eq_token: Token![=], value: Path },
|
||||
/// For which slot in the overseer this should be plugged.
|
||||
/// For which slot in the orchestra this should be plugged.
|
||||
///
|
||||
/// The subsystem implementation can and should have a different name
|
||||
/// from the declared parameter type in the overseer.
|
||||
/// from the declared parameter type in the orchestra.
|
||||
Subsystem { tag: Option<kw::subsystem>, eq_token: Option<Token![=]>, value: Ident },
|
||||
/// The prefix to apply when a subsystem is implemented in a different file/crate
|
||||
/// than the overseer itself.
|
||||
/// than the orchestra itself.
|
||||
///
|
||||
/// Important for `#[subsystem(..)]` to reference the traits correctly.
|
||||
TraitPrefix { tag: kw::prefix, eq_token: Token![=], value: Path },
|
||||
@@ -137,7 +137,7 @@ impl Parse for SubsystemAttrArgs {
|
||||
}
|
||||
}
|
||||
let error_path = extract_variant!(unique, Error);
|
||||
let subsystem_ident = extract_variant!(unique, Subsystem; err = "Must annotate the identical overseer error type via `subsystem=..` or plainly as `Subsystem` as specified in the overseer declaration.")?;
|
||||
let subsystem_ident = extract_variant!(unique, Subsystem; err = "Must annotate the identical orchestra error type via `subsystem=..` or plainly as `Subsystem` as specified in the orchestra declaration.")?;
|
||||
let trait_prefix_path = extract_variant!(unique, TraitPrefix);
|
||||
Ok(SubsystemAttrArgs { span, error_path, subsystem_ident, trait_prefix_path })
|
||||
}
|
||||
+9
-9
@@ -25,11 +25,11 @@ mod attr {
|
||||
|
||||
#[test]
|
||||
fn attr_full_works() {
|
||||
let attr: OverseerAttrArgs = parse_quote! {
|
||||
let attr: OrchestraAttrArgs = parse_quote! {
|
||||
gen=AllMessage, event=::some::why::ExternEvent, signal=SigSigSig, signal_capacity=111, message_capacity=222,
|
||||
error=OverseerError,
|
||||
error=OrchestraError,
|
||||
};
|
||||
assert_matches!(attr, OverseerAttrArgs {
|
||||
assert_matches!(attr, OrchestraAttrArgs {
|
||||
message_channel_capacity,
|
||||
signal_channel_capacity,
|
||||
..
|
||||
@@ -41,11 +41,11 @@ mod attr {
|
||||
|
||||
#[test]
|
||||
fn attr_partial_works() {
|
||||
let attr: OverseerAttrArgs = parse_quote! {
|
||||
let attr: OrchestraAttrArgs = parse_quote! {
|
||||
gen=AllMessage, event=::some::why::ExternEvent, signal=::foo::SigSigSig,
|
||||
error=OverseerError,
|
||||
error=OrchestraError,
|
||||
};
|
||||
assert_matches!(attr, OverseerAttrArgs {
|
||||
assert_matches!(attr, OrchestraAttrArgs {
|
||||
message_channel_capacity: _,
|
||||
signal_channel_capacity: _,
|
||||
..
|
||||
@@ -249,7 +249,7 @@ mod strukt {
|
||||
|
||||
#[test]
|
||||
fn struct_parse_baggage() {
|
||||
let item: OverseerGuts = parse_quote! {
|
||||
let item: OrchestraGuts = parse_quote! {
|
||||
pub struct Ooooh<X = Pffffffft> where X: Secrit {
|
||||
#[subsystem(consumes: Foo, sends: [])]
|
||||
sub0: FooSubsystem,
|
||||
@@ -262,7 +262,7 @@ mod strukt {
|
||||
|
||||
#[test]
|
||||
fn struct_parse_full() {
|
||||
let item: OverseerGuts = parse_quote! {
|
||||
let item: OrchestraGuts = parse_quote! {
|
||||
pub struct Ooooh<X = Pffffffft> where X: Secrit {
|
||||
#[subsystem(consumes: Foo, sends: [])]
|
||||
sub0: FooSubsystem,
|
||||
@@ -284,7 +284,7 @@ mod strukt {
|
||||
|
||||
#[test]
|
||||
fn struct_parse_basic() {
|
||||
let item: OverseerGuts = parse_quote! {
|
||||
let item: OrchestraGuts = parse_quote! {
|
||||
pub struct Ooooh {
|
||||
#[subsystem(consumes: Foo, sends: [])]
|
||||
sub0: FooSubsystem,
|
||||
+17
-17
@@ -20,16 +20,16 @@
|
||||
//! ## Implement `trait Subsystem<Context, Error>` via `subsystem`
|
||||
//!
|
||||
//! ```ignore
|
||||
//! # use polkadot_overseer_gen_proc_macro::subsystem;
|
||||
//! # use orchestra_proc_macro::subsystem;
|
||||
//! # mod somewhere {
|
||||
//! # use polkadot_overseer_gen_proc_macro::overlord;
|
||||
//! # pub use polkadot_overseer_gen::*;
|
||||
//! # use orchestra_proc_macro::orchestra;
|
||||
//! # pub use orchestra::*;
|
||||
//! #
|
||||
//! # #[derive(Debug, thiserror::Error)]
|
||||
//! # #[error("Yikes!")]
|
||||
//! # pub struct Yikes;
|
||||
//! # impl From<OverseerError> for Yikes {
|
||||
//! # fn from(_: OverseerError) -> Yikes { Yikes }
|
||||
//! # impl From<OrchestraError> for Yikes {
|
||||
//! # fn from(_: OrchestraError) -> Yikes { Yikes }
|
||||
//! # }
|
||||
//! # impl From<mpsc::SendError> for Yikes {
|
||||
//! # fn from(_: mpsc::SendError) -> Yikes { Yikes }
|
||||
@@ -46,7 +46,7 @@
|
||||
//! # #[derive(Debug, Clone, Copy)]
|
||||
//! # pub struct B;
|
||||
//! #
|
||||
//! # #[overlord(signal=Sig, gen=AllOfThem, event=Eve, error=Yikes)]
|
||||
//! # #[orchestra(signal=Sig, gen=AllOfThem, event=Eve, error=Yikes)]
|
||||
//! # pub struct Wonderland {
|
||||
//! # #[subsystem(A, sends: [B])]
|
||||
//! # foo: Foo,
|
||||
@@ -71,16 +71,16 @@
|
||||
//! expands to
|
||||
//!
|
||||
//! ```ignore
|
||||
//! # use polkadot_overseer_gen_proc_macro::subsystem;
|
||||
//! # use orchestra_proc_macro::subsystem;
|
||||
//! # mod somewhere {
|
||||
//! # use polkadot_overseer_gen_proc_macro::overlord;
|
||||
//! # pub use polkadot_overseer_gen::*;
|
||||
//! # use orchestra_proc_macro::orchestra;
|
||||
//! # pub use orchestra::*;
|
||||
//! #
|
||||
//! # #[derive(Debug, thiserror::Error)]
|
||||
//! # #[error("Yikes!")]
|
||||
//! # pub struct Yikes;
|
||||
//! # impl From<OverseerError> for Yikes {
|
||||
//! # fn from(_: OverseerError) -> Yikes { Yikes }
|
||||
//! # impl From<OrchestraError> for Yikes {
|
||||
//! # fn from(_: OrchestraError) -> Yikes { Yikes }
|
||||
//! # }
|
||||
//! # impl From<mpsc::SendError> for Yikes {
|
||||
//! # fn from(_: mpsc::SendError) -> Yikes { Yikes }
|
||||
@@ -97,7 +97,7 @@
|
||||
//! # #[derive(Debug, Clone, Copy)]
|
||||
//! # pub struct B;
|
||||
//! #
|
||||
//! # #[overlord(signal=Sig, gen=AllOfThem, event=Eve, error=Yikes)]
|
||||
//! # #[orchestra(signal=Sig, gen=AllOfThem, event=Eve, error=Yikes)]
|
||||
//! # pub struct Wonderland {
|
||||
//! # #[subsystem(A, sends: [B])]
|
||||
//! # foo: Foo,
|
||||
@@ -106,7 +106,7 @@
|
||||
//! # }
|
||||
//! # }
|
||||
//! # use somewhere::{Yikes, SpawnedSubsystem};
|
||||
//! # use polkadot_overseer_gen as support_crate;
|
||||
//! # use orchestra as support_crate;
|
||||
//! #
|
||||
//! # struct FooSubsystem;
|
||||
//! #
|
||||
@@ -204,15 +204,15 @@ pub(crate) fn impl_subsystem_context_trait_bounds(
|
||||
// a `prefix=*` provided. Either is ok.
|
||||
|
||||
// Technically this is two different things:
|
||||
// The place where the `#[overlord]` is annotated is where all `trait *SenderTrait` and
|
||||
// The place where the `#[orchestra]` is annotated is where all `trait *SenderTrait` and
|
||||
// `trait *ContextTrait` types exist.
|
||||
// The other usage is the true support crate `polkadot-overseer-gen`, where the static ones
|
||||
// The other usage is the true support crate `orchestra`, where the static ones
|
||||
// are declared.
|
||||
// Right now, if the `support_crate` is not included, it falls back silently to the `trait_prefix_path`.
|
||||
let support_crate = support_crate()
|
||||
.or_else(|_e| {
|
||||
trait_prefix_path.clone().ok_or_else(|| {
|
||||
syn::Error::new(attr.span(), "Couldn't find `polkadot-overseer-gen` in manifest, but also missing a `prefix=` to help trait bound resolution")
|
||||
syn::Error::new(attr.span(), "Couldn't find `orchestra` in manifest, but also missing a `prefix=` to help trait bound resolution")
|
||||
})
|
||||
})?;
|
||||
|
||||
@@ -255,7 +255,7 @@ pub(crate) fn impl_subsystem_context_trait_bounds(
|
||||
let error_path = error_path.ok_or_else(|| {
|
||||
syn::Error::new(
|
||||
span,
|
||||
"Must annotate the identical overseer error type via `error=..`.",
|
||||
"Must annotate the identical orchestra error type via `error=..`.",
|
||||
)
|
||||
})?;
|
||||
// Only replace the subsystem trait if it's desired.
|
||||
+10
-10
@@ -27,7 +27,7 @@ fn print() {
|
||||
signal=SigSigSig,
|
||||
signal_capacity=111,
|
||||
message_capacity=222,
|
||||
error=OverseerError,
|
||||
error=OrchestraError,
|
||||
};
|
||||
|
||||
let item = quote! {
|
||||
@@ -48,14 +48,14 @@ fn print() {
|
||||
}
|
||||
};
|
||||
|
||||
let output = impl_overseer_gen(attr, item).expect("Simple example always works. qed");
|
||||
let output = impl_orchestra_gen(attr, item).expect("Simple example always works. qed");
|
||||
println!("//generated:");
|
||||
println!("{}", output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn struct_parse_full() {
|
||||
let item: OverseerGuts = parse_quote! {
|
||||
let item: OrchestraGuts = parse_quote! {
|
||||
pub struct Ooooh<X = Pffffffft> where X: Secrit {
|
||||
#[subsystem(Foo)]
|
||||
sub0: FooSubsystem,
|
||||
@@ -77,7 +77,7 @@ fn struct_parse_full() {
|
||||
|
||||
#[test]
|
||||
fn struct_parse_basic() {
|
||||
let item: OverseerGuts = parse_quote! {
|
||||
let item: OrchestraGuts = parse_quote! {
|
||||
pub struct Ooooh {
|
||||
#[subsystem(Foo)]
|
||||
sub0: FooSubsystem,
|
||||
@@ -88,11 +88,11 @@ fn struct_parse_basic() {
|
||||
|
||||
#[test]
|
||||
fn attr_full() {
|
||||
let attr: OverseerAttrArgs = parse_quote! {
|
||||
let attr: OrchestraAttrArgs = parse_quote! {
|
||||
gen=AllMessage, event=::some::why::ExternEvent, signal=SigSigSig, signal_capacity=111, message_capacity=222,
|
||||
error=OverseerError,
|
||||
error=OrchestraError,
|
||||
};
|
||||
assert_matches!(attr, OverseerAttrArgs {
|
||||
assert_matches!(attr, OrchestraAttrArgs {
|
||||
message_channel_capacity,
|
||||
signal_channel_capacity,
|
||||
..
|
||||
@@ -104,11 +104,11 @@ fn attr_full() {
|
||||
|
||||
#[test]
|
||||
fn attr_partial() {
|
||||
let attr: OverseerAttrArgs = parse_quote! {
|
||||
let attr: OrchestraAttrArgs = parse_quote! {
|
||||
gen=AllMessage, event=::some::why::ExternEvent, signal=::foo::SigSigSig,
|
||||
error=OverseerError,
|
||||
error=OrchestraError,
|
||||
};
|
||||
assert_matches!(attr, OverseerAttrArgs {
|
||||
assert_matches!(attr, OrchestraAttrArgs {
|
||||
message_channel_capacity: _,
|
||||
signal_channel_capacity: _,
|
||||
..
|
||||
+59
-39
@@ -14,29 +14,31 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! # Overseer
|
||||
//! # Orchestra
|
||||
//!
|
||||
//! `overseer` implements the Overseer architecture described in the
|
||||
//! [implementers-guide](https://w3f.github.io/parachain-implementers-guide/node/index.html).
|
||||
//! For the motivations behind implementing the overseer itself you should
|
||||
//! check out that guide, documentation in this crate will be mostly discussing
|
||||
//! technical stuff.
|
||||
//! `orchestra` provides a global information flow of what a token of information.
|
||||
//! The token is arbitrary, but is used to notify all `Subsystem`s of what is relevant
|
||||
//! and what is not.
|
||||
//!
|
||||
//! An `Overseer` is something that allows spawning/stopping and overseeing
|
||||
//! For the motivations behind implementing the orchestra itself you should
|
||||
//! check out that guide, documentation in this crate will focus and be of
|
||||
//! technical nature.
|
||||
//!
|
||||
//! An `Orchestra` is something that allows spawning/stopping and orchestrating
|
||||
//! asynchronous tasks as well as establishing a well-defined and easy to use
|
||||
//! protocol that the tasks can use to communicate with each other. It is desired
|
||||
//! that this protocol is the only way tasks communicate with each other, however
|
||||
//! at this moment there are no foolproof guards against other ways of communication.
|
||||
//!
|
||||
//! The `Overseer` is instantiated with a pre-defined set of `Subsystems` that
|
||||
//! share the same behavior from `Overseer`'s point of view.
|
||||
//! The `Orchestra` is instantiated with a pre-defined set of `Subsystems` that
|
||||
//! share the same behavior from `Orchestra`'s point of view.
|
||||
//!
|
||||
//! ```text
|
||||
//! +-----------------------------+
|
||||
//! | Overseer |
|
||||
//! | Orchesta |
|
||||
//! +-----------------------------+
|
||||
//!
|
||||
//! ................| Overseer "holds" these and uses |..............
|
||||
//! ................| Orchestra "holds" these and uses |.............
|
||||
//! . them to (re)start things .
|
||||
//! . .
|
||||
//! . +-------------------+ +---------------------+ .
|
||||
@@ -47,7 +49,7 @@
|
||||
//! | |
|
||||
//! start() start()
|
||||
//! V V
|
||||
//! ..................| Overseer "runs" these |.......................
|
||||
//! ..................| Orchestra "runs" these |.......................
|
||||
//! . +--------------------+ +---------------------+ .
|
||||
//! . | SubsystemInstance1 | <-- bidir --> | SubsystemInstance2 | .
|
||||
//! . +--------------------+ +---------------------+ .
|
||||
@@ -60,15 +62,12 @@
|
||||
#![deny(missing_docs)]
|
||||
#![deny(unused_crate_dependencies)]
|
||||
|
||||
pub use polkadot_overseer_gen_proc_macro::{contextbounds, overlord, subsystem};
|
||||
pub use orchestra_proc_macro::{contextbounds, orchestra, subsystem};
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use gum;
|
||||
#[doc(hidden)]
|
||||
pub use metered;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use polkadot_node_primitives::SpawnNamed;
|
||||
pub use tracing;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use async_trait::async_trait;
|
||||
@@ -95,19 +94,40 @@ pub use std::time::Duration;
|
||||
#[doc(hidden)]
|
||||
pub use futures_timer::Delay;
|
||||
|
||||
pub use polkadot_node_network_protocol::WrongVariant;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
/// A type of messages that are sent from a [`Subsystem`] to the declared overseer.
|
||||
/// A spawner
|
||||
#[dyn_clonable::clonable]
|
||||
pub trait Spawner: Clone + Send + Sync {
|
||||
/// Spawn the given blocking future.
|
||||
///
|
||||
/// The given `group` and `name` is used to identify the future in tracing.
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
);
|
||||
/// Spawn the given non-blocking future.
|
||||
///
|
||||
/// The given `group` and `name` is used to identify the future in tracing.
|
||||
fn spawn(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
);
|
||||
}
|
||||
|
||||
/// A type of messages that are sent from a [`Subsystem`] to the declared orchestra.
|
||||
///
|
||||
/// Used to launch jobs.
|
||||
pub enum ToOverseer {
|
||||
pub enum ToOrchestra {
|
||||
/// A message that wraps something the `Subsystem` is desiring to
|
||||
/// spawn on the overseer and a `oneshot::Sender` to signal the result
|
||||
/// spawn on the orchestra and a `oneshot::Sender` to signal the result
|
||||
/// of the spawn.
|
||||
SpawnJob {
|
||||
/// Name of the task to spawn which be shown in jaeger and tracing logs.
|
||||
@@ -130,7 +150,7 @@ pub enum ToOverseer {
|
||||
},
|
||||
}
|
||||
|
||||
impl fmt::Debug for ToOverseer {
|
||||
impl fmt::Debug for ToOrchestra {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::SpawnJob { name, subsystem, .. } => {
|
||||
@@ -227,7 +247,7 @@ pub trait AnnotateErrorOrigin: 'static + Send + Sync + std::error::Error {
|
||||
/// In essence it's just a new type wrapping a `BoxFuture`.
|
||||
pub struct SpawnedSubsystem<E>
|
||||
where
|
||||
E: std::error::Error + Send + Sync + 'static + From<self::OverseerError>,
|
||||
E: std::error::Error + Send + Sync + 'static + From<self::OrchestraError>,
|
||||
{
|
||||
/// Name of the subsystem being spawned.
|
||||
pub name: &'static str,
|
||||
@@ -244,7 +264,7 @@ where
|
||||
/// * etc.
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum OverseerError {
|
||||
pub enum OrchestraError {
|
||||
#[error(transparent)]
|
||||
NotifyCancellation(#[from] oneshot::Canceled),
|
||||
|
||||
@@ -274,8 +294,8 @@ pub enum OverseerError {
|
||||
},
|
||||
}
|
||||
|
||||
/// Alias for a result with error type `OverseerError`.
|
||||
pub type OverseerResult<T> = std::result::Result<T, self::OverseerError>;
|
||||
/// Alias for a result with error type `OrchestraError`.
|
||||
pub type OrchestraResult<T> = std::result::Result<T, self::OrchestraError>;
|
||||
|
||||
/// Collection of meters related to a subsystem.
|
||||
#[derive(Clone)]
|
||||
@@ -329,14 +349,14 @@ pub struct SubsystemInstance<Message, Signal> {
|
||||
pub name: &'static str,
|
||||
}
|
||||
|
||||
/// A message type that a subsystem receives from an overseer.
|
||||
/// It wraps signals from an overseer and messages that are circulating
|
||||
/// A message type that a subsystem receives from an orchestra.
|
||||
/// It wraps signals from an orchestra and messages that are circulating
|
||||
/// between subsystems.
|
||||
///
|
||||
/// It is generic over over the message type `M` that a particular `Subsystem` may use.
|
||||
#[derive(Debug)]
|
||||
pub enum FromOverseer<Message, Signal> {
|
||||
/// Signal from the `Overseer`.
|
||||
pub enum FromOrchestra<Message, Signal> {
|
||||
/// Signal from the `Orchestra`.
|
||||
Signal(Signal),
|
||||
|
||||
/// Some other `Subsystem`'s message.
|
||||
@@ -346,7 +366,7 @@ pub enum FromOverseer<Message, Signal> {
|
||||
},
|
||||
}
|
||||
|
||||
impl<Signal, Message> From<Signal> for FromOverseer<Message, Signal> {
|
||||
impl<Signal, Message> From<Signal> for FromOrchestra<Message, Signal> {
|
||||
fn from(signal: Signal) -> Self {
|
||||
Self::Signal(signal)
|
||||
}
|
||||
@@ -356,7 +376,7 @@ impl<Signal, Message> From<Signal> for FromOverseer<Message, Signal> {
|
||||
/// It can be used by [`Subsystem`] to communicate with other [`Subsystem`]s
|
||||
/// or spawn jobs.
|
||||
///
|
||||
/// [`Overseer`]: struct.Overseer.html
|
||||
/// [`Orchestra`]: struct.Orchestra.html
|
||||
/// [`SubsystemJob`]: trait.SubsystemJob.html
|
||||
#[async_trait::async_trait]
|
||||
pub trait SubsystemContext: Send + 'static {
|
||||
@@ -375,16 +395,16 @@ pub trait SubsystemContext: Send + 'static {
|
||||
/// The sender type as provided by `sender()` and underlying.
|
||||
type Sender: Clone + Send + 'static + SubsystemSender<Self::OutgoingMessages>;
|
||||
/// The error type.
|
||||
type Error: ::std::error::Error + ::std::convert::From<OverseerError> + Sync + Send + 'static;
|
||||
type Error: ::std::error::Error + ::std::convert::From<OrchestraError> + Sync + Send + 'static;
|
||||
|
||||
/// Try to asynchronously receive a message.
|
||||
///
|
||||
/// Has to be used with caution, if you loop over this without
|
||||
/// using `pending!()` macro you will end up with a busy loop!
|
||||
async fn try_recv(&mut self) -> Result<Option<FromOverseer<Self::Message, Self::Signal>>, ()>;
|
||||
async fn try_recv(&mut self) -> Result<Option<FromOrchestra<Self::Message, Self::Signal>>, ()>;
|
||||
|
||||
/// Receive a message.
|
||||
async fn recv(&mut self) -> Result<FromOverseer<Self::Message, Self::Signal>, Self::Error>;
|
||||
async fn recv(&mut self) -> Result<FromOrchestra<Self::Message, Self::Signal>, Self::Error>;
|
||||
|
||||
/// Spawn a child task on the executor.
|
||||
fn spawn(
|
||||
@@ -438,18 +458,18 @@ pub trait SubsystemContext: Send + 'static {
|
||||
fn sender(&mut self) -> &mut Self::Sender;
|
||||
}
|
||||
|
||||
/// A trait that describes the [`Subsystem`]s that can run on the [`Overseer`].
|
||||
/// A trait that describes the [`Subsystem`]s that can run on the [`Orchestra`].
|
||||
///
|
||||
/// It is generic over the message type circulating in the system.
|
||||
/// The idea that we want some type containing persistent state that
|
||||
/// can spawn actually running subsystems when asked.
|
||||
///
|
||||
/// [`Overseer`]: struct.Overseer.html
|
||||
/// [`Orchestra`]: struct.Orchestra.html
|
||||
/// [`Subsystem`]: trait.Subsystem.html
|
||||
pub trait Subsystem<Ctx, E>
|
||||
where
|
||||
Ctx: SubsystemContext,
|
||||
E: std::error::Error + Send + Sync + 'static + From<self::OverseerError>,
|
||||
E: std::error::Error + Send + Sync + 'static + From<self::OrchestraError>,
|
||||
{
|
||||
/// Start this `Subsystem` and return `SpawnedSubsystem`.
|
||||
fn start(self, ctx: Ctx) -> SpawnedSubsystem<E>;
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use polkadot_overseer_gen::*;
|
||||
use orchestra::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct AwesomeSubSys;
|
||||
@@ -16,8 +16,8 @@ struct Event;
|
||||
#[derive(Clone)]
|
||||
struct MsgStrukt(u8);
|
||||
|
||||
#[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)]
|
||||
struct Overseer {
|
||||
#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)]
|
||||
struct Orchestra {
|
||||
#[subsystem(MsgStrukt)]
|
||||
sub0: AwesomeSubSys,
|
||||
|
||||
@@ -31,7 +31,7 @@ struct DummySpawner;
|
||||
struct DummyCtx;
|
||||
|
||||
fn main() {
|
||||
let overseer = Overseer::<_,_>::builder()
|
||||
let orchestra = Orchestra::<_,_>::builder()
|
||||
.sub0(AwesomeSubSys::default())
|
||||
.spawner(DummySpawner)
|
||||
.build(|| -> DummyCtx { DummyCtx } );
|
||||
@@ -0,0 +1,21 @@
|
||||
error[E0119]: conflicting implementations of trait `orchestra::SubsystemSender<MsgStrukt>` for type `OrchestraSubsystemSender`
|
||||
--> tests/ui/err-01-duplicate-consumer.rs:19:1
|
||||
|
|
||||
19 | #[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| first implementation here
|
||||
| conflicting implementation for `OrchestraSubsystemSender`
|
||||
|
|
||||
= note: this error originates in the attribute macro `orchestra` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0119]: conflicting implementations of trait `std::convert::From<MsgStrukt>` for type `AllMessages`
|
||||
--> tests/ui/err-01-duplicate-consumer.rs:19:1
|
||||
|
|
||||
19 | #[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| first implementation here
|
||||
| conflicting implementation for `AllMessages`
|
||||
|
|
||||
= note: this error originates in the attribute macro `orchestra` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use polkadot_overseer_gen::*;
|
||||
use orchestra::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct AwesomeSubSys;
|
||||
@@ -12,8 +12,8 @@ struct Event;
|
||||
#[derive(Clone, Debug)]
|
||||
struct MsgStrukt(u8);
|
||||
|
||||
#[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)]
|
||||
enum Overseer {
|
||||
#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)]
|
||||
enum Orchestra {
|
||||
#[subsystem(MsgStrukt)]
|
||||
Sub0(AwesomeSubSys),
|
||||
}
|
||||
@@ -24,7 +24,7 @@ struct DummySpawner;
|
||||
struct DummyCtx;
|
||||
|
||||
fn main() {
|
||||
let overseer = Overseer::<_,_>::builder()
|
||||
let orchestra = Orchestra::<_,_>::builder()
|
||||
.sub0(AwesomeSubSys::default())
|
||||
.i_like_pie(std::f64::consts::PI)
|
||||
.spawner(DummySpawner)
|
||||
@@ -0,0 +1,11 @@
|
||||
error: expected `struct`
|
||||
--> $DIR/err-02-enum.rs:16:1
|
||||
|
|
||||
16 | enum Orchestra {
|
||||
| ^^^^
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared type `Orchestra`
|
||||
--> $DIR/err-02-enum.rs:27:17
|
||||
|
|
||||
27 | let orchestra = Orchestra::<_,_>::builder()
|
||||
| ^^^^^^^^ use of undeclared type `Orchestra`
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use polkadot_overseer_gen::*;
|
||||
use orchestra::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct AwesomeSubSys;
|
||||
@@ -16,8 +16,8 @@ struct MsgStrukt(u8);
|
||||
#[derive(Clone, Debug)]
|
||||
struct MsgStrukt2(f64);
|
||||
|
||||
#[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)]
|
||||
struct Overseer {
|
||||
#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)]
|
||||
struct Orchestra {
|
||||
#[subsystem(MsgStrukt)]
|
||||
sub0: AwesomeSubSys,
|
||||
|
||||
@@ -31,7 +31,7 @@ struct DummySpawner;
|
||||
struct DummyCtx;
|
||||
|
||||
fn main() {
|
||||
let overseer = Overseer::<_,_>::builder()
|
||||
let orchestra = Orchestra::<_,_>::builder()
|
||||
.sub0(AwesomeSubSys::default())
|
||||
.i_like_pie(std::f64::consts::PI)
|
||||
.spawner(DummySpawner)
|
||||
+3
-3
@@ -10,8 +10,8 @@ error: previously defined here.
|
||||
22 | sub0: AwesomeSubSys,
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared type `Overseer`
|
||||
error[E0433]: failed to resolve: use of undeclared type `Orchestra`
|
||||
--> $DIR/err-03-subsys-twice.rs:34:17
|
||||
|
|
||||
34 | let overseer = Overseer::<_,_>::builder()
|
||||
| ^^^^^^^^ use of undeclared type `Overseer`
|
||||
34 | let orchestra = Orchestra::<_,_>::builder()
|
||||
| ^^^^^^^^ use of undeclared type `Orchestra`
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use polkadot_overseer_gen::*;
|
||||
use orchestra::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct AwesomeSubSys;
|
||||
@@ -13,8 +13,8 @@ struct Event;
|
||||
#[derive(Clone)]
|
||||
struct MsgStrukt(u8);
|
||||
|
||||
#[overlord(signal=SigSigSig, event=Event, gen=AllMessages)]
|
||||
struct Overseer {
|
||||
#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages)]
|
||||
struct Orchestra {
|
||||
#[subsystem(MsgStrukt)]
|
||||
sub0: AwesomeSubSys,
|
||||
|
||||
@@ -27,7 +27,7 @@ struct DummySpawner;
|
||||
struct DummyCtx;
|
||||
|
||||
fn main() {
|
||||
let _ = Overseer::builder()
|
||||
let _ = Orchestra::builder()
|
||||
.sub0(AwesomeSubSys::default())
|
||||
.i_like_pie(std::f64::consts::PI)
|
||||
.spawner(DummySpawner)
|
||||
@@ -0,0 +1,13 @@
|
||||
error: Must declare the orchestra error type via `error=..`.
|
||||
--> $DIR/err-04-missing-error.rs:16:1
|
||||
|
|
||||
16 | #[orchestra(signal=SigSigSig, event=Event, gen=AllMessages)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in the attribute macro `orchestra` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared type `Orchestra`
|
||||
--> $DIR/err-04-missing-error.rs:30:10
|
||||
|
|
||||
30 | let _ = Orchestra::builder()
|
||||
| ^^^^^^^^ use of undeclared type `Orchestra`
|
||||
+7
-7
@@ -1,12 +1,12 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use polkadot_overseer_gen::*;
|
||||
use orchestra::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct AwesomeSubSys;
|
||||
|
||||
impl ::polkadot_overseer_gen::Subsystem<OverseerSubsystemContext<MsgStrukt>, OverseerError> for AwesomeSubSys {
|
||||
fn start(self, _ctx: OverseerSubsystemContext<MsgStrukt>) -> SpawnedSubsystem<OverseerError> {
|
||||
impl ::orchestra::Subsystem<OrchestraSubsystemContext<MsgStrukt>, OrchestraError> for AwesomeSubSys {
|
||||
fn start(self, _ctx: OrchestraSubsystemContext<MsgStrukt>) -> SpawnedSubsystem<OrchestraError> {
|
||||
unimplemented!("starting yay!")
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,8 @@ pub struct Event;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MsgStrukt(u8);
|
||||
|
||||
#[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
|
||||
struct Overseer {
|
||||
#[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)]
|
||||
struct Orchestra {
|
||||
#[subsystem(MsgStrukt)]
|
||||
sub0: AwesomeSubSys,
|
||||
i_like_pie: f64,
|
||||
@@ -29,7 +29,7 @@ struct Overseer {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DummySpawner;
|
||||
|
||||
impl SpawnNamed for DummySpawner {
|
||||
impl Spawner for DummySpawner {
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
task_name: &'static str,
|
||||
@@ -52,7 +52,7 @@ impl SpawnNamed for DummySpawner {
|
||||
struct DummyCtx;
|
||||
|
||||
fn main() {
|
||||
let _ = Overseer::builder()
|
||||
let _ = Orchestra::builder()
|
||||
.sub0(AwesomeSubSys::default())
|
||||
//.i_like_pie(std::f64::consts::PI) // The filed is not initialised
|
||||
.spawner(DummySpawner)
|
||||
+4
-4
@@ -1,14 +1,14 @@
|
||||
error[E0599]: no method named `build` found for struct `OverseerBuilder<Init<DummySpawner>, Init<AwesomeSubSys>, Missing<f64>>` in the current scope
|
||||
error[E0599]: no method named `build` found for struct `OrchestraBuilder<Init<DummySpawner>, Init<AwesomeSubSys>, Missing<f64>>` in the current scope
|
||||
--> tests/ui/err-05-missing-field.rs:59:4
|
||||
|
|
||||
22 | #[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
|
||||
22 | #[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)]
|
||||
| -------------------------------------------------------------------------------- method `build` not found for this
|
||||
...
|
||||
59 | .build()
|
||||
| ^^^^^ method not found in `OverseerBuilder<Init<DummySpawner>, Init<AwesomeSubSys>, Missing<f64>>`
|
||||
| ^^^^^ method not found in `OrchestraBuilder<Init<DummySpawner>, Init<AwesomeSubSys>, Missing<f64>>`
|
||||
|
|
||||
= note: the method was found for
|
||||
- `OverseerBuilder<Init<S>, Init<AwesomeSubSys>, Init<f64>>`
|
||||
- `OrchestraBuilder<Init<S>, Init<AwesomeSubSys>, Init<f64>>`
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
= note: the following traits define an item `build`, perhaps you need to implement one of them:
|
||||
candidate #1: `frame_support::traits::hooks::GenesisBuild`
|
||||
+7
-7
@@ -1,12 +1,12 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use polkadot_overseer_gen::*;
|
||||
use orchestra::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct AwesomeSubSys;
|
||||
|
||||
impl ::polkadot_overseer_gen::Subsystem<OverseerSubsystemContext<MsgStrukt>, OverseerError> for AwesomeSubSys {
|
||||
fn start(self, _ctx: OverseerSubsystemContext<MsgStrukt>) -> SpawnedSubsystem<OverseerError> {
|
||||
impl ::orchestra::Subsystem<OrchestraSubsystemContext<MsgStrukt>, OrchestraError> for AwesomeSubSys {
|
||||
fn start(self, _ctx: OrchestraSubsystemContext<MsgStrukt>) -> SpawnedSubsystem<OrchestraError> {
|
||||
unimplemented!("starting yay!")
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,8 @@ pub struct Event;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MsgStrukt(u8);
|
||||
|
||||
#[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
|
||||
struct Overseer {
|
||||
#[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)]
|
||||
struct Orchestra {
|
||||
#[subsystem(MsgStrukt)]
|
||||
sub0: AwesomeSubSys,
|
||||
i_like_pie: f64,
|
||||
@@ -29,7 +29,7 @@ struct Overseer {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DummySpawner;
|
||||
|
||||
impl SpawnNamed for DummySpawner {
|
||||
impl Spawner for DummySpawner {
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
task_name: &'static str,
|
||||
@@ -52,7 +52,7 @@ impl SpawnNamed for DummySpawner {
|
||||
struct DummyCtx;
|
||||
|
||||
fn main() {
|
||||
let _ = Overseer::builder()
|
||||
let _ = Orchestra::builder()
|
||||
//.sub0(AwesomeSubSys::default()) // Subsystem is uninitialized
|
||||
.i_like_pie(std::f64::consts::PI)
|
||||
.spawner(DummySpawner)
|
||||
+4
-4
@@ -1,14 +1,14 @@
|
||||
error[E0599]: no method named `build` found for struct `OverseerBuilder<Init<DummySpawner>, Missing<_>, Init<f64>>` in the current scope
|
||||
error[E0599]: no method named `build` found for struct `OrchestraBuilder<Init<DummySpawner>, Missing<_>, Init<f64>>` in the current scope
|
||||
--> tests/ui/err-06-missing-subsystem.rs:59:4
|
||||
|
|
||||
22 | #[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
|
||||
22 | #[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)]
|
||||
| -------------------------------------------------------------------------------- method `build` not found for this
|
||||
...
|
||||
59 | .build()
|
||||
| ^^^^^ method not found in `OverseerBuilder<Init<DummySpawner>, Missing<_>, Init<f64>>`
|
||||
| ^^^^^ method not found in `OrchestraBuilder<Init<DummySpawner>, Missing<_>, Init<f64>>`
|
||||
|
|
||||
= note: the method was found for
|
||||
- `OverseerBuilder<Init<S>, Init<AwesomeSubSys>, Init<f64>>`
|
||||
- `OrchestraBuilder<Init<S>, Init<AwesomeSubSys>, Init<f64>>`
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
= note: the following traits define an item `build`, perhaps you need to implement one of them:
|
||||
candidate #1: `frame_support::traits::hooks::GenesisBuild`
|
||||
+7
-7
@@ -1,12 +1,12 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use polkadot_overseer_gen::*;
|
||||
use orchestra::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct AwesomeSubSys;
|
||||
|
||||
impl ::polkadot_overseer_gen::Subsystem<OverseerSubsystemContext<MsgStrukt>, OverseerError> for AwesomeSubSys {
|
||||
fn start(self, _ctx: OverseerSubsystemContext<MsgStrukt>) -> SpawnedSubsystem<OverseerError> {
|
||||
impl ::orchestra::Subsystem<OrchestraSubsystemContext<MsgStrukt>, OrchestraError> for AwesomeSubSys {
|
||||
fn start(self, _ctx: OrchestraSubsystemContext<MsgStrukt>) -> SpawnedSubsystem<OrchestraError> {
|
||||
unimplemented!("starting yay!")
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,8 @@ pub struct Event;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MsgStrukt(u8);
|
||||
|
||||
#[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
|
||||
struct Overseer {
|
||||
#[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)]
|
||||
struct Orchestra {
|
||||
#[subsystem(MsgStrukt)]
|
||||
sub0: AwesomeSubSys,
|
||||
i_like_pie: f64,
|
||||
@@ -29,7 +29,7 @@ struct Overseer {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DummySpawner;
|
||||
|
||||
impl SpawnNamed for DummySpawner {
|
||||
impl Spawner for DummySpawner {
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
task_name: &'static str,
|
||||
@@ -52,7 +52,7 @@ impl SpawnNamed for DummySpawner {
|
||||
struct DummyCtx;
|
||||
|
||||
fn main() {
|
||||
let _ = Overseer::builder()
|
||||
let _ = Orchestra::builder()
|
||||
.sub0(AwesomeSubSys::default())
|
||||
.i_like_pie(std::f64::consts::PI)
|
||||
//.spawner(DummySpawner) // Spawner is missing
|
||||
+4
-4
@@ -1,14 +1,14 @@
|
||||
error[E0599]: no method named `build` found for struct `OverseerBuilder<Missing<_>, Init<AwesomeSubSys>, Init<f64>>` in the current scope
|
||||
error[E0599]: no method named `build` found for struct `OrchestraBuilder<Missing<_>, Init<AwesomeSubSys>, Init<f64>>` in the current scope
|
||||
--> tests/ui/err-07-missing-spawner.rs:59:4
|
||||
|
|
||||
22 | #[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
|
||||
22 | #[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)]
|
||||
| -------------------------------------------------------------------------------- method `build` not found for this
|
||||
...
|
||||
59 | .build()
|
||||
| ^^^^^ method not found in `OverseerBuilder<Missing<_>, Init<AwesomeSubSys>, Init<f64>>`
|
||||
| ^^^^^ method not found in `OrchestraBuilder<Missing<_>, Init<AwesomeSubSys>, Init<f64>>`
|
||||
|
|
||||
= note: the method was found for
|
||||
- `OverseerBuilder<Init<S>, Init<AwesomeSubSys>, Init<f64>>`
|
||||
- `OrchestraBuilder<Init<S>, Init<AwesomeSubSys>, Init<f64>>`
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
= note: the following traits define an item `build`, perhaps you need to implement one of them:
|
||||
candidate #1: `frame_support::traits::hooks::GenesisBuild`
|
||||
+7
-7
@@ -1,12 +1,12 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use polkadot_overseer_gen::*;
|
||||
use orchestra::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct AwesomeSubSys;
|
||||
|
||||
impl ::polkadot_overseer_gen::Subsystem<OverseerSubsystemContext<MsgStrukt>, OverseerError> for AwesomeSubSys {
|
||||
fn start(self, _ctx: OverseerSubsystemContext<MsgStrukt>) -> SpawnedSubsystem<OverseerError> {
|
||||
impl ::orchestra::Subsystem<OrchestraSubsystemContext<MsgStrukt>, OrchestraError> for AwesomeSubSys {
|
||||
fn start(self, _ctx: OrchestraSubsystemContext<MsgStrukt>) -> SpawnedSubsystem<OrchestraError> {
|
||||
unimplemented!("starting yay!")
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,8 @@ pub struct Event;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MsgStrukt(u8);
|
||||
|
||||
#[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
|
||||
struct Overseer {
|
||||
#[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)]
|
||||
struct Orchestra {
|
||||
#[subsystem(MsgStrukt)]
|
||||
sub0: AwesomeSubSys,
|
||||
i_like_pie: f64,
|
||||
@@ -29,7 +29,7 @@ struct Overseer {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DummySpawner;
|
||||
|
||||
impl SpawnNamed for DummySpawner {
|
||||
impl Spawner for DummySpawner {
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
task_name: &'static str,
|
||||
@@ -52,7 +52,7 @@ impl SpawnNamed for DummySpawner {
|
||||
struct DummyCtx;
|
||||
|
||||
fn main() {
|
||||
let _ = Overseer::builder()
|
||||
let _ = Orchestra::builder()
|
||||
.sub0(AwesomeSubSys::default())
|
||||
.sub0(AwesomeSubSys::default()) // Duplicate subsystem
|
||||
.i_like_pie(std::f64::consts::PI)
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
error[E0599]: no method named `sub0` found for struct `OverseerBuilder<Missing<_>, Init<AwesomeSubSys>, Missing<f64>>` in the current scope
|
||||
error[E0599]: no method named `sub0` found for struct `OrchestraBuilder<Missing<_>, Init<AwesomeSubSys>, Missing<f64>>` in the current scope
|
||||
--> tests/ui/err-08-duplicate-subsystem.rs:57:4
|
||||
|
|
||||
22 | #[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
|
||||
22 | #[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)]
|
||||
| -------------------------------------------------------------------------------- method `sub0` not found for this
|
||||
...
|
||||
57 | .sub0(AwesomeSubSys::default()) // Duplicate subsystem
|
||||
+7
-7
@@ -1,12 +1,12 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use polkadot_overseer_gen::*;
|
||||
use orchestra::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct AwesomeSubSys;
|
||||
|
||||
impl ::polkadot_overseer_gen::Subsystem<OverseerSubsystemContext<MsgStrukt>, OverseerError> for AwesomeSubSys {
|
||||
fn start(self, _ctx: OverseerSubsystemContext<MsgStrukt>) -> SpawnedSubsystem<OverseerError> {
|
||||
impl ::orchestra::Subsystem<OrchestraSubsystemContext<MsgStrukt>, OrchestraError> for AwesomeSubSys {
|
||||
fn start(self, _ctx: OrchestraSubsystemContext<MsgStrukt>) -> SpawnedSubsystem<OrchestraError> {
|
||||
unimplemented!("starting yay!")
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,8 @@ pub struct Event;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MsgStrukt(u8);
|
||||
|
||||
#[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
|
||||
struct Overseer<T> {
|
||||
#[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)]
|
||||
struct Orchestra<T> {
|
||||
#[subsystem(MsgStrukt)]
|
||||
sub0: AwesomeSubSys,
|
||||
i_like_pie: T,
|
||||
@@ -29,7 +29,7 @@ struct Overseer<T> {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DummySpawner;
|
||||
|
||||
impl SpawnNamed for DummySpawner {
|
||||
impl Spawner for DummySpawner {
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
task_name: &'static str,
|
||||
@@ -52,7 +52,7 @@ impl SpawnNamed for DummySpawner {
|
||||
struct DummyCtx;
|
||||
|
||||
fn main() {
|
||||
let (_, _): (Overseer<_, f64>, _) = Overseer::builder()
|
||||
let (_, _): (Orchestra<_, f64>, _) = Orchestra::builder()
|
||||
.sub0(AwesomeSubSys::default())
|
||||
//.i_like_pie(std::f64::consts::PI) // The filed is not initialised
|
||||
.spawner(DummySpawner)
|
||||
+4
-4
@@ -1,14 +1,14 @@
|
||||
error[E0599]: no method named `build` found for struct `OverseerBuilder<Init<DummySpawner>, Init<AwesomeSubSys>, Missing<_>>` in the current scope
|
||||
error[E0599]: no method named `build` found for struct `OrchestraBuilder<Init<DummySpawner>, Init<AwesomeSubSys>, Missing<_>>` in the current scope
|
||||
--> tests/ui/err-09-uninit_generic_baggage.rs:59:4
|
||||
|
|
||||
22 | #[overlord(signal=SigSigSig, error=OverseerError, event=Event, gen=AllMessages)]
|
||||
22 | #[orchestra(signal=SigSigSig, error=OrchestraError, event=Event, gen=AllMessages)]
|
||||
| -------------------------------------------------------------------------------- method `build` not found for this
|
||||
...
|
||||
59 | .build()
|
||||
| ^^^^^ method not found in `OverseerBuilder<Init<DummySpawner>, Init<AwesomeSubSys>, Missing<_>>`
|
||||
| ^^^^^ method not found in `OrchestraBuilder<Init<DummySpawner>, Init<AwesomeSubSys>, Missing<_>>`
|
||||
|
|
||||
= note: the method was found for
|
||||
- `OverseerBuilder<Init<S>, Init<AwesomeSubSys>, Init<T>>`
|
||||
- `OrchestraBuilder<Init<S>, Init<AwesomeSubSys>, Init<T>>`
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
= note: the following traits define an item `build`, perhaps you need to implement one of them:
|
||||
candidate #1: `frame_support::traits::hooks::GenesisBuild`
|
||||
+9
-9
@@ -1,18 +1,18 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use polkadot_overseer_gen::*;
|
||||
use orchestra::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct AwesomeSubSysA;
|
||||
|
||||
|
||||
impl ::polkadot_overseer_gen::Subsystem<OverseerSubsystemContext<MsgA>, OverseerError> for AwesomeSubSysA {
|
||||
fn start(self, _ctx: OverseerSubsystemContext<MsgA>) -> SpawnedSubsystem<OverseerError> {
|
||||
impl ::orchestra::Subsystem<OrchestraSubsystemContext<MsgA>, OrchestraError> for AwesomeSubSysA {
|
||||
fn start(self, _ctx: OrchestraSubsystemContext<MsgA>) -> SpawnedSubsystem<OrchestraError> {
|
||||
SpawnedSubsystem { name: "sub A", future: Box::pin(async move { Ok(()) }) }
|
||||
}
|
||||
}
|
||||
impl ::polkadot_overseer_gen::Subsystem<OverseerSubsystemContext<MsgB>, OverseerError> for AwesomeSubSysB {
|
||||
fn start(self, _ctx: OverseerSubsystemContext<MsgB>) -> SpawnedSubsystem<OverseerError> {
|
||||
impl ::orchestra::Subsystem<OrchestraSubsystemContext<MsgB>, OrchestraError> for AwesomeSubSysB {
|
||||
fn start(self, _ctx: OrchestraSubsystemContext<MsgB>) -> SpawnedSubsystem<OrchestraError> {
|
||||
SpawnedSubsystem { name: "sub B", future: Box::pin(async move { Ok(()) }) }
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ impl ::polkadot_overseer_gen::Subsystem<OverseerSubsystemContext<MsgB>, Overseer
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DummySpawner;
|
||||
|
||||
impl SpawnNamed for DummySpawner {
|
||||
impl Spawner for DummySpawner {
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
task_name: &'static str,
|
||||
@@ -54,8 +54,8 @@ pub struct MsgA(u8);
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MsgB(u8);
|
||||
|
||||
#[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)]
|
||||
pub struct Overseer {
|
||||
#[orchestra(signal=SigSigSig, event=Event, gen=AllMessages, error=OrchestraError)]
|
||||
pub struct Orchestra {
|
||||
#[subsystem(MsgA)]
|
||||
sub_a: AwesomeSubSysA,
|
||||
|
||||
@@ -66,7 +66,7 @@ pub struct Overseer {
|
||||
pub struct DummyCtx;
|
||||
|
||||
fn main() {
|
||||
let _overseer_builder = Overseer::builder()
|
||||
let _orchestra_builder = Orchestra::builder()
|
||||
.sub_a(AwesomeSubSysA::default())
|
||||
// b is tagged as `wip`
|
||||
// .sub_b(AwesomeSubSysB::default())
|
||||
@@ -1,21 +0,0 @@
|
||||
error[E0119]: conflicting implementations of trait `polkadot_overseer_gen::SubsystemSender<MsgStrukt>` for type `OverseerSubsystemSender`
|
||||
--> tests/ui/err-01-duplicate-consumer.rs:19:1
|
||||
|
|
||||
19 | #[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| first implementation here
|
||||
| conflicting implementation for `OverseerSubsystemSender`
|
||||
|
|
||||
= note: this error originates in the attribute macro `overlord` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0119]: conflicting implementations of trait `std::convert::From<MsgStrukt>` for type `AllMessages`
|
||||
--> tests/ui/err-01-duplicate-consumer.rs:19:1
|
||||
|
|
||||
19 | #[overlord(signal=SigSigSig, event=Event, gen=AllMessages, error=OverseerError)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| first implementation here
|
||||
| conflicting implementation for `AllMessages`
|
||||
|
|
||||
= note: this error originates in the attribute macro `overlord` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
@@ -1,11 +0,0 @@
|
||||
error: expected `struct`
|
||||
--> $DIR/err-02-enum.rs:16:1
|
||||
|
|
||||
16 | enum Overseer {
|
||||
| ^^^^
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared type `Overseer`
|
||||
--> $DIR/err-02-enum.rs:27:17
|
||||
|
|
||||
27 | let overseer = Overseer::<_,_>::builder()
|
||||
| ^^^^^^^^ use of undeclared type `Overseer`
|
||||
@@ -1,13 +0,0 @@
|
||||
error: Must declare the overseer error type via `error=..`.
|
||||
--> $DIR/err-04-missing-error.rs:16:1
|
||||
|
|
||||
16 | #[overlord(signal=SigSigSig, event=Event, gen=AllMessages)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this error originates in the attribute macro `overlord` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0433]: failed to resolve: use of undeclared type `Overseer`
|
||||
--> $DIR/err-04-missing-error.rs:30:10
|
||||
|
|
||||
30 | let _ = Overseer::builder()
|
||||
| ^^^^^^^^ use of undeclared type `Overseer`
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
use crate::{
|
||||
prometheus::Registry, HeadSupportsParachains, InitializedOverseerBuilder, MetricsTrait,
|
||||
Overseer, OverseerMetrics, OverseerSignal, OverseerSubsystemContext, SpawnNamed,
|
||||
Overseer, OverseerMetrics, OverseerSignal, OverseerSubsystemContext, SpawnGlue,
|
||||
KNOWN_LEAVES_CACHE_SIZE,
|
||||
};
|
||||
use lru::LruCache;
|
||||
use orchestra::{FromOrchestra, SpawnedSubsystem, Subsystem, SubsystemContext};
|
||||
use polkadot_node_subsystem_types::{errors::SubsystemError, messages::*};
|
||||
use polkadot_overseer_gen::{FromOverseer, SpawnedSubsystem, Subsystem, SubsystemContext};
|
||||
|
||||
/// A dummy subsystem that implements [`Subsystem`] for all
|
||||
/// types of messages. Used for tests or as a placeholder.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -37,7 +36,7 @@ where
|
||||
loop {
|
||||
match ctx.recv().await {
|
||||
Err(_) => return Ok(()),
|
||||
Ok(FromOverseer::Signal(OverseerSignal::Conclude)) => return Ok(()),
|
||||
Ok(FromOrchestra::Signal(OverseerSignal::Conclude)) => return Ok(()),
|
||||
Ok(overseer_msg) => {
|
||||
gum::debug!(
|
||||
target: "dummy-subsystem",
|
||||
@@ -63,7 +62,7 @@ pub fn dummy_overseer_builder<'a, Spawner, SupportsParachains>(
|
||||
registry: Option<&'a Registry>,
|
||||
) -> Result<
|
||||
InitializedOverseerBuilder<
|
||||
Spawner,
|
||||
SpawnGlue<Spawner>,
|
||||
SupportsParachains,
|
||||
DummySubsystem,
|
||||
DummySubsystem,
|
||||
@@ -90,7 +89,7 @@ pub fn dummy_overseer_builder<'a, Spawner, SupportsParachains>(
|
||||
SubsystemError,
|
||||
>
|
||||
where
|
||||
Spawner: SpawnNamed + Send + Sync + 'static,
|
||||
SpawnGlue<Spawner>: orchestra::Spawner + 'static,
|
||||
SupportsParachains: HeadSupportsParachains,
|
||||
{
|
||||
one_for_all_overseer_builder(spawner, supports_parachains, DummySubsystem, registry)
|
||||
@@ -104,7 +103,7 @@ pub fn one_for_all_overseer_builder<'a, Spawner, SupportsParachains, Sub>(
|
||||
registry: Option<&'a Registry>,
|
||||
) -> Result<
|
||||
InitializedOverseerBuilder<
|
||||
Spawner,
|
||||
SpawnGlue<Spawner>,
|
||||
SupportsParachains,
|
||||
Sub,
|
||||
Sub,
|
||||
@@ -131,7 +130,7 @@ pub fn one_for_all_overseer_builder<'a, Spawner, SupportsParachains, Sub>(
|
||||
SubsystemError,
|
||||
>
|
||||
where
|
||||
Spawner: SpawnNamed + Send + Sync + 'static,
|
||||
SpawnGlue<Spawner>: orchestra::Spawner + 'static,
|
||||
SupportsParachains: HeadSupportsParachains,
|
||||
Sub: Clone
|
||||
+ Subsystem<OverseerSubsystemContext<AvailabilityDistributionMessage>, SubsystemError>
|
||||
@@ -185,7 +184,7 @@ where
|
||||
.active_leaves(Default::default())
|
||||
.known_leaves(LruCache::new(KNOWN_LEAVES_CACHE_SIZE))
|
||||
.leaves(Default::default())
|
||||
.spawner(spawner)
|
||||
.spawner(SpawnGlue(spawner))
|
||||
.metrics(metrics)
|
||||
.supports_parachains(supports_parachains);
|
||||
Ok(builder)
|
||||
|
||||
@@ -105,11 +105,12 @@ pub use polkadot_node_metrics::{
|
||||
|
||||
use parity_util_mem::MemoryAllocationTracker;
|
||||
|
||||
pub use polkadot_overseer_gen as gen;
|
||||
pub use polkadot_overseer_gen::{
|
||||
contextbounds, overlord, subsystem, FromOverseer, MapSubsystem, MessagePacket, SignalsReceived,
|
||||
SpawnNamed, Subsystem, SubsystemContext, SubsystemIncomingMessages, SubsystemInstance,
|
||||
SubsystemMeterReadouts, SubsystemMeters, SubsystemSender, TimeoutExt, ToOverseer,
|
||||
pub use orchestra as gen;
|
||||
pub use orchestra::{
|
||||
contextbounds, orchestra, subsystem, FromOrchestra, MapSubsystem, MessagePacket,
|
||||
SignalsReceived, Spawner, Subsystem, SubsystemContext, SubsystemIncomingMessages,
|
||||
SubsystemInstance, SubsystemMeterReadouts, SubsystemMeters, SubsystemSender, TimeoutExt,
|
||||
ToOrchestra,
|
||||
};
|
||||
|
||||
/// Store 2 days worth of blocks, not accounting for forks,
|
||||
@@ -119,6 +120,42 @@ pub const KNOWN_LEAVES_CACHE_SIZE: usize = 2 * 24 * 3600 / 6;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
use sp_core::traits::SpawnNamed;
|
||||
|
||||
/// Glue to connect `trait orchestra::Spawner` and `SpawnNamed` from `substrate`.
|
||||
pub struct SpawnGlue<S>(pub S);
|
||||
|
||||
impl<S> AsRef<S> for SpawnGlue<S> {
|
||||
fn as_ref(&self) -> &S {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Clone> Clone for SpawnGlue<S> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: SpawnNamed + Clone + Send + Sync> crate::gen::Spawner for SpawnGlue<S> {
|
||||
fn spawn_blocking(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
) {
|
||||
SpawnNamed::spawn_blocking(&self.0, name, group, future)
|
||||
}
|
||||
fn spawn(
|
||||
&self,
|
||||
name: &'static str,
|
||||
group: Option<&'static str>,
|
||||
future: futures::future::BoxFuture<'static, ()>,
|
||||
) {
|
||||
SpawnNamed::spawn(&self.0, name, group, future)
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a header supports parachain consensus or not.
|
||||
pub trait HeadSupportsParachains {
|
||||
/// Return true if the given header supports parachain consensus. Otherwise, false.
|
||||
@@ -346,7 +383,7 @@ pub async fn forward_events<P: BlockchainEvents<Block>>(client: Arc<P>, mut hand
|
||||
/// # SubsystemError,
|
||||
/// # gen::{
|
||||
/// # SubsystemContext,
|
||||
/// # FromOverseer,
|
||||
/// # FromOrchestra,
|
||||
/// # SpawnedSubsystem,
|
||||
/// # },
|
||||
/// # };
|
||||
@@ -408,7 +445,7 @@ pub async fn forward_events<P: BlockchainEvents<Block>>(client: Arc<P>, mut hand
|
||||
/// # });
|
||||
/// # }
|
||||
/// ```
|
||||
#[overlord(
|
||||
#[orchestra(
|
||||
gen=AllMessages,
|
||||
event=Event,
|
||||
signal=OverseerSignal,
|
||||
@@ -594,15 +631,15 @@ pub fn spawn_metronome_metrics<S, SupportsParachains>(
|
||||
metronome_metrics: OverseerMetrics,
|
||||
) -> Result<(), SubsystemError>
|
||||
where
|
||||
S: SpawnNamed,
|
||||
S: Spawner,
|
||||
SupportsParachains: HeadSupportsParachains,
|
||||
{
|
||||
struct ExtractNameAndMeters;
|
||||
|
||||
impl<'a, T: 'a> MapSubsystem<&'a OverseenSubsystem<T>> for ExtractNameAndMeters {
|
||||
impl<'a, T: 'a> MapSubsystem<&'a OrchestratedSubsystem<T>> for ExtractNameAndMeters {
|
||||
type Output = Option<(&'static str, SubsystemMeters)>;
|
||||
|
||||
fn map_subsystem(&self, subsystem: &'a OverseenSubsystem<T>) -> Self::Output {
|
||||
fn map_subsystem(&self, subsystem: &'a OrchestratedSubsystem<T>) -> Self::Output {
|
||||
subsystem
|
||||
.instance
|
||||
.as_ref()
|
||||
@@ -662,7 +699,7 @@ where
|
||||
impl<S, SupportsParachains> Overseer<S, SupportsParachains>
|
||||
where
|
||||
SupportsParachains: HeadSupportsParachains,
|
||||
S: SpawnNamed,
|
||||
S: Spawner,
|
||||
{
|
||||
/// Stop the `Overseer`.
|
||||
async fn stop(mut self) {
|
||||
@@ -707,12 +744,12 @@ where
|
||||
}
|
||||
}
|
||||
},
|
||||
msg = self.to_overseer_rx.select_next_some() => {
|
||||
msg = self.to_orchestra_rx.select_next_some() => {
|
||||
match msg {
|
||||
ToOverseer::SpawnJob { name, subsystem, s } => {
|
||||
ToOrchestra::SpawnJob { name, subsystem, s } => {
|
||||
self.spawn_job(name, subsystem, s);
|
||||
}
|
||||
ToOverseer::SpawnBlockingJob { name, subsystem, s } => {
|
||||
ToOrchestra::SpawnBlockingJob { name, subsystem, s } => {
|
||||
self.spawn_blocking_job(name, subsystem, s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,12 +70,12 @@ where
|
||||
let mut i = 0;
|
||||
loop {
|
||||
match ctx.recv().await {
|
||||
Ok(FromOverseer::Communication { .. }) => {
|
||||
Ok(FromOrchestra::Communication { .. }) => {
|
||||
let _ = sender.send(i).await;
|
||||
i += 1;
|
||||
continue
|
||||
},
|
||||
Ok(FromOverseer::Signal(OverseerSignal::Conclude)) => return Ok(()),
|
||||
Ok(FromOrchestra::Signal(OverseerSignal::Conclude)) => return Ok(()),
|
||||
Err(_) => return Ok(()),
|
||||
_ => (),
|
||||
}
|
||||
@@ -121,7 +121,7 @@ where
|
||||
continue
|
||||
}
|
||||
match ctx.try_recv().await {
|
||||
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => break,
|
||||
Ok(Some(FromOrchestra::Signal(OverseerSignal::Conclude))) => break,
|
||||
Ok(Some(_)) => continue,
|
||||
Err(_) => return Ok(()),
|
||||
_ => (),
|
||||
@@ -318,8 +318,8 @@ where
|
||||
future: Box::pin(async move {
|
||||
loop {
|
||||
match ctx.try_recv().await {
|
||||
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => break,
|
||||
Ok(Some(FromOverseer::Signal(s))) => {
|
||||
Ok(Some(FromOrchestra::Signal(OverseerSignal::Conclude))) => break,
|
||||
Ok(Some(FromOrchestra::Signal(s))) => {
|
||||
sender.send(s).await.unwrap();
|
||||
continue
|
||||
},
|
||||
@@ -350,8 +350,8 @@ where
|
||||
future: Box::pin(async move {
|
||||
loop {
|
||||
match ctx.try_recv().await {
|
||||
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => break,
|
||||
Ok(Some(FromOverseer::Signal(s))) => {
|
||||
Ok(Some(FromOrchestra::Signal(OverseerSignal::Conclude))) => break,
|
||||
Ok(Some(FromOrchestra::Signal(s))) => {
|
||||
sender.send(s).await.unwrap();
|
||||
continue
|
||||
},
|
||||
@@ -754,15 +754,15 @@ where
|
||||
future: Box::pin(async move {
|
||||
loop {
|
||||
match ctx.try_recv().await {
|
||||
Ok(Some(FromOverseer::Signal(OverseerSignal::Conclude))) => {
|
||||
Ok(Some(FromOrchestra::Signal(OverseerSignal::Conclude))) => {
|
||||
self.stop_signals_received.fetch_add(1, atomic::Ordering::SeqCst);
|
||||
break
|
||||
},
|
||||
Ok(Some(FromOverseer::Signal(_))) => {
|
||||
Ok(Some(FromOrchestra::Signal(_))) => {
|
||||
self.signals_received.fetch_add(1, atomic::Ordering::SeqCst);
|
||||
continue
|
||||
},
|
||||
Ok(Some(FromOverseer::Communication { .. })) => {
|
||||
Ok(Some(FromOrchestra::Communication { .. })) => {
|
||||
self.msgs_received.fetch_add(1, atomic::Ordering::SeqCst);
|
||||
continue
|
||||
},
|
||||
@@ -1139,7 +1139,7 @@ fn context_holds_onto_message_until_enough_signals_received() {
|
||||
|
||||
let test_fut = async move {
|
||||
signal_tx.send(OverseerSignal::Conclude).await.unwrap();
|
||||
assert_matches!(ctx.recv().await.unwrap(), FromOverseer::Signal(OverseerSignal::Conclude));
|
||||
assert_matches!(ctx.recv().await.unwrap(), FromOrchestra::Signal(OverseerSignal::Conclude));
|
||||
|
||||
assert_eq!(ctx.signals_received.load(), 1);
|
||||
bounded_tx
|
||||
@@ -1158,9 +1158,9 @@ fn context_holds_onto_message_until_enough_signals_received() {
|
||||
assert!(ctx.pending_incoming.is_some());
|
||||
|
||||
signal_tx.send(OverseerSignal::Conclude).await.unwrap();
|
||||
assert_matches!(ctx.recv().await.unwrap(), FromOverseer::Signal(OverseerSignal::Conclude));
|
||||
assert_matches!(ctx.recv().await.unwrap(), FromOverseer::Communication { msg: () });
|
||||
assert_matches!(ctx.recv().await.unwrap(), FromOverseer::Communication { msg: () });
|
||||
assert_matches!(ctx.recv().await.unwrap(), FromOrchestra::Signal(OverseerSignal::Conclude));
|
||||
assert_matches!(ctx.recv().await.unwrap(), FromOrchestra::Communication { msg: () });
|
||||
assert_matches!(ctx.recv().await.unwrap(), FromOrchestra::Communication { msg: () });
|
||||
assert!(ctx.pending_incoming.is_none());
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user