mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-29 23:07:26 +00:00
54bec3bfc0
* start sketching out a collation generation subsystem * invent a basic strategy for double initialization * clean up warnings * impl util requests from runtime assuming a context instead of a FromJob sender * implement collation generation algorithm from guide * update AllMessages in tests * fix trivial review comments * remove another redundant declaration from merge * filter availability cores by para_id * handle new activations each in their own async task * update guide according to the actual current implementation * add initialization to guide * add general-purpose subsystem_test_harness helper * write first handle_new_activations test * add test that handle_new_activations filters local_validation_data requests * add (failing) test of collation distribution message sending * rustfmt * broken: work on fixing sender test Unfortunately, for reasons that are not yet clear, despite the public key and checked data being identical, the signer is not producing an identical signature. This commit produces this output (among more): signing with Public(c4733ab0bbe3ba4c096685d1737a7f498cdbdd167a767d04a21dc7df12b8c858 (5GWHUNm5...)) checking with Public(c4733ab0bbe3ba4c096685d1737a7f498cdbdd167a767d04a21dc7df12b8c858 (5GWHUNm5...)) signed payload: [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 10, 0, 0, 0, c7, e5, c0, 64, 7a, db, fe, 44, 81, e5, 51, 11, 79, 9f, a5, 63, 93, 94, 3c, c4, 36, c6, 30, 36, c2, c5, 44, a2, 1b, db, b7, 82, 3, 17, a, 2e, 75, 97, b7, b7, e3, d8, 4c, 5, 39, 1d, 13, 9a, 62, b1, 57, e7, 87, 86, d8, c0, 82, f2, 9d, cf, 4c, 11, 13, 14] checked payload: [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 10, 0, 0, 0, c7, e5, c0, 64, 7a, db, fe, 44, 81, e5, 51, 11, 79, 9f, a5, 63, 93, 94, 3c, c4, 36, c6, 30, 36, c2, c5, 44, a2, 1b, db, b7, 82, 3, 17, a, 2e, 75, 97, b7, b7, e3, d8, 4c, 5, 39, 1d, 13, 9a, 62, b1, 57, e7, 87, 86, d8, c0, 82, f2, 9d, cf, 4c, 11, 13, 14] * fix broken test * collation function returns commitments hash It doesn't look like we use the actual commitments data anywhere, and it's not obvious if there are any fields of `CandidateCommitments` not available to the collator, so this commit just assigns them the entire responsibility of generating the hash. * add missing overseer impls * calculating erasure coding is polkadot's responsibility, not cumulus * concurrentize per-relay_parent requests
183 lines
4.3 KiB
Rust
183 lines
4.3 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 std::time::Duration;
|
|
use futures::{
|
|
channel::oneshot,
|
|
pending, pin_mut, select, stream,
|
|
FutureExt, StreamExt,
|
|
};
|
|
use futures_timer::Delay;
|
|
use kv_log_macro as log;
|
|
|
|
use polkadot_primitives::v1::{BlockData, PoV};
|
|
use polkadot_overseer::{Overseer, AllSubsystems};
|
|
|
|
use polkadot_subsystem::{
|
|
Subsystem, SubsystemContext, DummySubsystem,
|
|
SpawnedSubsystem, FromOverseer,
|
|
};
|
|
use polkadot_subsystem::messages::{
|
|
CandidateValidationMessage, CandidateBackingMessage, AllMessages,
|
|
};
|
|
|
|
struct Subsystem1;
|
|
|
|
impl Subsystem1 {
|
|
async fn run(mut ctx: impl SubsystemContext<Message=CandidateBackingMessage>) {
|
|
loop {
|
|
match ctx.try_recv().await {
|
|
Ok(Some(msg)) => {
|
|
if let FromOverseer::Communication { msg } = msg {
|
|
log::info!("msg {:?}", msg);
|
|
}
|
|
continue;
|
|
}
|
|
Ok(None) => (),
|
|
Err(_) => {
|
|
log::info!("exiting");
|
|
return;
|
|
}
|
|
}
|
|
|
|
Delay::new(Duration::from_secs(1)).await;
|
|
let (tx, _) = oneshot::channel();
|
|
|
|
ctx.send_message(AllMessages::CandidateValidation(
|
|
CandidateValidationMessage::ValidateFromChainState(
|
|
Default::default(),
|
|
PoV {
|
|
block_data: BlockData(Vec::new()),
|
|
}.into(),
|
|
tx,
|
|
)
|
|
)).await.unwrap();
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<C> Subsystem<C> for Subsystem1
|
|
where C: SubsystemContext<Message=CandidateBackingMessage>
|
|
{
|
|
fn start(self, ctx: C) -> SpawnedSubsystem {
|
|
let future = Box::pin(async move {
|
|
Self::run(ctx).await;
|
|
});
|
|
|
|
SpawnedSubsystem {
|
|
name: "subsystem-1",
|
|
future,
|
|
}
|
|
}
|
|
}
|
|
|
|
struct Subsystem2;
|
|
|
|
impl Subsystem2 {
|
|
async fn run(mut ctx: impl SubsystemContext<Message=CandidateValidationMessage>) {
|
|
ctx.spawn(
|
|
"subsystem-2-job",
|
|
Box::pin(async {
|
|
loop {
|
|
log::info!("Job tick");
|
|
Delay::new(Duration::from_secs(1)).await;
|
|
}
|
|
}),
|
|
).await.unwrap();
|
|
|
|
loop {
|
|
match ctx.try_recv().await {
|
|
Ok(Some(msg)) => {
|
|
log::info!("Subsystem2 received message {:?}", msg);
|
|
continue;
|
|
}
|
|
Ok(None) => { pending!(); }
|
|
Err(_) => {
|
|
log::info!("exiting");
|
|
return;
|
|
},
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<C> Subsystem<C> for Subsystem2
|
|
where C: SubsystemContext<Message=CandidateValidationMessage>
|
|
{
|
|
fn start(self, ctx: C) -> SpawnedSubsystem {
|
|
let future = Box::pin(async move {
|
|
Self::run(ctx).await;
|
|
});
|
|
|
|
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 all_subsystems = AllSubsystems {
|
|
candidate_validation: Subsystem2,
|
|
candidate_backing: Subsystem1,
|
|
candidate_selection: DummySubsystem,
|
|
statement_distribution: DummySubsystem,
|
|
availability_distribution: DummySubsystem,
|
|
bitfield_signing: DummySubsystem,
|
|
bitfield_distribution: DummySubsystem,
|
|
provisioner: DummySubsystem,
|
|
pov_distribution: DummySubsystem,
|
|
runtime_api: DummySubsystem,
|
|
availability_store: DummySubsystem,
|
|
network_bridge: DummySubsystem,
|
|
chain_api: DummySubsystem,
|
|
collation_generation: DummySubsystem,
|
|
collator_protocol: DummySubsystem,
|
|
};
|
|
let (overseer, _handler) = Overseer::new(
|
|
vec![],
|
|
all_subsystems,
|
|
spawner,
|
|
).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() => {
|
|
log::info!("tick");
|
|
}
|
|
complete => break,
|
|
}
|
|
}
|
|
});
|
|
}
|