mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 05:47:58 +00:00
0f1a9fb1eb
* remove Default from CandidateHash * Apply suggestions from code review Co-authored-by: Andronik Ordian <write@reusable.software> * chore: fmt * remove backed candidate default * Partial migration away from CandidateReceipt::default * Remove more CandidateReceipt defaults * fmt * Mostly remove CommittedCandidateReceipt default usage * Remove CommittedCandidateReceipt * Remove more Defaults from polakdot primitives v1 + fmt * Remove more Default from polkadot primites v1 * WIP trying to get overseer example + tests to compile * feat: add primitives test helpers * reduce deps of helper * update primitive helpers * make candidate validation compile * fixup cargo lock * make av-store compile * fixup disputes coordinator tests * test: fixup backing * test: fixup approval voting * fixup bitfield signing * test: fixup runtime-api * test: fixup availability dist * foxi[ pverseer test] * remove some Defaults, remove bounds from `dummy` All `fn dummy` in primitives need to be removed anyways. This aids in the transition. * it's a test helper, so always use std * test: fixup parachains runtime tests Excluding benches. * fix keyring * fix paras runtime properly, no more default * Remove fn dummy() usage from approval voting * Move TestCandidateBuilder out of av store to test helpers * Make candidate validation tests pass * Make most dispute coirdinator tests pass * Make provisioner tests work * Make availability recovery tests work with test helpers * Update polkadot-collator-protocol tests * Update statement distribution tests * Update polkadot overseer examples and tests * Derive default for validation code so we don't break unrelated things * Make para runtime test pass (no bench) * Some more work * chore: cargo fmt * cargo fix * avoid some Default::default * fixup dispute coordinator test * remove unused crate deps * remove Default::default wherever possible, replace by dummy_* for the most part * chore: cargo fmt * Remove some warnings * Remove CommittedCandidateReceipt dummy * Remove CandidateReceipt dummy * Remove CandidateDescriptor dummy * Remove commented out code * Fix para runtime tests * chore: nightly * Some updates to the builder * Dynamically adjust mock head data size * Make dispute cooridinator tests work * Fix test candidate_backing_reorders_votes work * +nightly-2021-10-29 fmt * Spelling and remove a default use in builder * Various clean up * More small updates * fmt * More small updates * Doc comments for test helpers * cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_parachains::paras_inherent --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_parachains_paras_inherent.rs * cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=polkadot-dev --steps=50 --repeat=20 --pallet=runtime_parachains::paras_inherent --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/polkadot/src/weights/runtime_parachains_paras_inherent.rs * Update lib.rs * review comments * fix warnings * fix test by using correct candidate receipt relay parent Co-authored-by: Andronik Ordian <write@reusable.software> Co-authored-by: emostov <32168567+emostov@users.noreply.github.com> Co-authored-by: Parity Bot <admin@parity.io> Co-authored-by: Gavin Wood <gavin@parity.io>
199 lines
4.7 KiB
Rust
199 lines
4.7 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::{
|
|
CandidateBackingMessage, CandidateValidationMessage,
|
|
};
|
|
use polkadot_overseer::{
|
|
self as overseer,
|
|
dummy::dummy_overseer_builder,
|
|
gen::{FromOverseer, SpawnedSubsystem},
|
|
AllMessages, HeadSupportsParachains, OverseerSignal, SubsystemError,
|
|
};
|
|
use polkadot_primitives::v1::Hash;
|
|
|
|
struct AlwaysSupportsParachains;
|
|
impl HeadSupportsParachains for AlwaysSupportsParachains {
|
|
fn head_supports_parachains(&self, _head: &Hash) -> bool {
|
|
true
|
|
}
|
|
}
|
|
|
|
////////
|
|
|
|
struct Subsystem1;
|
|
|
|
impl Subsystem1 {
|
|
async fn run<Ctx>(mut ctx: Ctx) -> ()
|
|
where
|
|
Ctx: overseer::SubsystemContext<
|
|
Message = CandidateBackingMessage,
|
|
AllMessages = AllMessages,
|
|
Signal = OverseerSignal,
|
|
>,
|
|
{
|
|
'louy: loop {
|
|
match ctx.try_recv().await {
|
|
Ok(Some(msg)) => {
|
|
if let FromOverseer::Communication { msg } = msg {
|
|
tracing::info!("msg {:?}", msg);
|
|
}
|
|
continue 'louy
|
|
},
|
|
Ok(None) => (),
|
|
Err(_) => {
|
|
tracing::info!("exiting");
|
|
break 'louy
|
|
},
|
|
}
|
|
|
|
Delay::new(Duration::from_secs(1)).await;
|
|
let (tx, _) = oneshot::channel();
|
|
|
|
let msg = CandidateValidationMessage::ValidateFromChainState(
|
|
dummy_candidate_descriptor(dummy_hash()),
|
|
PoV { block_data: BlockData(Vec::new()) }.into(),
|
|
Default::default(),
|
|
tx,
|
|
);
|
|
ctx.send_message(<Ctx as overseer::SubsystemContext>::AllMessages::from(msg))
|
|
.await;
|
|
}
|
|
()
|
|
}
|
|
}
|
|
|
|
impl<Context> overseer::Subsystem<Context, SubsystemError> for Subsystem1
|
|
where
|
|
Context: overseer::SubsystemContext<
|
|
Message = CandidateBackingMessage,
|
|
AllMessages = AllMessages,
|
|
Signal = OverseerSignal,
|
|
>,
|
|
{
|
|
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;
|
|
|
|
impl Subsystem2 {
|
|
async fn run<Ctx>(mut ctx: Ctx)
|
|
where
|
|
Ctx: overseer::SubsystemContext<
|
|
Message = CandidateValidationMessage,
|
|
AllMessages = AllMessages,
|
|
Signal = OverseerSignal,
|
|
>,
|
|
{
|
|
ctx.spawn(
|
|
"subsystem-2-job",
|
|
Box::pin(async {
|
|
loop {
|
|
tracing::info!("Job tick");
|
|
Delay::new(Duration::from_secs(1)).await;
|
|
}
|
|
}),
|
|
)
|
|
.unwrap();
|
|
|
|
loop {
|
|
match ctx.try_recv().await {
|
|
Ok(Some(msg)) => {
|
|
tracing::info!("Subsystem2 received message {:?}", msg);
|
|
continue
|
|
},
|
|
Ok(None) => {
|
|
pending!();
|
|
},
|
|
Err(_) => {
|
|
tracing::info!("exiting");
|
|
return
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<Context> overseer::Subsystem<Context, SubsystemError> for Subsystem2
|
|
where
|
|
Context: overseer::SubsystemContext<
|
|
Message = CandidateValidationMessage,
|
|
AllMessages = AllMessages,
|
|
Signal = OverseerSignal,
|
|
>,
|
|
{
|
|
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)
|
|
.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() => {
|
|
tracing::info!("tick");
|
|
}
|
|
complete => break,
|
|
}
|
|
}
|
|
});
|
|
}
|