From f4cffcf7575c0739d0d0c0970962333627bbafdf Mon Sep 17 00:00:00 2001 From: Bernhard Schuster Date: Mon, 14 Jun 2021 16:21:16 +0200 Subject: [PATCH] generics haggling --- node/core/candidate-validation/src/lib.rs | 1 + node/malus/src/lib.rs | 34 +++++++++++++---------- node/malus/src/variant-a.rs | 9 ++++-- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/node/core/candidate-validation/src/lib.rs b/node/core/candidate-validation/src/lib.rs index 4efec16db1c1..b05ff9cabc32 100644 --- a/node/core/candidate-validation/src/lib.rs +++ b/node/core/candidate-validation/src/lib.rs @@ -56,6 +56,7 @@ use async_trait::async_trait; const LOG_TARGET: &'static str = "parachain::candidate-validation"; /// Configuration for the candidate validation subsystem +#[derive(Clone)] pub struct Config { /// The path where candidate validation can store compiled artifacts for PVFs. pub artifacts_cache_path: PathBuf, diff --git a/node/malus/src/lib.rs b/node/malus/src/lib.rs index a6a28977a0f8..36e94b8f94d7 100644 --- a/node/malus/src/lib.rs +++ b/node/malus/src/lib.rs @@ -20,8 +20,10 @@ //! multiple subsystems and intercept or replace incoming and outgoing //! messages on the overseer level. -use polkadot_node_subsystem::messages::AllMessages; -use polkadot_node_subsystem::FromOverseer; +pub use polkadot_node_subsystem::{ + FromOverseer, + messages::AllMessages, +}; use polkadot_node_subsystem::*; use std::future::Future; use std::pin::Pin; @@ -33,7 +35,7 @@ pub trait MsgFilter: Send + Sync + Clone + 'static { /// Filter messages that are to be received by /// the subsystem. - fn filter_in(&self, msg: Self::Message) -> Option { + fn filter_in(&self, msg: FromOverseer) -> Option> { Some(msg) } @@ -80,19 +82,19 @@ where } /// A subsystem context, that filters the outgoing messages. -pub struct FilteredContext { - inner: X, +pub struct FilteredContext { + inner: Context, message_filter: Fil, - sender: FilteredSender<::Sender, Fil>, + sender: FilteredSender<::Sender, Fil>, } -impl FilteredContext +impl FilteredContext where - X: SubsystemContext, - Fil: MsgFilter, + Context: SubsystemContext, + Fil: MsgFilter::Message>, { - pub fn new(mut inner: X, message_filter: Fil) -> Self { - let sender = FilteredSender::<::Sender, Fil> { + pub fn new(mut inner: Context, message_filter: Fil) -> Self { + let sender = FilteredSender::<::Sender, Fil> { inner: inner.sender().clone(), message_filter: message_filter.clone(), }; @@ -108,7 +110,7 @@ where impl SubsystemContext for FilteredContext where Context: SubsystemContext, - Fil: MsgFilter::Message>>, + Fil: MsgFilter::Message>, { type Message = ::Message; type Sender = FilteredSender<::Sender, Fil>; @@ -173,11 +175,13 @@ impl FilteredSubsystem { impl Subsystem for FilteredSubsystem where - Sub: Subsystem, + Context: SubsystemContext + Sync + Send, + Sub: Subsystem>, + FilteredContext: Subsystem, Fil: MsgFilter::Message>, - Context: FilteredContext, { fn start(self, ctx: Context) -> SpawnedSubsystem { - self.subsystem.start(ctx) + let ctx = FilteredContext::new(ctx, self.message_filter); + Subsystem::>::start(self.subsystem, ctx) } } diff --git a/node/malus/src/variant-a.rs b/node/malus/src/variant-a.rs index 8f6715f3a389..7246734c944d 100644 --- a/node/malus/src/variant-a.rs +++ b/node/malus/src/variant-a.rs @@ -31,6 +31,7 @@ use polkadot_cli::{ }, Cli, }; +use polkadot_node_core_candidate_validation::{Metrics, CandidateValidationSubsystem}; use std::sync::atomic::AtomicUsize; use std::sync::Arc; use structopt::StructOpt; @@ -73,10 +74,14 @@ impl OverseerGen for BehaveMaleficient { let leaves = args.leaves.clone(); let runtime_client = args.runtime_client.clone(); let registry = args.registry.clone(); - + let candidate_validation_config = args.candidate_validation_config.clone(); // modify the subsystem(s) as needed: let all_subsystems = create_default_subsystems(args)?.replace_candidate_validation( - FilteredSubsystem::new(args.candidate_validation, Skippy::default()), + // create the filtered subsystem + FilteredSubsystem::new(CandidateValidationSubsystem::from_config( + candidate_validation_config, + Metrics::register(registry)?, + ), Skippy::default()), ); Overseer::new(leaves, all_subsystems, registry, runtime_client, spawner)