Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make orchestra compile as standalone
  • Loading branch information
drahnr committed May 19, 2022
commit 1c1f518441a74498146fb12fe34668d9ffb64e8f
71 changes: 34 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/metered-channel/src/oneshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<T> Future for MeteredReceiver<T> {
.get_or_insert_with(move || Delay::new(soft_timeout).fuse());

if Pin::new(soft_timeout).poll(ctx).is_ready() {
gum::warn!("Oneshot `{name}` exceeded the soft threshold", name = &self.name);
tracing::warn!(target: "oneshot", "Oneshot `{name}` exceeded the soft threshold", name = &self.name);
}

let hard_timeout = self.hard_timeout.clone().into();
Expand Down
4 changes: 0 additions & 4 deletions node/overseer/orchestra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ async-trait = "0.1"
thiserror = "1"
metered = { package = "metered-channel", path = "../../metered-channel" }
orchestra-proc-macro = { path = "./proc-macro" }
polkadot-node-network-protocol = { path = "../../network/protocol"}
# FIXME TODO
# trait Spawner
polkadot-node-primitives = { path = "../../primitives" }
futures-timer = "3.0.2"
pin-project = "1.0"

Expand Down
12 changes: 6 additions & 6 deletions node/overseer/orchestra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ where at it's core it creates and spawns a set of subsystems, which are purely
declarative.

```rust
#[orchestra(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, sends: [MsgB])]
sub_a: AwesomeSubSysA,

Expand Down Expand Up @@ -40,7 +40,7 @@ into the overseer, without participating in the subsystem pattern.
pub struct DummySpawner;

fn main() {
let _overseer = Overseer::builder()
let _overseer = Orchestra::builder()
.sub_a(AwesomeSubSysA::default())
.sub_b(AwesomeSubSysB::default())
.spawner(DummySpawner)
Expand All @@ -61,11 +61,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
#[orchestra(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, sends: MsgB)]
sub_a: AwesomeSubSysA,

Expand Down
4 changes: 2 additions & 2 deletions node/overseer/orchestra/examples/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ impl std::fmt::Display for Yikes {

impl std::error::Error for Yikes {}

impl From<orchestra::OverseerError> for Yikes {
fn from(_: orchestra::OverseerError) -> Yikes {
impl From<orchestra::OrchestraError> for Yikes {
fn from(_: orchestra::OrchestraError) -> Yikes {
Yikes
}
}
Expand Down
32 changes: 16 additions & 16 deletions node/overseer/orchestra/proc-macro/src/impl_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ fn recollect_without_idx<T: Clone>(x: &[T], idx: usize) -> Vec<T> {
v
}

/// Implement a builder pattern for the `Overseer`-type,
/// Implement a builder pattern for the `Orchestra`-type,
/// which acts as the gateway to constructing the overseer.
///
/// Elements tagged with `wip` are not covered here.
pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
pub(crate) fn impl_builder(info: &OrchestraInfo) -> proc_macro2::TokenStream {
let overseer_name = info.overseer_name.clone();
let builder = format_ident!("{}Builder", overseer_name);
let handle = format_ident!("{}Handle", overseer_name);
Expand Down Expand Up @@ -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, )*
};
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 >();
Expand Down Expand Up @@ -560,7 +560,7 @@ 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
ToOrchestra
>();

#(
Expand Down Expand Up @@ -622,7 +622,7 @@ pub(crate) fn impl_builder(info: &OverseerInfo) -> proc_macro2::TokenStream {
#subsystem_name_str_literal
);

let #subsystem_name: OverseenSubsystem< #consumes > =
let #subsystem_name: OrchestratedSubsystem< #consumes > =
spawn::<_,_, #blocking, _, _, _>(
&mut spawner,
#channel_name_tx,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 ::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 + From<#support_crate ::OrchestraError>,
SubSys: #support_crate ::Subsystem<Ctx, E>,
{
let #support_crate ::SpawnedSubsystem::<E> { future, name } = s.start(ctx);
Expand All @@ -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(());
});
Expand All @@ -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");
tracing::warn!(err = ?e, "dropping error");
Ok(())
})
));
Expand All @@ -749,7 +749,7 @@ pub(crate) fn impl_task_kind(info: &OverseerInfo) -> proc_macro2::TokenStream {
name,
});

Ok(OverseenSubsystem {
Ok(OrchestratedSubsystem {
instance,
})
}
Expand Down
10 changes: 5 additions & 5 deletions node/overseer/orchestra/proc-macro/src/impl_channels_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading