mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-29 20:31:04 +00:00
add ActiveLeavesUpdate, remove StartWork, StopWork (#1458)
* add ActiveLeavesUpdate, remove StartWork, StopWork * replace StartWork, StopWork in subsystem crate tests * mechanically update OverseerSignal in other modules * convert overseer to take advantage of new multi-hash update abilities Note: this does not yet convert the tests; some of the tests now freeze: test tests::overseer_start_stop_works ... test tests::overseer_start_stop_works has been running for over 60 seconds test tests::overseer_finalize_works ... test tests::overseer_finalize_works has been running for over 60 seconds * fix broken overseer tests * manually impl PartialEq for ActiveLeavesUpdate, rm trait Equivalent This cleans up the code a bit and makes it easier in the future to do the right thing when comparing ALUs. * use target in all network bridge logging * reduce spamming of and
This commit is contained in:
committed by
GitHub
parent
1cb92aa83e
commit
106bd929ce
@@ -30,6 +30,7 @@ use futures::future::BoxFuture;
|
||||
|
||||
use polkadot_primitives::v1::Hash;
|
||||
use async_trait::async_trait;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::messages::AllMessages;
|
||||
|
||||
@@ -38,13 +39,51 @@ pub mod util;
|
||||
#[cfg(any(test, feature = "test-helpers"))]
|
||||
pub mod test_helpers;
|
||||
|
||||
/// How many slots are stack-reserved for active leaves updates
|
||||
///
|
||||
/// If there are fewer than this number of slots, then we've wasted some stack space.
|
||||
/// If there are greater than this number of slots, then we fall back to a heap vector.
|
||||
const ACTIVE_LEAVES_SMALLVEC_CAPACITY: usize = 8;
|
||||
|
||||
/// Changes in the set of active leaves: the parachain heads which we care to work on.
|
||||
///
|
||||
/// Note that the activated and deactivated fields indicate deltas, not complete sets.
|
||||
#[derive(Clone, Debug, Default, Eq)]
|
||||
pub struct ActiveLeavesUpdate {
|
||||
/// New relay chain block hashes of interest.
|
||||
pub activated: SmallVec<[Hash; ACTIVE_LEAVES_SMALLVEC_CAPACITY]>,
|
||||
/// Relay chain block hashes no longer of interest.
|
||||
pub deactivated: SmallVec<[Hash; ACTIVE_LEAVES_SMALLVEC_CAPACITY]>,
|
||||
}
|
||||
|
||||
impl ActiveLeavesUpdate {
|
||||
/// Create a ActiveLeavesUpdate with a single activated hash
|
||||
pub fn start_work(hash: Hash) -> Self {
|
||||
Self { activated: [hash].as_ref().into(), ..Default::default() }
|
||||
}
|
||||
|
||||
/// Create a ActiveLeavesUpdate with a single deactivated hash
|
||||
pub fn stop_work(hash: Hash) -> Self {
|
||||
Self { deactivated: [hash].as_ref().into(), ..Default::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for ActiveLeavesUpdate {
|
||||
/// Equality for `ActiveLeavesUpdate` doesnt imply bitwise equality.
|
||||
///
|
||||
/// Instead, it means equality when `activated` and `deactivated` are considered as sets.
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
use std::collections::HashSet;
|
||||
self.activated.iter().collect::<HashSet<_>>() == other.activated.iter().collect::<HashSet<_>>() &&
|
||||
self.deactivated.iter().collect::<HashSet<_>>() == other.deactivated.iter().collect::<HashSet<_>>()
|
||||
}
|
||||
}
|
||||
|
||||
/// Signals sent by an overseer to a subsystem.
|
||||
#[derive(PartialEq, Clone, Debug)]
|
||||
pub enum OverseerSignal {
|
||||
/// `Subsystem` should start working on block-based work, given by the relay-chain block hash.
|
||||
StartWork(Hash),
|
||||
/// `Subsystem` should stop working on block-based work specified by the relay-chain block hash.
|
||||
StopWork(Hash),
|
||||
/// Subsystems should adjust their jobs to start and stop work on appropriate block hashes.
|
||||
ActiveLeaves(ActiveLeavesUpdate),
|
||||
/// Conclude the work of the `Overseer` and all `Subsystem`s.
|
||||
Conclude,
|
||||
}
|
||||
|
||||
@@ -602,21 +602,25 @@ where
|
||||
err_tx: &mut Option<mpsc::Sender<(Option<Hash>, JobsError<Job::Error>)>>
|
||||
) -> bool {
|
||||
use crate::FromOverseer::{Communication, Signal};
|
||||
use crate::OverseerSignal::{Conclude, StartWork, StopWork};
|
||||
use crate::ActiveLeavesUpdate;
|
||||
use crate::OverseerSignal::{Conclude, ActiveLeaves};
|
||||
|
||||
match incoming {
|
||||
Ok(Signal(StartWork(hash))) => {
|
||||
if let Err(e) = jobs.spawn_job(hash, run_args.clone()) {
|
||||
log::error!("Failed to spawn a job: {:?}", e);
|
||||
Self::fwd_err(Some(hash), e.into(), err_tx).await;
|
||||
return true;
|
||||
Ok(Signal(ActiveLeaves(ActiveLeavesUpdate { activated, deactivated }))) => {
|
||||
for hash in activated {
|
||||
if let Err(e) = jobs.spawn_job(hash, run_args.clone()) {
|
||||
log::error!("Failed to spawn a job: {:?}", e);
|
||||
Self::fwd_err(Some(hash), e.into(), err_tx).await;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Signal(StopWork(hash))) => {
|
||||
if let Err(e) = jobs.stop_job(hash).await {
|
||||
log::error!("Failed to stop a job: {:?}", e);
|
||||
Self::fwd_err(Some(hash), e.into(), err_tx).await;
|
||||
return true;
|
||||
|
||||
for hash in deactivated {
|
||||
if let Err(e) = jobs.stop_job(hash).await {
|
||||
log::error!("Failed to stop a job: {:?}", e);
|
||||
Self::fwd_err(Some(hash), e.into(), err_tx).await;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Signal(Conclude)) => {
|
||||
@@ -725,6 +729,7 @@ mod tests {
|
||||
JobTrait,
|
||||
ToJobTrait,
|
||||
},
|
||||
ActiveLeavesUpdate,
|
||||
FromOverseer,
|
||||
OverseerSignal,
|
||||
};
|
||||
@@ -920,12 +925,12 @@ mod tests {
|
||||
run_args.insert(relay_parent.clone(), vec![FromJob::Test(test_message.clone())]);
|
||||
|
||||
test_harness(run_args, |mut overseer_handle, err_rx| async move {
|
||||
overseer_handle.send(FromOverseer::Signal(OverseerSignal::StartWork(relay_parent))).await;
|
||||
overseer_handle.send(FromOverseer::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(relay_parent)))).await;
|
||||
assert_matches!(
|
||||
overseer_handle.recv().await,
|
||||
AllMessages::Test(msg) if msg == test_message
|
||||
);
|
||||
overseer_handle.send(FromOverseer::Signal(OverseerSignal::StopWork(relay_parent))).await;
|
||||
overseer_handle.send(FromOverseer::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::stop_work(relay_parent)))).await;
|
||||
|
||||
let errs: Vec<_> = err_rx.collect().await;
|
||||
assert_eq!(errs.len(), 0);
|
||||
@@ -938,7 +943,7 @@ mod tests {
|
||||
let run_args = HashMap::new();
|
||||
|
||||
test_harness(run_args, |mut overseer_handle, err_rx| async move {
|
||||
overseer_handle.send(FromOverseer::Signal(OverseerSignal::StopWork(relay_parent))).await;
|
||||
overseer_handle.send(FromOverseer::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::stop_work(relay_parent)))).await;
|
||||
|
||||
let errs: Vec<_> = err_rx.collect().await;
|
||||
assert_eq!(errs.len(), 1);
|
||||
|
||||
Reference in New Issue
Block a user