mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
450ca2baca
* 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>
178 lines
4.4 KiB
Rust
178 lines
4.4 KiB
Rust
// Copyright 2020 Parity Technologies (UK) Ltd.
|
|
// This file is part of Polkadot.
|
|
|
|
// Polkadot is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Polkadot is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Shows a basic usage of the `Overseer`:
|
|
//! * Spawning subsystems and subsystem child jobs
|
|
//! * Establishing message passing
|
|
|
|
use futures::{channel::oneshot, pending, pin_mut, select, stream, FutureExt, StreamExt};
|
|
use futures_timer::Delay;
|
|
use std::time::Duration;
|
|
|
|
use ::test_helpers::{dummy_candidate_descriptor, dummy_hash};
|
|
use polkadot_node_primitives::{BlockData, PoV};
|
|
use polkadot_node_subsystem_types::messages::CandidateValidationMessage;
|
|
use polkadot_overseer::{
|
|
self as overseer,
|
|
dummy::dummy_overseer_builder,
|
|
gen::{FromOrchestra, SpawnedSubsystem},
|
|
HeadSupportsParachains, SubsystemError,
|
|
};
|
|
use polkadot_primitives::v2::{CandidateReceipt, Hash};
|
|
|
|
struct AlwaysSupportsParachains;
|
|
impl HeadSupportsParachains for AlwaysSupportsParachains {
|
|
fn head_supports_parachains(&self, _head: &Hash) -> bool {
|
|
true
|
|
}
|
|
}
|
|
|
|
////////
|
|
|
|
struct Subsystem1;
|
|
|
|
#[overseer::contextbounds(CandidateBacking, prefix = self::overseer)]
|
|
impl Subsystem1 {
|
|
async fn run<Context>(mut ctx: Context) {
|
|
'louy: loop {
|
|
match ctx.try_recv().await {
|
|
Ok(Some(msg)) => {
|
|
if let FromOrchestra::Communication { msg } = msg {
|
|
gum::info!("msg {:?}", msg);
|
|
}
|
|
continue 'louy
|
|
},
|
|
Ok(None) => (),
|
|
Err(_) => {
|
|
gum::info!("exiting");
|
|
break 'louy
|
|
},
|
|
}
|
|
|
|
Delay::new(Duration::from_secs(1)).await;
|
|
let (tx, _) = oneshot::channel();
|
|
|
|
let candidate_receipt = CandidateReceipt {
|
|
descriptor: dummy_candidate_descriptor(dummy_hash()),
|
|
commitments_hash: Hash::zero(),
|
|
};
|
|
|
|
let msg = CandidateValidationMessage::ValidateFromChainState(
|
|
candidate_receipt,
|
|
PoV { block_data: BlockData(Vec::new()) }.into(),
|
|
Default::default(),
|
|
tx,
|
|
);
|
|
ctx.send_message(msg).await;
|
|
}
|
|
()
|
|
}
|
|
}
|
|
|
|
#[overseer::subsystem(CandidateBacking, error = SubsystemError, prefix = self::overseer)]
|
|
impl<Context> Subsystem1 {
|
|
fn start(self, ctx: Context) -> SpawnedSubsystem<SubsystemError> {
|
|
let future = Box::pin(async move {
|
|
Self::run(ctx).await;
|
|
Ok(())
|
|
});
|
|
|
|
SpawnedSubsystem { name: "subsystem-1", future }
|
|
}
|
|
}
|
|
|
|
//////////////////
|
|
|
|
struct Subsystem2;
|
|
|
|
#[overseer::contextbounds(CandidateValidation, prefix = self::overseer)]
|
|
impl Subsystem2 {
|
|
async fn run<Context>(mut ctx: Context) -> () {
|
|
ctx.spawn(
|
|
"subsystem-2-job",
|
|
Box::pin(async {
|
|
loop {
|
|
gum::info!("Job tick");
|
|
Delay::new(Duration::from_secs(1)).await;
|
|
}
|
|
}),
|
|
)
|
|
.unwrap();
|
|
|
|
loop {
|
|
match ctx.try_recv().await {
|
|
Ok(Some(msg)) => {
|
|
gum::info!("Subsystem2 received message {:?}", msg);
|
|
continue
|
|
},
|
|
Ok(None) => {
|
|
pending!();
|
|
},
|
|
Err(_) => {
|
|
gum::info!("exiting");
|
|
return
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[overseer::subsystem(CandidateValidation, error = SubsystemError, prefix = self::overseer)]
|
|
impl<Context> Subsystem2 {
|
|
fn start(self, ctx: Context) -> SpawnedSubsystem<SubsystemError> {
|
|
let future = Box::pin(async move {
|
|
Self::run(ctx).await;
|
|
Ok(())
|
|
});
|
|
|
|
SpawnedSubsystem { name: "subsystem-2", future }
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
femme::with_level(femme::LevelFilter::Trace);
|
|
let spawner = sp_core::testing::TaskExecutor::new();
|
|
futures::executor::block_on(async {
|
|
let timer_stream = stream::repeat(()).then(|_| async {
|
|
Delay::new(Duration::from_secs(1)).await;
|
|
});
|
|
|
|
let (overseer, _handle) = dummy_overseer_builder(spawner, AlwaysSupportsParachains, None)
|
|
.unwrap()
|
|
.replace_candidate_validation(|_| Subsystem2)
|
|
.replace_candidate_backing(|orig| orig)
|
|
.replace_candidate_backing(|_orig| Subsystem1)
|
|
.build()
|
|
.unwrap();
|
|
|
|
let overseer_fut = overseer.run().fuse();
|
|
let timer_stream = timer_stream;
|
|
|
|
pin_mut!(timer_stream);
|
|
pin_mut!(overseer_fut);
|
|
|
|
loop {
|
|
select! {
|
|
_ = overseer_fut => break,
|
|
_ = timer_stream.next() => {
|
|
gum::info!("tick");
|
|
}
|
|
complete => break,
|
|
}
|
|
}
|
|
});
|
|
}
|