mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 23:01:01 +00:00
Implement Network Bridge (#1280)
* network bridge skeleton * move some primitives around and add debug impls * protocol registration glue & abstract network interface * add send_msgs to subsystemctx * select logic * transform different events into actions and handle * implement remaining network bridge state machine * start test skeleton * make network methods asynchronous * extract subsystem out to subsystem crate * port over overseer to subsystem context trait * fix minimal example * fix overseer doc test * update network-bridge crate * write a subsystem test-helpers crate * write a network test helper for network-bridge * set up (broken) view test * Revamp network to be more async-friendly and not require Sync * fix spacing * fix test compilation * insert side-channel for actions * Add some more message types to AllMessages * introduce a test harness * add some tests * ensure service compiles and passes tests * fix typo * fix service-new compilation * Subsystem test helpers send messages synchronously * remove smelly action inspector * remove superfluous let binding * fix warnings * Update node/network/bridge/src/lib.rs Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com> * fix compilation Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
90de55918a
commit
d16e7485d4
@@ -28,16 +28,17 @@ use futures_timer::Delay;
|
||||
use kv_log_macro as log;
|
||||
|
||||
use polkadot_primitives::parachain::{BlockData, PoVBlock};
|
||||
use polkadot_overseer::{Overseer, Subsystem, SubsystemContext, SpawnedSubsystem};
|
||||
use polkadot_overseer::Overseer;
|
||||
|
||||
use messages::{
|
||||
AllMessages, CandidateBackingMessage, FromOverseer, CandidateValidationMessage
|
||||
use polkadot_subsystem::{Subsystem, SubsystemContext, SpawnedSubsystem, FromOverseer};
|
||||
use polkadot_subsystem::messages::{
|
||||
AllMessages, CandidateBackingMessage, CandidateValidationMessage
|
||||
};
|
||||
|
||||
struct Subsystem1;
|
||||
|
||||
impl Subsystem1 {
|
||||
async fn run(mut ctx: SubsystemContext<CandidateBackingMessage>) {
|
||||
async fn run(mut ctx: impl SubsystemContext<Message=CandidateBackingMessage>) {
|
||||
loop {
|
||||
match ctx.try_recv().await {
|
||||
Ok(Some(msg)) => {
|
||||
@@ -56,7 +57,7 @@ impl Subsystem1 {
|
||||
Delay::new(Duration::from_secs(1)).await;
|
||||
let (tx, _) = oneshot::channel();
|
||||
|
||||
ctx.send_msg(AllMessages::CandidateValidation(
|
||||
ctx.send_message(AllMessages::CandidateValidation(
|
||||
CandidateValidationMessage::Validate(
|
||||
Default::default(),
|
||||
Default::default(),
|
||||
@@ -70,8 +71,10 @@ impl Subsystem1 {
|
||||
}
|
||||
}
|
||||
|
||||
impl Subsystem<CandidateBackingMessage> for Subsystem1 {
|
||||
fn start(&mut self, ctx: SubsystemContext<CandidateBackingMessage>) -> SpawnedSubsystem {
|
||||
impl<C> Subsystem<C> for Subsystem1
|
||||
where C: SubsystemContext<Message=CandidateBackingMessage>
|
||||
{
|
||||
fn start(&mut self, ctx: C) -> SpawnedSubsystem {
|
||||
SpawnedSubsystem(Box::pin(async move {
|
||||
Self::run(ctx).await;
|
||||
}))
|
||||
@@ -81,7 +84,7 @@ impl Subsystem<CandidateBackingMessage> for Subsystem1 {
|
||||
struct Subsystem2;
|
||||
|
||||
impl Subsystem2 {
|
||||
async fn run(mut ctx: SubsystemContext<CandidateValidationMessage>) {
|
||||
async fn run(mut ctx: impl SubsystemContext<Message=CandidateValidationMessage>) {
|
||||
ctx.spawn(Box::pin(async {
|
||||
loop {
|
||||
log::info!("Job tick");
|
||||
@@ -105,8 +108,10 @@ impl Subsystem2 {
|
||||
}
|
||||
}
|
||||
|
||||
impl Subsystem<CandidateValidationMessage> for Subsystem2 {
|
||||
fn start(&mut self, ctx: SubsystemContext<CandidateValidationMessage>) -> SpawnedSubsystem {
|
||||
impl<C> Subsystem<C> for Subsystem2
|
||||
where C: SubsystemContext<Message=CandidateValidationMessage>
|
||||
{
|
||||
fn start(&mut self, ctx: C) -> SpawnedSubsystem {
|
||||
SpawnedSubsystem(Box::pin(async move {
|
||||
Self::run(ctx).await;
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user