change ActiveLeaves to contain at most one activated (#3525)

* change ActiveLeaves to contain at most one activated

* fix test
This commit is contained in:
Andronik Ordian
2021-07-27 16:45:15 +02:00
committed by GitHub
parent 6519ba987c
commit e1be821fe1
14 changed files with 183 additions and 259 deletions
-2
View File
@@ -5932,7 +5932,6 @@ dependencies = [
"polkadot-primitives", "polkadot-primitives",
"rand 0.8.4", "rand 0.8.4",
"sc-network", "sc-network",
"smallvec 1.6.1",
"sp-application-crypto", "sp-application-crypto",
"sp-core", "sp-core",
"sp-keyring", "sp-keyring",
@@ -5962,7 +5961,6 @@ dependencies = [
"polkadot-primitives", "polkadot-primitives",
"rand 0.8.4", "rand 0.8.4",
"sc-network", "sc-network",
"smallvec 1.6.1",
"sp-application-crypto", "sp-application-crypto",
"sp-core", "sp-core",
"sp-keyring", "sp-keyring",
+18 -27
View File
@@ -255,15 +255,12 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: vec![ActivatedLeaf { hash: new_leaf,
hash: new_leaf, number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}].into(),
deactivated: vec![].into(),
}),
).await; ).await;
let header = Header { let header = Header {
@@ -806,15 +803,12 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: vec![ActivatedLeaf { hash: new_leaf,
hash: new_leaf, number: 4,
number: 4, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}].into(),
deactivated: vec![].into(),
}),
).await; ).await;
assert_matches!( assert_matches!(
@@ -1139,15 +1133,12 @@ async fn import_leaf(
overseer_signal( overseer_signal(
virtual_overseer, virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: vec![ActivatedLeaf { hash: new_leaf,
hash: new_leaf, number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}].into(),
deactivated: vec![].into(),
}),
).await; ).await;
assert_matches!( assert_matches!(
@@ -31,4 +31,3 @@ sc-network = { git = "https://github.com/paritytech/substrate", branch = "master
futures-timer = "3.0.2" futures-timer = "3.0.2"
assert_matches = "1.4.0" assert_matches = "1.4.0"
maplit = "1.0" maplit = "1.0"
smallvec = "1.6.1"
@@ -18,7 +18,6 @@ use std::{collections::{HashMap, HashSet}, sync::Arc, time::Duration};
use polkadot_node_subsystem_util::TimeoutExt; use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_subsystem_testhelpers::TestSubsystemContextHandle; use polkadot_subsystem_testhelpers::TestSubsystemContextHandle;
use smallvec::smallvec;
use futures::{FutureExt, channel::oneshot, SinkExt, channel::mpsc, StreamExt}; use futures::{FutureExt, channel::oneshot, SinkExt, channel::mpsc, StreamExt};
use futures_timer::Delay; use futures_timer::Delay;
@@ -171,13 +170,13 @@ impl TestState {
self self
.relay_chain.iter().zip(advanced) .relay_chain.iter().zip(advanced)
.map(|(old, new)| ActiveLeavesUpdate { .map(|(old, new)| ActiveLeavesUpdate {
activated: smallvec![ActivatedLeaf { activated: Some(ActivatedLeaf {
hash: new.clone(), hash: new.clone(),
number: 1, number: 1,
status: LeafStatus::Fresh, status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled), span: Arc::new(jaeger::Span::Disabled),
}], }),
deactivated: smallvec![old.clone()], deactivated: vec![old.clone()].into(),
}).collect::<Vec<_>>() }).collect::<Vec<_>>()
}; };
@@ -24,7 +24,6 @@ assert_matches = "1.4.0"
env_logger = "0.8.4" env_logger = "0.8.4"
futures-timer = "3.0.2" futures-timer = "3.0.2"
log = "0.4.11" log = "0.4.11"
smallvec = "1.5.1"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -20,7 +20,6 @@ use std::sync::Arc;
use futures::{executor, future}; use futures::{executor, future};
use futures_timer::Delay; use futures_timer::Delay;
use assert_matches::assert_matches; use assert_matches::assert_matches;
use smallvec::smallvec;
use parity_scale_codec::Encode; use parity_scale_codec::Encode;
@@ -446,15 +445,12 @@ fn availability_is_recovered_from_chunks_if_no_group_provided() {
test_harness_fast_path(|mut virtual_overseer| async move { test_harness_fast_path(|mut virtual_overseer| async move {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: smallvec![ActivatedLeaf { hash: test_state.current.clone(),
hash: test_state.current.clone(), number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}],
deactivated: smallvec![],
}),
).await; ).await;
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
@@ -528,15 +524,12 @@ fn availability_is_recovered_from_chunks_even_if_backing_group_supplied_if_chunk
test_harness_chunks_only(|mut virtual_overseer| async move { test_harness_chunks_only(|mut virtual_overseer| async move {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: smallvec![ActivatedLeaf { hash: test_state.current.clone(),
hash: test_state.current.clone(), number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}],
deactivated: smallvec![],
}),
).await; ).await;
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
@@ -610,15 +603,12 @@ fn bad_merkle_path_leads_to_recovery_error() {
test_harness_fast_path(|mut virtual_overseer| async move { test_harness_fast_path(|mut virtual_overseer| async move {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: smallvec![ActivatedLeaf { hash: test_state.current.clone(),
hash: test_state.current.clone(), number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}],
deactivated: smallvec![],
}),
).await; ).await;
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
@@ -667,15 +657,12 @@ fn wrong_chunk_index_leads_to_recovery_error() {
test_harness_fast_path(|mut virtual_overseer| async move { test_harness_fast_path(|mut virtual_overseer| async move {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: smallvec![ActivatedLeaf { hash: test_state.current.clone(),
hash: test_state.current.clone(), number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}],
deactivated: smallvec![],
}),
).await; ).await;
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
@@ -741,15 +728,12 @@ fn invalid_erasure_coding_leads_to_invalid_error() {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: smallvec![ActivatedLeaf { hash: test_state.current.clone(),
hash: test_state.current.clone(), number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}],
deactivated: smallvec![],
}),
).await; ).await;
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
@@ -789,15 +773,12 @@ fn fast_path_backing_group_recovers() {
test_harness_fast_path(|mut virtual_overseer| async move { test_harness_fast_path(|mut virtual_overseer| async move {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: smallvec![ActivatedLeaf { hash: test_state.current.clone(),
hash: test_state.current.clone(), number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}],
deactivated: smallvec![],
}),
).await; ).await;
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
@@ -842,15 +823,12 @@ fn no_answers_in_fast_path_causes_chunk_requests() {
test_harness_fast_path(|mut virtual_overseer| async move { test_harness_fast_path(|mut virtual_overseer| async move {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: smallvec![ActivatedLeaf { hash: test_state.current.clone(),
hash: test_state.current.clone(), number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}],
deactivated: smallvec![],
}),
).await; ).await;
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
@@ -905,15 +883,12 @@ fn task_canceled_when_receivers_dropped() {
test_harness_chunks_only(|mut virtual_overseer| async move { test_harness_chunks_only(|mut virtual_overseer| async move {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: smallvec![ActivatedLeaf { hash: test_state.current.clone(),
hash: test_state.current.clone(), number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}],
deactivated: smallvec![],
}),
).await; ).await;
let (tx, _) = oneshot::channel(); let (tx, _) = oneshot::channel();
@@ -948,15 +923,12 @@ fn chunks_retry_until_all_nodes_respond() {
test_harness_chunks_only(|mut virtual_overseer| async move { test_harness_chunks_only(|mut virtual_overseer| async move {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: smallvec![ActivatedLeaf { hash: test_state.current.clone(),
hash: test_state.current.clone(), number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}],
deactivated: smallvec![],
}),
).await; ).await;
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
@@ -1007,15 +979,12 @@ fn returns_early_if_we_have_the_data() {
test_harness_chunks_only(|mut virtual_overseer| async move { test_harness_chunks_only(|mut virtual_overseer| async move {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: smallvec![ActivatedLeaf { hash: test_state.current.clone(),
hash: test_state.current.clone(), number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}],
deactivated: smallvec![],
}),
).await; ).await;
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
@@ -1045,15 +1014,12 @@ fn does_not_query_local_validator() {
test_harness_chunks_only(|mut virtual_overseer| async move { test_harness_chunks_only(|mut virtual_overseer| async move {
overseer_signal( overseer_signal(
&mut virtual_overseer, &mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: smallvec![ActivatedLeaf { hash: test_state.current.clone(),
hash: test_state.current.clone(), number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}],
deactivated: smallvec![],
}),
).await; ).await;
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
+1 -1
View File
@@ -401,7 +401,7 @@ where
tracing::trace!( tracing::trace!(
target: LOG_TARGET, target: LOG_TARGET,
action = "ActiveLeaves", action = "ActiveLeaves",
num_activated = %activated.len(), has_activated = activated.is_some(),
num_deactivated = %deactivated.len(), num_deactivated = %deactivated.len(),
); );
+31 -29
View File
@@ -1336,31 +1336,22 @@ fn our_view_updates_decreasing_order_and_limited_to_max() {
// to show that we're still connected on the collation protocol, send a view update. // to show that we're still connected on the collation protocol, send a view update.
let hashes = (0..MAX_VIEW_HEADS * 3).map(|i| Hash::repeat_byte(i as u8)); let hashes = (0..MAX_VIEW_HEADS + 1).map(|i| Hash::repeat_byte(i as u8));
virtual_overseer.send( for (i, hash) in hashes.enumerate().rev() {
FromOverseer::Signal(OverseerSignal::ActiveLeaves( // These are in reverse order, so the subsystem must sort internally to
// These are in reverse order, so the subsystem must sort internally to // get the correct view.
// get the correct view. virtual_overseer.send(
ActiveLeavesUpdate { FromOverseer::Signal(OverseerSignal::ActiveLeaves(
activated: hashes.enumerate().map(|(i, h)| ActivatedLeaf { ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: h, hash,
number: i as _, number: i as _,
status: LeafStatus::Fresh, status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled), span: Arc::new(jaeger::Span::Disabled),
}).rev().collect(), }),
deactivated: Default::default(), ))
} ).await;
)) }
).await;
let view_heads = (MAX_VIEW_HEADS * 2 .. MAX_VIEW_HEADS * 3).rev()
.map(|i| (Hash::repeat_byte(i as u8), Arc::new(jaeger::Span::Disabled)) );
let our_view = OurView::new(
view_heads,
0,
);
assert_matches!( assert_matches!(
virtual_overseer.recv().await, virtual_overseer.recv().await,
@@ -1375,15 +1366,26 @@ fn our_view_updates_decreasing_order_and_limited_to_max() {
) )
); );
assert_sends_validation_event_to_all( let our_views = (1..=MAX_VIEW_HEADS).rev()
NetworkBridgeEvent::OurViewChange(our_view.clone()), .map(|start| OurView::new(
&mut virtual_overseer, (start..=MAX_VIEW_HEADS)
).await; .rev()
.map(|i| (Hash::repeat_byte(i as u8), Arc::new(jaeger::Span::Disabled))),
0,
));
for our_view in our_views {
assert_sends_validation_event_to_all(
NetworkBridgeEvent::OurViewChange(our_view.clone()),
&mut virtual_overseer,
).await;
assert_sends_collation_event_to_all(
NetworkBridgeEvent::OurViewChange(our_view),
&mut virtual_overseer,
).await;
}
assert_sends_collation_event_to_all(
NetworkBridgeEvent::OurViewChange(our_view),
&mut virtual_overseer,
).await;
virtual_overseer virtual_overseer
}); });
} }
@@ -286,15 +286,12 @@ async fn setup_system(virtual_overseer: &mut VirtualOverseer, test_state: &TestS
overseer_signal( overseer_signal(
virtual_overseer, virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: vec![ActivatedLeaf { hash: test_state.relay_parent,
hash: test_state.relay_parent, number: 1,
number: 1, status: LeafStatus::Fresh,
status: LeafStatus::Fresh, span: Arc::new(jaeger::Span::Disabled),
span: Arc::new(jaeger::Span::Disabled), })),
}].into(),
deactivated: [][..].into(),
}),
).await; ).await;
overseer_send( overseer_send(
@@ -615,16 +615,14 @@ async fn activate_leaf(
handle.send(FromOverseer::Signal( handle.send(FromOverseer::Signal(
OverseerSignal::ActiveLeaves( OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate { ActiveLeavesUpdate {
activated: [ActivatedLeaf { activated: Some(ActivatedLeaf {
hash: activate, hash: activate,
number: 10, number: 10,
status: LeafStatus::Fresh, status: LeafStatus::Fresh,
span: Arc::new(Span::Disabled), span: Arc::new(Span::Disabled),
}][..] }),
.into(),
deactivated: deactivate.into_iter().collect(), deactivated: deactivate.into_iter().collect(),
} }
))) )))
.await; .await;
assert_matches!( assert_matches!(
@@ -652,15 +652,14 @@ fn receiving_from_one_sends_to_another_and_to_candidate_backing() {
let test_fut = async move { let test_fut = async move {
// register our active heads. // register our active heads.
handle.send(FromOverseer::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { handle.send(FromOverseer::Signal(
activated: vec![ActivatedLeaf { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a, hash: hash_a,
number: 1, number: 1,
status: LeafStatus::Fresh, status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled), span: Arc::new(jaeger::Span::Disabled),
}].into(), })),
deactivated: vec![].into(), )).await;
}))).await;
assert_matches!( assert_matches!(
handle.recv().await, handle.recv().await,
@@ -828,15 +827,14 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
}).await; }).await;
// register our active heads. // register our active heads.
handle.send(FromOverseer::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { handle.send(FromOverseer::Signal(
activated: vec![ActivatedLeaf { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a, hash: hash_a,
number: 1, number: 1,
status: LeafStatus::Fresh, status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled), span: Arc::new(jaeger::Span::Disabled),
}].into(), })),
deactivated: vec![].into(), )).await;
}))).await;
assert_matches!( assert_matches!(
handle.recv().await, handle.recv().await,
@@ -1300,15 +1298,14 @@ fn share_prioritizes_backing_group() {
}).await; }).await;
// register our active heads. // register our active heads.
handle.send(FromOverseer::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { handle.send(FromOverseer::Signal(
activated: vec![ActivatedLeaf { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a, hash: hash_a,
number: 1, number: 1,
status: LeafStatus::Fresh, status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled), span: Arc::new(jaeger::Span::Disabled),
}].into(), })),
deactivated: vec![].into(), )).await;
}))).await;
assert_matches!( assert_matches!(
handle.recv().await, handle.recv().await,
@@ -1556,15 +1553,14 @@ fn peer_cant_flood_with_large_statements() {
}).await; }).await;
// register our active heads. // register our active heads.
handle.send(FromOverseer::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { handle.send(FromOverseer::Signal(
activated: vec![ActivatedLeaf { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a, hash: hash_a,
number: 1, number: 1,
status: LeafStatus::Fresh, status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled), span: Arc::new(jaeger::Span::Disabled),
}].into(), })),
deactivated: vec![].into(), )).await;
}))).await;
assert_matches!( assert_matches!(
handle.recv().await, handle.recv().await,
+6 -10
View File
@@ -706,31 +706,27 @@ where
/// Stop the overseer. /// Stop the overseer.
async fn stop(mut self) { async fn stop(mut self) {
let _ = self.wait_terminate( let _ = self.wait_terminate(
OverseerSignal::Conclude, OverseerSignal::Conclude,
::std::time::Duration::from_secs(1_u64) Duration::from_secs(1_u64)
).await; ).await;
} }
/// Run the `Overseer`. /// Run the `Overseer`.
pub async fn run(mut self) -> SubsystemResult<()> { pub async fn run(mut self) -> SubsystemResult<()> {
let mut update = ActiveLeavesUpdate::default(); // Notify about active leaves on startup before starting the loop
for (hash, number) in std::mem::take(&mut self.leaves) { for (hash, number) in std::mem::take(&mut self.leaves) {
let _ = self.active_leaves.insert(hash, number); let _ = self.active_leaves.insert(hash, number);
if let Some((span, status)) = self.on_head_activated(&hash, None) { if let Some((span, status)) = self.on_head_activated(&hash, None) {
update.activated.push(ActivatedLeaf { let update = ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash, hash,
number, number,
status, status,
span, span,
}); });
self.broadcast_signal(OverseerSignal::ActiveLeaves(update)).await?;
} }
} }
if !update.is_empty() {
self.broadcast_signal(OverseerSignal::ActiveLeaves(update)).await?;
}
loop { loop {
select! { select! {
msg = self.events_rx.select_next_some() => { msg = self.events_rx.select_next_some() => {
+22 -32
View File
@@ -427,21 +427,21 @@ fn overseer_start_stop_works() {
status: LeafStatus::Fresh, status: LeafStatus::Fresh,
})), })),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
activated: [ActivatedLeaf { activated: Some(ActivatedLeaf {
hash: second_block_hash, hash: second_block_hash,
number: 2, number: 2,
span: Arc::new(jaeger::Span::Disabled), span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh, status: LeafStatus::Fresh,
}].as_ref().into(), }),
deactivated: [first_block_hash].as_ref().into(), deactivated: [first_block_hash].as_ref().into(),
}), }),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
activated: [ActivatedLeaf { activated: Some(ActivatedLeaf {
hash: third_block_hash, hash: third_block_hash,
number: 3, number: 3,
span: Arc::new(jaeger::Span::Disabled), span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh, status: LeafStatus::Fresh,
}].as_ref().into(), }),
deactivated: [second_block_hash].as_ref().into(), deactivated: [second_block_hash].as_ref().into(),
}), }),
]; ];
@@ -530,23 +530,18 @@ fn overseer_finalize_works() {
handle.block_finalized(third_block).await; handle.block_finalized(third_block).await;
let expected_heartbeats = vec![ let expected_heartbeats = vec![
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: [ hash: first_block_hash,
ActivatedLeaf { number: 1,
hash: first_block_hash, span: Arc::new(jaeger::Span::Disabled),
number: 1, status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled), })),
status: LeafStatus::Fresh, OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
}, hash: second_block_hash,
ActivatedLeaf { number: 2,
hash: second_block_hash, span: Arc::new(jaeger::Span::Disabled),
number: 2, status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled), })),
status: LeafStatus::Fresh,
},
].as_ref().into(),
..Default::default()
}),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
deactivated: [first_block_hash, second_block_hash].as_ref().into(), deactivated: [first_block_hash, second_block_hash].as_ref().into(),
..Default::default() ..Default::default()
@@ -630,17 +625,12 @@ fn do_not_send_empty_leaves_update_on_block_finalization() {
handle.block_imported(imported_block.clone()).await; handle.block_imported(imported_block.clone()).await;
let expected_heartbeats = vec![ let expected_heartbeats = vec![
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate { OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
activated: [ hash: imported_block.hash,
ActivatedLeaf { number: imported_block.number,
hash: imported_block.hash, span: Arc::new(jaeger::Span::Disabled),
number: imported_block.number, status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled), })),
status: LeafStatus::Fresh,
}
].as_ref().into(),
..Default::default()
}),
OverseerSignal::BlockFinalized(finalized_block.hash, 1), OverseerSignal::BlockFinalized(finalized_block.hash, 1),
]; ];
+7 -14
View File
@@ -90,8 +90,8 @@ pub struct ActivatedLeaf {
/// Note that the activated and deactivated fields indicate deltas, not complete sets. /// Note that the activated and deactivated fields indicate deltas, not complete sets.
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct ActiveLeavesUpdate { pub struct ActiveLeavesUpdate {
/// New relay chain blocks of interest. /// New relay chain block of interest.
pub activated: SmallVec<[ActivatedLeaf; ACTIVE_LEAVES_SMALLVEC_CAPACITY]>, pub activated: Option<ActivatedLeaf>,
/// Relay chain block hashes no longer of interest. /// Relay chain block hashes no longer of interest.
pub deactivated: SmallVec<[Hash; ACTIVE_LEAVES_SMALLVEC_CAPACITY]>, pub deactivated: SmallVec<[Hash; ACTIVE_LEAVES_SMALLVEC_CAPACITY]>,
} }
@@ -99,7 +99,7 @@ pub struct ActiveLeavesUpdate {
impl ActiveLeavesUpdate { impl ActiveLeavesUpdate {
/// Create a `ActiveLeavesUpdate` with a single activated hash /// Create a `ActiveLeavesUpdate` with a single activated hash
pub fn start_work(activated: ActivatedLeaf) -> Self { pub fn start_work(activated: ActivatedLeaf) -> Self {
Self { activated: [activated][..].into(), ..Default::default() } Self { activated: Some(activated), ..Default::default() }
} }
/// Create a `ActiveLeavesUpdate` with a single deactivated hash /// Create a `ActiveLeavesUpdate` with a single deactivated hash
@@ -109,7 +109,7 @@ impl ActiveLeavesUpdate {
/// Is this update empty and doesn't contain any information? /// Is this update empty and doesn't contain any information?
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.activated.is_empty() && self.deactivated.is_empty() self.activated.is_none() && self.deactivated.is_empty()
} }
} }
@@ -118,23 +118,16 @@ impl PartialEq for ActiveLeavesUpdate {
/// ///
/// Instead, it means equality when `activated` and `deactivated` are considered as sets. /// Instead, it means equality when `activated` and `deactivated` are considered as sets.
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.activated.len() == other.activated.len() && self.deactivated.len() == other.deactivated.len() self.activated.as_ref().map(|a| a.hash) == other.activated.as_ref().map(|a| a.hash)
&& self.activated.iter().all(|a| other.activated.iter().any(|o| a.hash == o.hash)) && self.deactivated.len() == other.deactivated.len()
&& self.deactivated.iter().all(|a| other.deactivated.contains(a)) && self.deactivated.iter().all(|a| other.deactivated.contains(a))
} }
} }
impl fmt::Debug for ActiveLeavesUpdate { impl fmt::Debug for ActiveLeavesUpdate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
struct Activated<'a>(&'a [ActivatedLeaf]);
impl fmt::Debug for Activated<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_list().entries(self.0.iter().map(|e| e.hash)).finish()
}
}
f.debug_struct("ActiveLeavesUpdate") f.debug_struct("ActiveLeavesUpdate")
.field("activated", &Activated(&self.activated)) .field("activated", &self.activated)
.field("deactivated", &self.deactivated) .field("deactivated", &self.deactivated)
.finish() .finish()
} }