polkadot: pin one block per session (#1220)

* polkadot: propagate UnpinHandle to ActiveLeafUpdate

Also extract the leaf creation for tests
into a common function.

* dispute-coordinator: try pinned blocks for slashin

* apparently 1.72 is smarter than 1.70

* address nits

* rename fresh_leaf to new_leaf
This commit is contained in:
ordian
2023-09-07 12:24:40 +02:00
committed by GitHub
parent 1346143194
commit 15503883e2
33 changed files with 387 additions and 620 deletions
Generated
+6 -1
View File
@@ -12303,9 +12303,10 @@ dependencies = [
"parking_lot 0.12.1",
"polkadot-node-subsystem",
"polkadot-node-subsystem-util",
"polkadot-overseer",
"polkadot-primitives",
"sc-client-api",
"sc-keystore",
"sc-utils",
"sp-application-crypto",
"sp-core",
"sp-keyring",
@@ -12325,6 +12326,7 @@ dependencies = [
"polkadot-node-primitives",
"polkadot-primitives",
"polkadot-statement-table",
"sc-client-api",
"sc-network",
"sc-transaction-pool-api",
"smallvec",
@@ -12362,11 +12364,13 @@ dependencies = [
"polkadot-node-primitives",
"polkadot-node-subsystem",
"polkadot-node-subsystem-test-helpers",
"polkadot-node-subsystem-types",
"polkadot-overseer",
"polkadot-primitives",
"polkadot-primitives-test-helpers",
"prioritized-metered-channel",
"rand 0.8.5",
"sc-client-api",
"schnellru",
"sp-application-crypto",
"sp-core",
@@ -12390,6 +12394,7 @@ dependencies = [
"polkadot-node-metrics",
"polkadot-node-network-protocol",
"polkadot-node-primitives",
"polkadot-node-subsystem-test-helpers",
"polkadot-node-subsystem-types",
"polkadot-primitives",
"polkadot-primitives-test-helpers",
@@ -36,13 +36,14 @@ use polkadot_node_network_protocol::{
use polkadot_node_subsystem_util::metrics::{prometheus::Registry, Metrics};
use polkadot_overseer::{
BlockInfo, DummySubsystem, Handle, Overseer, OverseerConnector, OverseerHandle, SpawnGlue,
KNOWN_LEAVES_CACHE_SIZE,
UnpinHandle, KNOWN_LEAVES_CACHE_SIZE,
};
use polkadot_primitives::CollatorPair;
use sc_authority_discovery::Service as AuthorityDiscoveryService;
use sc_network::NetworkStateInfo;
use sc_service::TaskManager;
use sc_utils::mpsc::tracing_unbounded;
use sp_runtime::traits::Block as BlockT;
use cumulus_primitives_core::relay_chain::{Block, Hash as PHash};
@@ -221,20 +222,25 @@ async fn forward_collator_events(
) -> Result<(), RelayChainError> {
let mut finality = client.finality_notification_stream().await?.fuse();
let mut imports = client.import_notification_stream().await?.fuse();
// Collators do no need to pin any specific blocks
let (dummy_sink, _) = tracing_unbounded("does-not-matter", 42);
let dummy_unpin_handle = UnpinHandle::new(Default::default(), dummy_sink);
loop {
select! {
f = finality.next() => {
match f {
Some(header) => {
let hash = header.hash();
tracing::info!(
target: "minimal-polkadot-node",
"Received finalized block via RPC: #{} ({} -> {})",
header.number,
header.parent_hash,
header.hash()
hash,
);
let block_info = BlockInfo { hash: header.hash(), parent_hash: header.parent_hash, number: header.number };
let unpin_handle = dummy_unpin_handle.clone();
let block_info = BlockInfo { hash, parent_hash: header.parent_hash, number: header.number, unpin_handle };
handle.block_finalized(block_info).await;
}
None => return Err(RelayChainError::GenericError("Relay chain finality stream ended.".to_string())),
@@ -243,14 +249,16 @@ async fn forward_collator_events(
i = imports.next() => {
match i {
Some(header) => {
let hash = header.hash();
tracing::info!(
target: "minimal-polkadot-node",
"Received imported block via RPC: #{} ({} -> {})",
header.number,
header.parent_hash,
header.hash()
hash,
);
let block_info = BlockInfo { hash: header.hash(), parent_hash: header.parent_hash, number: header.number };
let unpin_handle = dummy_unpin_handle.clone();
let block_info = BlockInfo { hash, parent_hash: header.parent_hash, number: header.number, unpin_handle };
handle.block_imported(block_info).await;
}
None => return Err(RelayChainError::GenericError("Relay chain import stream ended.".to_string())),
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use self::test_helpers::mock::new_leaf;
use super::*;
use polkadot_node_primitives::{
approval::{
@@ -26,7 +27,7 @@ use polkadot_node_subsystem::{
messages::{
AllMessages, ApprovalVotingMessage, AssignmentCheckResult, AvailabilityRecoveryMessage,
},
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
ActiveLeavesUpdate,
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_util::TimeoutExt;
@@ -777,12 +778,7 @@ async fn import_block(
overseer_send(
overseer,
FromOrchestra::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(
ActivatedLeaf {
hash: *new_head,
number,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
},
new_leaf(*new_head, number),
))),
)
.await;
+17 -32
View File
@@ -19,14 +19,14 @@ use super::*;
use assert_matches::assert_matches;
use futures::{channel::oneshot, executor, future, Future};
use self::test_helpers::mock::new_leaf;
use ::test_helpers::TestCandidateBuilder;
use parking_lot::Mutex;
use polkadot_node_primitives::{AvailableData, BlockData, PoV, Proof};
use polkadot_node_subsystem::{
errors::RuntimeApiError,
jaeger,
messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest},
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
ActiveLeavesUpdate,
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_util::{database::Database, TimeoutExt};
@@ -219,16 +219,11 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
let store = test_store();
test_harness(TestState::default(), store, |mut virtual_overseer| async move {
let new_leaf = Hash::repeat_byte(0x01);
let a_leaf = Hash::repeat_byte(0x01);
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: new_leaf,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(a_leaf, 1))),
)
.await;
@@ -246,7 +241,7 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
relay_parent,
tx,
)) => {
assert_eq!(relay_parent, new_leaf);
assert_eq!(relay_parent, a_leaf);
tx.send(Ok(Some(header))).unwrap();
}
);
@@ -258,7 +253,7 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
relay_parent,
RuntimeApiRequest::CandidateEvents(tx),
)) => {
assert_eq!(relay_parent, new_leaf);
assert_eq!(relay_parent, a_leaf);
#[derive(Debug)]
struct FauxError;
impl std::error::Error for FauxError {}
@@ -741,7 +736,7 @@ fn stored_data_kept_until_finalized() {
available_data,
);
let new_leaf = import_leaf(
let a_leaf = import_leaf(
&mut virtual_overseer,
parent,
block_number,
@@ -764,7 +759,7 @@ fn stored_data_kept_until_finalized() {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::BlockFinalized(new_leaf, block_number),
OverseerSignal::BlockFinalized(a_leaf, block_number),
)
.await;
@@ -849,16 +844,11 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
extrinsics_root: Hash::zero(),
digest: Default::default(),
};
let new_leaf = Hash::repeat_byte(4);
let a_leaf = Hash::repeat_byte(4);
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: new_leaf,
number: 4,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(a_leaf, 4))),
)
.await;
@@ -868,7 +858,7 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
relay_parent,
tx,
)) => {
assert_eq!(relay_parent, new_leaf);
assert_eq!(relay_parent, a_leaf);
tx.send(Ok(Some(header))).unwrap();
}
);
@@ -886,7 +876,7 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
k,
response_channel: tx,
}) => {
assert_eq!(hash, new_leaf);
assert_eq!(hash, a_leaf);
assert_eq!(k, 2);
let _ = tx.send(Ok(vec![
Hash::repeat_byte(3),
@@ -1166,16 +1156,11 @@ async fn import_leaf(
extrinsics_root: Hash::zero(),
digest: Default::default(),
};
let new_leaf = header.hash();
let a_leaf = header.hash();
overseer_signal(
virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: new_leaf,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(a_leaf, 1))),
)
.await;
@@ -1185,7 +1170,7 @@ async fn import_leaf(
relay_parent,
tx,
)) => {
assert_eq!(relay_parent, new_leaf);
assert_eq!(relay_parent, a_leaf);
tx.send(Ok(Some(header))).unwrap();
}
);
@@ -1196,7 +1181,7 @@ async fn import_leaf(
relay_parent,
RuntimeApiRequest::CandidateEvents(tx),
)) => {
assert_eq!(relay_parent, new_leaf);
assert_eq!(relay_parent, a_leaf);
tx.send(Ok(events)).unwrap();
}
);
@@ -1212,7 +1197,7 @@ async fn import_leaf(
}
);
new_leaf
a_leaf
}
#[test]
+3 -8
View File
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use self::test_helpers::mock::new_leaf;
use super::*;
use ::test_helpers::{
dummy_candidate_receipt_bad_sig, dummy_collator, dummy_collator_signature,
@@ -24,12 +25,11 @@ use futures::{future, Future};
use polkadot_node_primitives::{BlockData, InvalidCandidate, SignedFullStatement, Statement};
use polkadot_node_subsystem::{
errors::RuntimeApiError,
jaeger,
messages::{
AllMessages, CollatorProtocolMessage, RuntimeApiMessage, RuntimeApiRequest,
ValidationFailed,
},
ActivatedLeaf, ActiveLeavesUpdate, FromOrchestra, LeafStatus, OverseerSignal, TimeoutExt,
ActiveLeavesUpdate, FromOrchestra, OverseerSignal, TimeoutExt,
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_primitives::{
@@ -234,12 +234,7 @@ async fn test_startup(virtual_overseer: &mut VirtualOverseer, test_state: &TestS
// Start work on some new parent.
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(
ActivatedLeaf {
hash: test_state.relay_parent,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
},
new_leaf(test_state.relay_parent, 1),
))))
.await;
@@ -18,7 +18,7 @@
use polkadot_node_subsystem::{
messages::{ChainApiMessage, FragmentTreeMembership},
TimeoutExt,
ActivatedLeaf, TimeoutExt,
};
use polkadot_primitives::{vstaging as vstaging_primitives, BlockNumber, Header, OccupiedCore};
@@ -346,12 +346,7 @@ fn seconding_sanity_check_allowed() {
// `a` is grandparent of `b`.
let leaf_a_hash = Hash::from_low_u64_be(130);
let leaf_a_parent = get_parent_hash(leaf_a_hash);
let activated = ActivatedLeaf {
hash: leaf_a_hash,
number: LEAF_A_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(leaf_a_hash, LEAF_A_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_A_BLOCK_NUMBER - LEAF_A_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };
@@ -359,12 +354,7 @@ fn seconding_sanity_check_allowed() {
const LEAF_B_ANCESTRY_LEN: BlockNumber = 4;
let leaf_b_hash = Hash::from_low_u64_be(128);
let activated = ActivatedLeaf {
hash: leaf_b_hash,
number: LEAF_B_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(leaf_b_hash, LEAF_B_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_B_BLOCK_NUMBER - LEAF_B_ANCESTRY_LEN)];
let test_leaf_b = TestLeaf { activated, min_relay_parents };
@@ -503,24 +493,14 @@ fn seconding_sanity_check_disallowed() {
// `a` is grandparent of `b`.
let leaf_a_hash = Hash::from_low_u64_be(130);
let leaf_a_parent = get_parent_hash(leaf_a_hash);
let activated = ActivatedLeaf {
hash: leaf_a_hash,
number: LEAF_A_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(leaf_a_hash, LEAF_A_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_A_BLOCK_NUMBER - LEAF_A_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };
const LEAF_B_BLOCK_NUMBER: BlockNumber = LEAF_A_BLOCK_NUMBER + 2;
const LEAF_B_ANCESTRY_LEN: BlockNumber = 4;
let activated = ActivatedLeaf {
hash: leaf_b_hash,
number: LEAF_B_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(leaf_b_hash, LEAF_B_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_B_BLOCK_NUMBER - LEAF_B_ANCESTRY_LEN)];
let test_leaf_b = TestLeaf { activated, min_relay_parents };
@@ -722,12 +702,7 @@ fn prospective_parachains_reject_candidate() {
let leaf_a_hash = Hash::from_low_u64_be(130);
let leaf_a_parent = get_parent_hash(leaf_a_hash);
let activated = ActivatedLeaf {
hash: leaf_a_hash,
number: LEAF_A_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(leaf_a_hash, LEAF_A_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_A_BLOCK_NUMBER - LEAF_A_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };
@@ -905,12 +880,7 @@ fn second_multiple_candidates_per_relay_parent() {
let leaf_hash = Hash::from_low_u64_be(130);
let leaf_parent = get_parent_hash(leaf_hash);
let leaf_grandparent = get_parent_hash(leaf_parent);
let activated = ActivatedLeaf {
hash: leaf_hash,
number: LEAF_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(leaf_hash, LEAF_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_BLOCK_NUMBER - LEAF_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };
@@ -1046,12 +1016,7 @@ fn backing_works() {
let leaf_hash = Hash::from_low_u64_be(130);
let leaf_parent = get_parent_hash(leaf_hash);
let activated = ActivatedLeaf {
hash: leaf_hash,
number: LEAF_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(leaf_hash, LEAF_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_BLOCK_NUMBER - LEAF_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };
@@ -1212,12 +1177,7 @@ fn concurrent_dependent_candidates() {
let leaf_hash = Hash::from_low_u64_be(130);
let leaf_parent = get_parent_hash(leaf_hash);
let leaf_grandparent = get_parent_hash(leaf_parent);
let activated = ActivatedLeaf {
hash: leaf_hash,
number: LEAF_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(leaf_hash, LEAF_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_BLOCK_NUMBER - LEAF_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };
@@ -1458,12 +1418,7 @@ fn seconding_sanity_check_occupy_same_depth() {
let leaf_hash = Hash::from_low_u64_be(130);
let leaf_parent = get_parent_hash(leaf_hash);
let activated = ActivatedLeaf {
hash: leaf_hash,
number: LEAF_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(leaf_hash, LEAF_BLOCK_NUMBER);
let min_block_number = LEAF_BLOCK_NUMBER - LEAF_ANCESTRY_LEN;
let min_relay_parents = vec![(para_id_a, min_block_number), (para_id_b, min_block_number)];
@@ -1617,12 +1572,7 @@ fn occupied_core_assignment() {
let leaf_a_hash = Hash::from_low_u64_be(130);
let leaf_a_parent = get_parent_hash(leaf_a_hash);
let activated = ActivatedLeaf {
hash: leaf_a_hash,
number: LEAF_A_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(leaf_a_hash, LEAF_A_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_A_BLOCK_NUMBER - LEAF_A_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };
@@ -35,11 +35,10 @@ use parity_scale_codec::Encode;
use parking_lot::Mutex;
use sp_core::testing::TaskExecutor;
use polkadot_node_subsystem::{
jaeger, messages::AllMessages, ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
};
use polkadot_node_subsystem::{messages::AllMessages, ActiveLeavesUpdate};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_primitives::{BlakeTwo256, ConsensusLog, HashT};
use test_helpers::mock::new_leaf;
#[derive(Default)]
struct TestBackendInner {
@@ -367,12 +366,10 @@ async fn import_blocks_into(
let hash = header.hash();
virtual_overseer
.send(
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
hash,
number: header.number,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}))
header.number,
)))
.into(),
)
.await;
@@ -425,12 +422,10 @@ async fn import_all_blocks_into(
let (_, write_rx) = backend.await_next_write();
virtual_overseer
.send(
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: head_hash,
number: head.number,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}))
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
head_hash,
head.number,
)))
.into(),
)
.await;
@@ -308,6 +308,8 @@ impl Initialized {
Ok(session_idx)
if self.gaps_in_cache || session_idx > self.highest_session_seen =>
{
// Pin the block from the new session.
self.runtime_info.pin_block(session_idx, new_leaf.unpin_handle);
// Fetch the last `DISPUTE_WINDOW` number of sessions unless there are no gaps
// in cache and we are not missing too many `SessionInfo`s
let mut lower_bound = session_idx.saturating_sub(DISPUTE_WINDOW.get() - 1);
@@ -387,26 +389,28 @@ impl Initialized {
"Processing unapplied validator slashes",
);
let pinned_hash = self.runtime_info.get_block_in_session(session_index);
let inclusions = self.scraper.get_blocks_including_candidate(&candidate_hash);
if inclusions.is_empty() {
if pinned_hash.is_none() && inclusions.is_empty() {
gum::info!(
target: LOG_TARGET,
"Couldn't find inclusion parent for an unapplied slash",
?session_index,
"Couldn't find blocks in the session for an unapplied slash",
);
return
}
// Find the first inclusion parent that we can use
// Find a relay block that we can use
// to generate key ownership proof on.
// We use inclusion parents because of the proper session index.
// We use inclusion parents as a fallback.
let mut key_ownership_proofs = Vec::new();
let mut dispute_proofs = Vec::new();
for (_height, inclusion_parent) in inclusions {
let blocks_in_the_session =
pinned_hash.into_iter().chain(inclusions.into_iter().map(|(_n, h)| h));
for hash in blocks_in_the_session {
for (validator_index, validator_id) in pending.keys.iter() {
let res =
key_ownership_proof(ctx.sender(), inclusion_parent, validator_id.clone())
.await;
let res = key_ownership_proof(ctx.sender(), hash, validator_id.clone()).await;
match res {
Ok(Some(key_ownership_proof)) => {
@@ -28,15 +28,14 @@ use ::test_helpers::{
use parity_scale_codec::Encode;
use polkadot_node_primitives::{AvailableData, BlockData, InvalidCandidate, PoV};
use polkadot_node_subsystem::{
jaeger,
messages::{
AllMessages, ChainApiMessage, DisputeCoordinatorMessage, RuntimeApiMessage,
RuntimeApiRequest,
},
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus, SpawnGlue,
ActiveLeavesUpdate, SpawnGlue,
};
use polkadot_node_subsystem_test_helpers::{
make_subsystem_context, TestSubsystemContext, TestSubsystemContextHandle,
make_subsystem_context, mock::new_leaf, TestSubsystemContext, TestSubsystemContextHandle,
};
use polkadot_primitives::{
BlakeTwo256, CandidateCommitments, HashT, Header, PersistedValidationData, ValidationCode,
@@ -100,12 +99,7 @@ async fn activate_leaf<Context>(
participation
.process_active_leaves_update(
ctx,
&ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: block_hash,
span: Arc::new(jaeger::Span::Disabled),
number: block_number,
status: LeafStatus::Fresh,
}),
&ActiveLeavesUpdate::start_work(new_leaf(block_hash, block_number)),
)
.await
}
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use std::{sync::Arc, time::Duration};
use std::time::Duration;
use assert_matches::assert_matches;
@@ -25,15 +25,15 @@ use sp_core::testing::TaskExecutor;
use ::test_helpers::{dummy_collator, dummy_collator_signature, dummy_hash};
use polkadot_node_primitives::DISPUTE_CANDIDATE_LIFETIME_AFTER_FINALIZATION;
use polkadot_node_subsystem::{
jaeger,
messages::{
AllMessages, ChainApiMessage, DisputeCoordinatorMessage, RuntimeApiMessage,
RuntimeApiRequest,
},
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus, SpawnGlue,
ActivatedLeaf, ActiveLeavesUpdate, SpawnGlue,
};
use polkadot_node_subsystem_test_helpers::{
make_subsystem_context, TestSubsystemContext, TestSubsystemContextHandle, TestSubsystemSender,
make_subsystem_context, mock::new_leaf, TestSubsystemContext, TestSubsystemContextHandle,
TestSubsystemSender,
};
use polkadot_node_subsystem_util::{reexports::SubsystemContext, TimeoutExt};
use polkadot_primitives::{
@@ -141,12 +141,7 @@ fn make_candidate_receipt(relay_parent: Hash) -> CandidateReceipt {
/// Get a dummy `ActivatedLeaf` for a given block number.
fn get_activated_leaf(n: BlockNumber) -> ActivatedLeaf {
ActivatedLeaf {
hash: get_block_number_hash(n),
number: n,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}
new_leaf(get_block_number_hash(n), n)
}
/// Get a dummy relay parent hash for dummy block number.
@@ -54,12 +54,11 @@ use sp_keystore::{Keystore, KeystorePtr};
use ::test_helpers::{dummy_candidate_receipt_bad_sig, dummy_digest, dummy_hash};
use polkadot_node_primitives::{Timestamp, ACTIVE_DURATION_SECS};
use polkadot_node_subsystem::{
jaeger,
messages::{AllMessages, BlockDescription, RuntimeApiMessage, RuntimeApiRequest},
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
ActiveLeavesUpdate,
};
use polkadot_node_subsystem_test_helpers::{
make_buffered_subsystem_context, TestSubsystemContextHandle,
make_buffered_subsystem_context, mock::new_leaf, TestSubsystemContextHandle,
};
use polkadot_primitives::{
ApprovalVote, BlockNumber, CandidateCommitments, CandidateEvent, CandidateHash,
@@ -276,12 +275,7 @@ impl TestState {
gum::debug!(?block_number, "Activating block in activate_leaf_at_session.");
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: block_hash,
span: Arc::new(jaeger::Span::Disabled),
number: block_number,
status: LeafStatus::Fresh,
}),
ActiveLeavesUpdate::start_work(new_leaf(block_hash, block_number)),
)))
.await;
@@ -449,12 +443,7 @@ impl TestState {
);
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: *leaf,
number: n as u32,
span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh,
}),
ActiveLeavesUpdate::start_work(new_leaf(*leaf, n as u32)),
)))
.await;
@@ -24,7 +24,6 @@ use polkadot_node_subsystem::{
},
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_types::{jaeger, ActivatedLeaf, LeafStatus};
use polkadot_primitives::{
vstaging::{AsyncBackingParams, BackingState, Constraints, InboundHrmpLimitations},
CommittedCandidateReceipt, HeadData, Header, PersistedValidationData, ScheduledCore,
@@ -32,6 +31,7 @@ use polkadot_primitives::{
};
use polkadot_primitives_test_helpers::make_candidate;
use std::sync::Arc;
use test_helpers::mock::new_leaf;
const ALLOWED_ANCESTRY_LEN: u32 = 3;
const ASYNC_BACKING_PARAMETERS: AsyncBackingParams =
@@ -197,12 +197,7 @@ async fn activate_leaf_with_params(
) {
let TestLeaf { number, hash, .. } = leaf;
let activated = ActivatedLeaf {
hash: *hash,
number: *number,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(*hash, *number);
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(
@@ -497,12 +492,7 @@ fn should_do_no_work_if_async_backing_disabled_for_leaf() {
// Start work on some new parent.
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash, 1)),
)))
.await;
@@ -1318,12 +1308,7 @@ fn correctly_updates_leaves() {
.await;
// Activate a leaf and remove one at the same time.
let activated = ActivatedLeaf {
hash: leaf_c.hash,
number: leaf_c.number,
span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh,
};
let activated = new_leaf(leaf_c.hash, leaf_c.number);
let update = ActiveLeavesUpdate {
activated: Some(activated),
deactivated: [leaf_b.hash][..].into(),
@@ -1349,12 +1334,7 @@ fn correctly_updates_leaves() {
.await;
// Activate and deactivate the same leaf.
let activated = ActivatedLeaf {
hash: leaf_a.hash,
number: leaf_a.number,
span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh,
};
let activated = new_leaf(leaf_a.hash, leaf_a.number);
let update = ActiveLeavesUpdate {
activated: Some(activated),
deactivated: [leaf_a.hash][..].into(),
@@ -1578,12 +1558,7 @@ fn uses_ancestry_only_within_session() {
vec![Hash::repeat_byte(4), Hash::repeat_byte(3), Hash::repeat_byte(2)];
let session_change_hash = Hash::repeat_byte(3);
let activated = ActivatedLeaf {
hash,
number,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(hash, number);
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
@@ -24,12 +24,11 @@ use polkadot_node_primitives::{CandidateVotes, DisputeStatus, ACTIVE_DURATION_SE
use polkadot_node_subsystem::messages::{
AllMessages, DisputeCoordinatorMessage, RuntimeApiMessage, RuntimeApiRequest,
};
use polkadot_node_subsystem_test_helpers::TestSubsystemSender;
use polkadot_node_subsystem_test_helpers::{mock::new_leaf, TestSubsystemSender};
use polkadot_primitives::{
CandidateHash, DisputeState, InvalidDisputeStatementKind, SessionIndex,
ValidDisputeStatementKind, ValidatorSignature,
};
use std::sync::Arc;
use test_helpers;
//
@@ -353,12 +352,7 @@ async fn mock_overseer(
}
fn leaf() -> ActivatedLeaf {
ActivatedLeaf {
hash: Hash::repeat_byte(0xAA),
number: 0xAA,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}
new_leaf(Hash::repeat_byte(0xAA), 0xAA)
}
struct TestDisputes {
+5 -9
View File
@@ -17,14 +17,15 @@
use ::test_helpers::{dummy_digest, dummy_hash};
use futures::{channel::oneshot, future::BoxFuture, prelude::*};
use polkadot_node_subsystem::{
jaeger,
messages::{
AllMessages, CandidateValidationMessage, PreCheckOutcome, PvfCheckerMessage,
RuntimeApiMessage, RuntimeApiRequest,
},
ActivatedLeaf, ActiveLeavesUpdate, FromOrchestra, LeafStatus, OverseerSignal, RuntimeApiError,
ActiveLeavesUpdate, FromOrchestra, OverseerSignal, RuntimeApiError,
};
use polkadot_node_subsystem_test_helpers::{
make_subsystem_context, mock::new_leaf, TestSubsystemContextHandle,
};
use polkadot_node_subsystem_test_helpers::{make_subsystem_context, TestSubsystemContextHandle};
use polkadot_primitives::{
BlockNumber, Hash, Header, PvfCheckStatement, SessionIndex, ValidationCode, ValidationCodeHash,
ValidatorId,
@@ -195,12 +196,7 @@ impl TestState {
},
);
Some(ActivatedLeaf {
hash: activated_leaf.block_hash,
span: Arc::new(jaeger::Span::Disabled),
number: activated_leaf.block_number,
status: LeafStatus::Fresh,
})
Some(new_leaf(activated_leaf.block_hash, activated_leaf.block_number))
} else {
None
};
@@ -16,12 +16,13 @@
use std::collections::HashMap;
use std::{future::Future, sync::Arc};
use std::future::Future;
use futures::FutureExt;
use polkadot_node_network_protocol::jaeger;
use polkadot_node_primitives::{BlockData, ErasureChunk, PoV};
use polkadot_node_subsystem_test_helpers::mock::new_leaf;
use polkadot_node_subsystem_util::runtime::RuntimeInfo;
use polkadot_primitives::{
BlockNumber, CoreState, ExecutorParams, GroupIndex, Hash, Id as ParaId, ScheduledCore,
@@ -34,7 +35,7 @@ use polkadot_node_subsystem::{
AllMessages, AvailabilityDistributionMessage, AvailabilityStoreMessage, ChainApiMessage,
NetworkBridgeTxMessage, RuntimeApiMessage, RuntimeApiRequest,
},
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus, SpawnGlue,
ActiveLeavesUpdate, SpawnGlue,
};
use polkadot_node_subsystem_test_helpers::{
make_subsystem_context, mock::make_ferdie_keystore, TestSubsystemContext,
@@ -205,12 +206,7 @@ fn check_ancestry_lookup_in_same_session() {
let spans: HashMap<Hash, jaeger::PerLeafSpan> = HashMap::new();
let block_number = 1;
let update = ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: chain[block_number],
number: block_number as u32,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
activated: Some(new_leaf(chain[block_number], block_number as u32)),
deactivated: Vec::new().into(),
};
@@ -225,12 +221,7 @@ fn check_ancestry_lookup_in_same_session() {
let block_number = 2;
let update = ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: chain[block_number],
number: block_number as u32,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
activated: Some(new_leaf(chain[block_number], block_number as u32)),
deactivated: Vec::new().into(),
};
@@ -252,12 +243,7 @@ fn check_ancestry_lookup_in_same_session() {
// part of ancestry.
let block_number = 2 + Requester::LEAF_ANCESTRY_LEN_WITHIN_SESSION;
let update = ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: test_state.relay_chain[block_number],
number: block_number as u32,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
activated: Some(new_leaf(chain[block_number], block_number as u32)),
deactivated: vec![chain[1], chain[2]].into(),
};
requester
@@ -292,12 +278,7 @@ fn check_ancestry_lookup_in_different_sessions() {
let spans: HashMap<Hash, jaeger::PerLeafSpan> = HashMap::new();
let block_number = 3;
let update = ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: chain[block_number],
number: block_number as u32,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
activated: Some(new_leaf(chain[block_number], block_number as u32)),
deactivated: Vec::new().into(),
};
@@ -310,12 +291,7 @@ fn check_ancestry_lookup_in_different_sessions() {
let block_number = 4;
let update = ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: chain[block_number],
number: block_number as u32,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
activated: Some(new_leaf(chain[block_number], block_number as u32)),
deactivated: vec![chain[1], chain[2], chain[3]].into(),
};
@@ -328,12 +304,7 @@ fn check_ancestry_lookup_in_different_sessions() {
let block_number = 5;
let update = ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: chain[block_number],
number: block_number as u32,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
activated: Some(new_leaf(chain[block_number], block_number as u32)),
deactivated: vec![chain[4]].into(),
};
@@ -16,7 +16,6 @@
use std::{
collections::{HashMap, HashSet},
sync::Arc,
time::Duration,
};
@@ -34,9 +33,8 @@ use sc_network::{config as netconfig, config::RequestResponseConfig, IfDisconnec
use sp_core::{testing::TaskExecutor, traits::SpawnNamed};
use sp_keystore::KeystorePtr;
use polkadot_node_network_protocol::{
jaeger,
request_response::{v1, IncomingRequest, OutgoingRequest, Requests},
use polkadot_node_network_protocol::request_response::{
v1, IncomingRequest, OutgoingRequest, Requests,
};
use polkadot_node_primitives::ErasureChunk;
use polkadot_node_subsystem::{
@@ -44,14 +42,14 @@ use polkadot_node_subsystem::{
AllMessages, AvailabilityDistributionMessage, AvailabilityStoreMessage, ChainApiMessage,
NetworkBridgeTxMessage, RuntimeApiMessage, RuntimeApiRequest,
},
ActivatedLeaf, ActiveLeavesUpdate, FromOrchestra, LeafStatus, OverseerSignal,
ActiveLeavesUpdate, FromOrchestra, OverseerSignal,
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_primitives::{
CandidateHash, CoreState, ExecutorParams, GroupIndex, Hash, Id as ParaId, ScheduledCore,
SessionInfo, ValidatorIndex,
};
use test_helpers::mock::make_ferdie_keystore;
use test_helpers::mock::{make_ferdie_keystore, new_leaf};
use super::mock::{make_session_info, OccupiedCoreBuilder};
use crate::LOG_TARGET;
@@ -175,12 +173,7 @@ impl TestState {
.iter()
.zip(advanced)
.map(|(old, new)| ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: *new,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
activated: Some(new_leaf(*new, 1)),
deactivated: vec![*old].into(),
})
.collect::<Vec<_>>()
@@ -29,12 +29,10 @@ use sc_network::config::RequestResponseConfig;
use polkadot_erasure_coding::{branches, obtain_chunks_v1 as obtain_chunks};
use polkadot_node_primitives::{BlockData, PoV, Proof};
use polkadot_node_subsystem::{
jaeger,
messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest},
ActivatedLeaf, LeafStatus,
use polkadot_node_subsystem::messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest};
use polkadot_node_subsystem_test_helpers::{
make_subsystem_context, mock::new_leaf, TestSubsystemContextHandle,
};
use polkadot_node_subsystem_test_helpers::{make_subsystem_context, TestSubsystemContextHandle};
use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_primitives::{
AuthorityDiscoveryId, Hash, HeadData, IndexedVec, PersistedValidationData, ValidatorId,
@@ -561,12 +559,10 @@ fn availability_is_recovered_from_chunks_if_no_group_provided() {
test_harness_fast_path(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -647,12 +643,10 @@ fn availability_is_recovered_from_chunks_even_if_backing_group_supplied_if_chunk
test_harness_chunks_only(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -733,12 +727,10 @@ fn bad_merkle_path_leads_to_recovery_error() {
test_harness_fast_path(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -791,12 +783,10 @@ fn wrong_chunk_index_leads_to_recovery_error() {
test_harness_fast_path(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -865,12 +855,10 @@ fn invalid_erasure_coding_leads_to_invalid_error() {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -914,12 +902,10 @@ fn fast_path_backing_group_recovers() {
test_harness_fast_path(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -964,12 +950,10 @@ fn recovers_from_only_chunks_if_pov_large() {
test_harness_chunks_if_pov_large(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -1068,12 +1052,10 @@ fn fast_path_backing_group_recovers_if_pov_small() {
test_harness_chunks_if_pov_large(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -1127,12 +1109,10 @@ fn no_answers_in_fast_path_causes_chunk_requests() {
test_harness_fast_path(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -1189,12 +1169,10 @@ fn task_canceled_when_receivers_dropped() {
test_harness_chunks_only(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -1231,12 +1209,10 @@ fn chunks_retry_until_all_nodes_respond() {
test_harness_chunks_only(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -1292,12 +1268,10 @@ fn not_returning_requests_wont_stall_retrieval() {
test_harness_chunks_only(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -1364,12 +1338,10 @@ fn all_not_returning_requests_still_recovers_on_return() {
test_harness_chunks_only(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -1441,12 +1413,10 @@ fn returns_early_if_we_have_the_data() {
test_harness_chunks_only(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -1478,12 +1448,10 @@ fn does_not_query_local_validator() {
test_harness_chunks_only(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
@@ -1537,12 +1505,10 @@ fn invalid_local_chunk_is_ignored() {
test_harness_chunks_only(|mut virtual_overseer, req_cfg| async move {
overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.current,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.current,
1,
))),
)
.await;
+13 -58
View File
@@ -16,8 +16,9 @@
use super::*;
use futures::{channel::oneshot, executor, stream::BoxStream};
use overseer::jaeger;
use polkadot_node_network_protocol::{self as net_protocol, OurView};
use polkadot_node_subsystem::{messages::NetworkBridgeEvent, ActivatedLeaf};
use polkadot_node_subsystem::messages::NetworkBridgeEvent;
use assert_matches::assert_matches;
use async_trait::async_trait;
@@ -36,15 +37,14 @@ use polkadot_node_network_protocol::{
view, ObservedRole, Versioned,
};
use polkadot_node_subsystem::{
jaeger,
messages::{
AllMessages, ApprovalDistributionMessage, BitfieldDistributionMessage,
GossipSupportMessage, StatementDistributionMessage,
},
ActiveLeavesUpdate, FromOrchestra, LeafStatus, OverseerSignal,
ActiveLeavesUpdate, FromOrchestra, OverseerSignal,
};
use polkadot_node_subsystem_test_helpers::{
SingleItemSink, SingleItemStream, TestSubsystemContextHandle,
mock::new_leaf, SingleItemSink, SingleItemStream, TestSubsystemContextHandle,
};
use polkadot_node_subsystem_util::metered;
use polkadot_primitives::{AuthorityDiscoveryId, CandidateHash, Hash};
@@ -427,12 +427,7 @@ fn send_our_view_upon_connection() {
let head = Hash::repeat_byte(1);
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: head,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(head, 1)),
)))
.await;
@@ -514,12 +509,7 @@ fn sends_view_updates_to_peers() {
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash_a, 1)),
)))
.await;
@@ -585,12 +575,7 @@ fn do_not_send_view_update_until_synced() {
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash_a, 1)),
)))
.await;
@@ -601,12 +586,7 @@ fn do_not_send_view_update_until_synced() {
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_b,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash_b, 1)),
)))
.await;
@@ -672,12 +652,7 @@ fn do_not_send_view_update_when_only_finalized_block_changed() {
// This should trigger the view update to our peers.
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash_a, 1)),
)))
.await;
@@ -895,12 +870,7 @@ fn peer_disconnect_from_just_one_peerset() {
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash_a, 1)),
)))
.await;
@@ -1132,12 +1102,7 @@ fn sent_views_include_finalized_number_update() {
.await;
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_b,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash_b, 1)),
)))
.await;
@@ -1211,12 +1176,7 @@ fn our_view_updates_decreasing_order_and_limited_to_max() {
// get the correct view.
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash,
number: i as _,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash, i as _)),
)))
.await;
}
@@ -1265,12 +1225,7 @@ fn network_protocol_versioning_view_update() {
let head = Hash::repeat_byte(1);
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: head,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(head, 1)),
)))
.await;
@@ -40,7 +40,7 @@ use polkadot_node_subsystem::{
errors::RuntimeApiError,
jaeger,
messages::{AllMessages, ReportPeerMessage, RuntimeApiMessage, RuntimeApiRequest},
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
ActiveLeavesUpdate,
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_util::{reputation::add_reputation, TimeoutExt};
@@ -49,6 +49,7 @@ use polkadot_primitives::{
ScheduledCore, SessionIndex, SessionInfo, ValidatorId, ValidatorIndex,
};
use polkadot_primitives_test_helpers::TestCandidateBuilder;
use test_helpers::mock::new_leaf;
mod prospective_parachains;
@@ -310,12 +311,10 @@ async fn setup_system(virtual_overseer: &mut VirtualOverseer, test_state: &TestS
overseer_signal(
virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: test_state.relay_parent,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
test_state.relay_parent,
1,
))),
)
.await;
@@ -19,7 +19,6 @@
use std::{
collections::HashSet,
sync::Arc,
task::Poll,
time::{Duration, Instant},
};
@@ -51,10 +50,11 @@ use polkadot_node_subsystem::{
AllMessages, DisputeCoordinatorMessage, DisputeDistributionMessage, ImportStatementsResult,
NetworkBridgeTxMessage, RuntimeApiMessage, RuntimeApiRequest,
},
ActivatedLeaf, ActiveLeavesUpdate, FromOrchestra, LeafStatus, OverseerSignal, Span,
ActiveLeavesUpdate, FromOrchestra, OverseerSignal,
};
use polkadot_node_subsystem_test_helpers::{
mock::make_ferdie_keystore, subsystem_test_harness, TestSubsystemContextHandle,
mock::{make_ferdie_keystore, new_leaf},
subsystem_test_harness, TestSubsystemContextHandle,
};
use polkadot_primitives::{
AuthorityDiscoveryId, CandidateHash, CandidateReceipt, ExecutorParams, Hash, SessionIndex,
@@ -735,12 +735,7 @@ async fn activate_leaf(
) {
handle
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: activate,
number: 10,
status: LeafStatus::Fresh,
span: Arc::new(Span::Disabled),
}),
activated: Some(new_leaf(activate, 10)),
deactivated: deactivate.into_iter().collect(),
})))
.await;
@@ -16,7 +16,7 @@
//! Unit tests for Gossip Support Subsystem.
use std::{collections::HashSet, sync::Arc, time::Duration};
use std::{collections::HashSet, time::Duration};
use assert_matches::assert_matches;
use async_trait::async_trait;
@@ -30,15 +30,11 @@ use sp_core::crypto::Pair as PairT;
use sp_keyring::Sr25519Keyring;
use polkadot_node_network_protocol::grid_topology::{SessionGridTopology, TopologyPeerInfo};
use polkadot_node_subsystem::{
jaeger,
messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest},
ActivatedLeaf, LeafStatus,
};
use polkadot_node_subsystem::messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_util::TimeoutExt as _;
use polkadot_primitives::{GroupIndex, IndexedVec};
use test_helpers::mock::make_ferdie_keystore;
use test_helpers::mock::{make_ferdie_keystore, new_leaf};
use super::*;
@@ -196,12 +192,7 @@ fn test_harness<T: Future<Output = VirtualOverseer>, AD: AuthorityDiscovery>(
const TIMEOUT: Duration = Duration::from_millis(100);
async fn overseer_signal_active_leaves(overseer: &mut VirtualOverseer, leaf: Hash) {
let leaf = ActivatedLeaf {
hash: leaf,
number: 0xdeadcafe,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let leaf = new_leaf(leaf, 0xdeadcafe);
overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(
leaf,
@@ -36,13 +36,12 @@ use polkadot_node_primitives::{
SignedFullStatementWithPVD, Statement, UncheckedSignedFullStatement,
};
use polkadot_node_subsystem::{
jaeger,
messages::{
network_bridge_event, AllMessages, ReportPeerMessage, RuntimeApiMessage, RuntimeApiRequest,
},
ActivatedLeaf, LeafStatus, RuntimeApiError,
RuntimeApiError,
};
use polkadot_node_subsystem_test_helpers::mock::make_ferdie_keystore;
use polkadot_node_subsystem_test_helpers::mock::{make_ferdie_keystore, new_leaf};
use polkadot_primitives::{
ExecutorParams, GroupIndex, Hash, HeadData, Id as ParaId, IndexedVec, SessionInfo,
ValidationCode,
@@ -787,12 +786,7 @@ fn receiving_from_one_sends_to_another_and_to_candidate_backing() {
// register our active heads.
handle
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash_a, 1)),
)))
.await;
@@ -1032,12 +1026,7 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
// register our active heads.
handle
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash_a, 1)),
)))
.await;
@@ -1567,12 +1556,7 @@ fn delay_reputation_changes() {
// register our active heads.
handle
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash_a, 1)),
)))
.await;
@@ -2052,12 +2036,7 @@ fn share_prioritizes_backing_group() {
// register our active heads.
handle
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash_a, 1)),
)))
.await;
@@ -2379,12 +2358,7 @@ fn peer_cant_flood_with_large_statements() {
// register our active heads.
handle
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: hash_a,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(hash_a, 1)),
)))
.await;
@@ -2609,12 +2583,7 @@ fn handle_multiple_seconded_statements() {
// register our active heads.
handle
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: relay_parent_hash,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
}),
ActiveLeavesUpdate::start_work(new_leaf(relay_parent_hash, 1)),
)))
.await;
@@ -30,7 +30,6 @@ use polkadot_node_subsystem::messages::{
RuntimeApiMessage, RuntimeApiRequest,
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_types::{jaeger, ActivatedLeaf, LeafStatus};
use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_primitives::vstaging::{
AssignmentPair, AsyncBackingParams, BlockNumber, CommittedCandidateReceipt, CoreState,
@@ -46,6 +45,7 @@ use assert_matches::assert_matches;
use futures::Future;
use parity_scale_codec::Encode;
use rand::{Rng, SeedableRng};
use test_helpers::mock::new_leaf;
use std::sync::Arc;
@@ -358,12 +358,7 @@ async fn activate_leaf(
test_state: &TestState,
is_new_session: bool,
) {
let activated = ActivatedLeaf {
hash: leaf.hash,
number: leaf.number,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = new_leaf(leaf.hash, leaf.number);
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(
+1 -1
View File
@@ -25,12 +25,12 @@ tikv-jemalloc-ctl = { version = "0.5.0", optional = true }
[dev-dependencies]
metered = { package = "prioritized-metered-channel", version = "0.2.0" }
sp-core = { path = "../../../substrate/primitives/core" }
futures = { version = "0.3.21", features = ["thread-pool"] }
femme = "2.2.1"
assert_matches = "1.4.0"
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../primitives/test-helpers" }
node-test-helpers = { package = "polkadot-node-subsystem-test-helpers", path = "../subsystem-test-helpers" }
[target.'cfg(target_os = "linux")'.dependencies]
tikv-jemalloc-ctl = "0.5.0"
+19 -6
View File
@@ -87,7 +87,7 @@ use polkadot_node_subsystem_types::messages::{
pub use polkadot_node_subsystem_types::{
errors::{SubsystemError, SubsystemResult},
jaeger, ActivatedLeaf, ActiveLeavesUpdate, LeafStatus, OverseerSignal,
RuntimeApiSubsystemClient,
RuntimeApiSubsystemClient, UnpinHandle,
};
pub mod metrics;
@@ -245,23 +245,35 @@ impl Handle {
/// `HeaderBackend::block_number_from_id()`.
#[derive(Debug, Clone)]
pub struct BlockInfo {
/// hash of the block.
/// Hash of the block.
pub hash: Hash,
/// hash of the parent block.
/// Hash of the parent block.
pub parent_hash: Hash,
/// block's number.
/// Block's number.
pub number: BlockNumber,
/// A handle to unpin the block on drop.
pub unpin_handle: UnpinHandle,
}
impl From<BlockImportNotification<Block>> for BlockInfo {
fn from(n: BlockImportNotification<Block>) -> Self {
BlockInfo { hash: n.hash, parent_hash: n.header.parent_hash, number: n.header.number }
let hash = n.hash;
let parent_hash = n.header.parent_hash;
let number = n.header.number;
let unpin_handle = n.into_unpin_handle();
BlockInfo { hash, parent_hash, number, unpin_handle }
}
}
impl From<FinalityNotification<Block>> for BlockInfo {
fn from(n: FinalityNotification<Block>) -> Self {
BlockInfo { hash: n.hash, parent_hash: n.header.parent_hash, number: n.header.number }
let hash = n.hash;
let parent_hash = n.header.parent_hash;
let number = n.header.number;
let unpin_handle = n.into_unpin_handle();
BlockInfo { hash, parent_hash, number, unpin_handle }
}
}
@@ -792,6 +804,7 @@ where
hash: block.hash,
number: block.number,
status,
unpin_handle: block.unpin_handle,
span,
}),
None => ActiveLeavesUpdate::default(),
+94 -69
View File
@@ -19,15 +19,14 @@ use futures::{executor, pending, pin_mut, poll, select, stream, FutureExt};
use std::{collections::HashMap, sync::atomic, task::Poll};
use ::test_helpers::{dummy_candidate_descriptor, dummy_candidate_receipt, dummy_hash};
use node_test_helpers::mock::{dummy_unpin_handle, new_leaf};
use polkadot_node_network_protocol::{PeerId, UnifiedReputationChange};
use polkadot_node_primitives::{
BlockData, CollationGenerationConfig, CollationResult, DisputeMessage, InvalidDisputeVote, PoV,
UncheckedDisputeMessage, ValidDisputeVote,
};
use polkadot_node_subsystem_types::{
jaeger,
messages::{NetworkBridgeEvent, ReportPeerMessage, RuntimeApiRequest},
ActivatedLeaf, LeafStatus,
use polkadot_node_subsystem_types::messages::{
NetworkBridgeEvent, ReportPeerMessage, RuntimeApiRequest,
};
use polkadot_primitives::{
CandidateHash, CandidateReceipt, CollatorPair, Id as ParaId, InvalidDisputeStatementKind,
@@ -99,7 +98,7 @@ where
if c < 10 {
let candidate_receipt = CandidateReceipt {
descriptor: dummy_candidate_descriptor(dummy_hash()),
commitments_hash: Hash::zero(),
commitments_hash: dummy_hash(),
};
let (tx, _) = oneshot::channel();
@@ -216,11 +215,20 @@ fn overseer_metrics_work() {
executor::block_on(async move {
let first_block_hash = [1; 32].into();
let second_block_hash = [2; 32].into();
let unpin_handle = dummy_unpin_handle(dummy_hash());
let first_block =
BlockInfo { hash: first_block_hash, parent_hash: [0; 32].into(), number: 1 };
let second_block =
BlockInfo { hash: second_block_hash, parent_hash: first_block_hash, number: 2 };
let first_block = BlockInfo {
hash: first_block_hash,
parent_hash: [0; 32].into(),
number: 1,
unpin_handle: unpin_handle.clone(),
};
let second_block = BlockInfo {
hash: second_block_hash,
parent_hash: first_block_hash,
number: 2,
unpin_handle: unpin_handle.clone(),
};
let registry = prometheus::Registry::new();
let (overseer, handle) =
@@ -368,11 +376,20 @@ fn overseer_start_stop_works() {
executor::block_on(async move {
let first_block_hash = [1; 32].into();
let second_block_hash = [2; 32].into();
let unpin_handle = dummy_unpin_handle(dummy_hash());
let first_block =
BlockInfo { hash: first_block_hash, parent_hash: [0; 32].into(), number: 1 };
let second_block =
BlockInfo { hash: second_block_hash, parent_hash: first_block_hash, number: 2 };
let first_block = BlockInfo {
hash: first_block_hash,
parent_hash: [0; 32].into(),
number: 1,
unpin_handle: unpin_handle.clone(),
};
let second_block = BlockInfo {
hash: second_block_hash,
parent_hash: first_block_hash,
number: 2,
unpin_handle: unpin_handle.clone(),
};
let (tx_5, mut rx_5) = metered::channel(64);
let (tx_6, mut rx_6) = metered::channel(64);
@@ -396,21 +413,11 @@ fn overseer_start_stop_works() {
let expected_heartbeats = vec![
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: first_block_hash,
number: 1,
span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh,
}),
activated: Some(new_leaf(first_block_hash, 1)),
deactivated: Default::default(),
}),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: second_block_hash,
number: 2,
span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh,
}),
activated: Some(new_leaf(second_block_hash, 2)),
deactivated: [first_block_hash].as_ref().into(),
}),
];
@@ -456,13 +463,26 @@ fn overseer_finalize_works() {
let first_block_hash = [1; 32].into();
let second_block_hash = [2; 32].into();
let third_block_hash = [3; 32].into();
let unpin_handle = dummy_unpin_handle(dummy_hash());
let first_block =
BlockInfo { hash: first_block_hash, parent_hash: [0; 32].into(), number: 1 };
let second_block =
BlockInfo { hash: second_block_hash, parent_hash: [42; 32].into(), number: 2 };
let third_block =
BlockInfo { hash: third_block_hash, parent_hash: second_block_hash, number: 3 };
let first_block = BlockInfo {
hash: first_block_hash,
parent_hash: [0; 32].into(),
number: 1,
unpin_handle: unpin_handle.clone(),
};
let second_block = BlockInfo {
hash: second_block_hash,
parent_hash: [42; 32].into(),
number: 2,
unpin_handle: unpin_handle.clone(),
};
let third_block = BlockInfo {
hash: third_block_hash,
parent_hash: second_block_hash,
number: 3,
unpin_handle: unpin_handle.clone(),
};
let (tx_5, mut rx_5) = metered::channel(64);
let (tx_6, mut rx_6) = metered::channel(64);
@@ -492,21 +512,11 @@ fn overseer_finalize_works() {
let expected_heartbeats = vec![
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: first_block_hash,
number: 1,
span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh,
}),
activated: Some(new_leaf(first_block_hash, 1)),
deactivated: Default::default(),
}),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
activated: Some(ActivatedLeaf {
hash: second_block_hash,
number: 2,
span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh,
}),
activated: Some(new_leaf(second_block_hash, 2)),
deactivated: Default::default(),
}),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
@@ -563,11 +573,20 @@ fn overseer_finalize_leaf_preserves_it() {
executor::block_on(async move {
let first_block_hash = [1; 32].into();
let second_block_hash = [2; 32].into();
let unpin_handle = dummy_unpin_handle(dummy_hash());
let first_block =
BlockInfo { hash: first_block_hash, parent_hash: [0; 32].into(), number: 1 };
let second_block =
BlockInfo { hash: second_block_hash, parent_hash: [42; 32].into(), number: 1 };
let first_block = BlockInfo {
hash: first_block_hash,
parent_hash: [0; 32].into(),
number: 1,
unpin_handle: unpin_handle.clone(),
};
let second_block = BlockInfo {
hash: second_block_hash,
parent_hash: [42; 32].into(),
number: 1,
unpin_handle: unpin_handle.clone(),
};
let (tx_5, mut rx_5) = metered::channel(64);
let (tx_6, mut rx_6) = metered::channel(64);
@@ -595,18 +614,14 @@ fn overseer_finalize_leaf_preserves_it() {
handle.block_finalized(first_block).await;
let expected_heartbeats = vec![
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: first_block_hash,
number: 1,
span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh,
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: second_block_hash,
number: 1,
span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh,
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
first_block_hash,
1,
))),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
second_block_hash,
2,
))),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate {
deactivated: [second_block_hash].as_ref().into(),
..Default::default()
@@ -657,11 +672,21 @@ fn do_not_send_empty_leaves_update_on_block_finalization() {
let spawner = sp_core::testing::TaskExecutor::new();
executor::block_on(async move {
let imported_block =
BlockInfo { hash: Hash::random(), parent_hash: Hash::random(), number: 1 };
let unpin_handle = dummy_unpin_handle(dummy_hash());
let finalized_block =
BlockInfo { hash: Hash::random(), parent_hash: Hash::random(), number: 1 };
let imported_block = BlockInfo {
hash: Hash::random(),
parent_hash: Hash::random(),
number: 1,
unpin_handle: unpin_handle.clone(),
};
let finalized_block = BlockInfo {
hash: Hash::random(),
parent_hash: Hash::random(),
number: 1,
unpin_handle: unpin_handle.clone(),
};
let (tx_5, mut rx_5) = metered::channel(64);
@@ -682,12 +707,10 @@ fn do_not_send_empty_leaves_update_on_block_finalization() {
handle.block_imported(imported_block.clone()).await;
let expected_heartbeats = vec![
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: imported_block.hash,
number: imported_block.number,
span: Arc::new(jaeger::Span::Disabled),
status: LeafStatus::Fresh,
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(
imported_block.hash,
imported_block.number,
))),
OverseerSignal::BlockFinalized(finalized_block.hash, 1),
];
@@ -952,11 +975,13 @@ fn overseer_all_subsystems_receive_signals_and_messages() {
pin_mut!(overseer_fut);
// send a signal to each subsystem
let unpin_handle = dummy_unpin_handle(dummy_hash());
handle
.block_imported(BlockInfo {
hash: Default::default(),
parent_hash: Default::default(),
number: Default::default(),
unpin_handle: unpin_handle.clone(),
})
.await;
@@ -14,11 +14,10 @@ parking_lot = "0.12.0"
polkadot-node-subsystem = { path = "../subsystem" }
polkadot-node-subsystem-util = { path = "../subsystem-util" }
polkadot-primitives = { path = "../../primitives" }
sc-client-api = { path = "../../../substrate/client/api" }
sc-utils = { path = "../../../substrate/client/utils" }
sp-core = { path = "../../../substrate/primitives/core" }
sp-keystore = { path = "../../../substrate/primitives/keystore" }
sc-keystore = { path = "../../../substrate/client/keystore" }
sp-keyring = { path = "../../../substrate/primitives/keyring" }
sp-application-crypto = { path = "../../../substrate/primitives/application-crypto" }
[dev-dependencies]
polkadot-overseer = { path = "../overseer" }
@@ -435,42 +435,6 @@ impl Future for Yield {
#[cfg(test)]
mod tests {
use super::*;
use futures::executor::block_on;
use polkadot_node_subsystem::messages::CollatorProtocolMessage;
use polkadot_overseer::{dummy::dummy_overseer_builder, Handle, HeadSupportsParachains};
use polkadot_primitives::Hash;
use sp_core::traits::SpawnNamed;
struct AlwaysSupportsParachains;
#[async_trait::async_trait]
impl HeadSupportsParachains for AlwaysSupportsParachains {
async fn head_supports_parachains(&self, _head: &Hash) -> bool {
true
}
}
#[test]
fn forward_subsystem_works() {
let spawner = sp_core::testing::TaskExecutor::new();
let (tx, rx) = mpsc::channel(2);
let (overseer, handle) =
dummy_overseer_builder(spawner.clone(), AlwaysSupportsParachains, None)
.unwrap()
.replace_collator_protocol(|_| ForwardSubsystem(tx))
.build()
.unwrap();
let mut handle = Handle::new(handle);
spawner.spawn("overseer", None, overseer.run().then(|_| async { () }).boxed());
block_on(handle.send_msg_anon(CollatorProtocolMessage::CollateOn(Default::default())));
assert!(matches!(
block_on(rx.into_future()).0.unwrap(),
CollatorProtocolMessage::CollateOn(_)
));
}
#[test]
fn macro_arbitrary_order() {
@@ -16,12 +16,15 @@
use std::sync::Arc;
use polkadot_node_subsystem::{jaeger, ActivatedLeaf, LeafStatus};
use sc_client_api::UnpinHandle;
use sc_keystore::LocalKeystore;
use sc_utils::mpsc::tracing_unbounded;
use sp_application_crypto::AppCrypto;
use sp_keyring::Sr25519Keyring;
use sp_keystore::{Keystore, KeystorePtr};
use polkadot_primitives::{AuthorityDiscoveryId, ValidatorId};
use polkadot_primitives::{AuthorityDiscoveryId, Block, BlockNumber, Hash, ValidatorId};
/// Get mock keystore with `Ferdie` key.
pub fn make_ferdie_keystore() -> KeystorePtr {
@@ -40,3 +43,20 @@ pub fn make_ferdie_keystore() -> KeystorePtr {
.expect("Insert key into keystore");
keystore
}
/// Create a meaningless unpin handle for a block.
pub fn dummy_unpin_handle(block: Hash) -> UnpinHandle<Block> {
let (dummy_sink, _) = tracing_unbounded("Expect Chaos", 69);
UnpinHandle::new(block, dummy_sink)
}
/// Create a new leaf with the given hash and number.
pub fn new_leaf(hash: Hash, number: BlockNumber) -> ActivatedLeaf {
ActivatedLeaf {
hash,
number,
status: LeafStatus::Fresh,
unpin_handle: dummy_unpin_handle(hash),
span: Arc::new(jaeger::Span::Disabled),
}
}
+1
View File
@@ -19,6 +19,7 @@ sc-network = { path = "../../../substrate/client/network" }
sp-api = { path = "../../../substrate/primitives/api" }
sp-consensus-babe = { path = "../../../substrate/primitives/consensus/babe" }
sp-authority-discovery = { path = "../../../substrate/primitives/authority-discovery" }
sc-client-api = { path = "../../../substrate/client/api" }
sc-transaction-pool-api = { path = "../../../substrate/client/transaction-pool/api" }
smallvec = "1.8.0"
substrate-prometheus-endpoint = { path = "../../../substrate/utils/prometheus" }
+13 -2
View File
@@ -22,10 +22,19 @@
#![warn(missing_docs)]
use smallvec::SmallVec;
use std::{fmt, sync::Arc};
pub use polkadot_primitives::{BlockNumber, Hash};
use smallvec::SmallVec;
pub use polkadot_primitives::{Block, BlockNumber, Hash};
/// Keeps the state of a specific block pinned in memory while the handle is alive.
///
/// The handle is reference counted and once the last is dropped, the
/// block is unpinned.
///
/// This is useful for runtime API calls to blocks that are
/// racing against finality, e.g. for slashing purposes.
pub type UnpinHandle = sc_client_api::UnpinHandle<Block>;
pub mod errors;
pub mod messages;
@@ -80,6 +89,8 @@ pub struct ActivatedLeaf {
pub number: BlockNumber,
/// The status of the leaf.
pub status: LeafStatus,
/// A handle to unpin the block on drop.
pub unpin_handle: UnpinHandle,
/// An associated [`jaeger::Span`].
///
/// NOTE: Each span should only be kept active as long as the leaf is considered active and
+2
View File
@@ -22,6 +22,7 @@ derive_more = "0.99.17"
schnellru = "0.2.1"
polkadot-node-subsystem = { path = "../subsystem" }
polkadot-node-subsystem-types = { path = "../subsystem-types" }
polkadot-node-jaeger = { path = "../jaeger" }
polkadot-node-metrics = { path = "../metrics" }
polkadot-node-network-protocol = { path = "../network/protocol" }
@@ -33,6 +34,7 @@ metered = { package = "prioritized-metered-channel", version = "0.2.0" }
sp-core = { path = "../../../substrate/primitives/core" }
sp-application-crypto = { path = "../../../substrate/primitives/application-crypto" }
sp-keystore = { path = "../../../substrate/primitives/keystore" }
sc-client-api = { path = "../../../substrate/client/api" }
kvdb = "0.13.0"
parity-db = { version = "0.4.8"}
@@ -28,6 +28,7 @@ use polkadot_node_subsystem::{
messages::{RuntimeApiMessage, RuntimeApiRequest},
overseer, SubsystemSender,
};
use polkadot_node_subsystem_types::UnpinHandle;
use polkadot_primitives::{
vstaging, CandidateEvent, CandidateHash, CoreState, EncodeAs, ExecutorParams, GroupIndex,
GroupRotationInfo, Hash, IndexedVec, OccupiedCore, ScrapedOnChainVotes, SessionIndex,
@@ -75,6 +76,10 @@ pub struct RuntimeInfo {
/// Look up cached sessions by `SessionIndex`.
session_info_cache: LruMap<SessionIndex, ExtendedSessionInfo>,
/// Unpin handle of *some* block in the session.
/// Only blocks pinned explicitly by `pin_block` are stored here.
pinned_blocks: LruMap<SessionIndex, UnpinHandle>,
/// Key store for determining whether we are a validator and what `ValidatorIndex` we have.
keystore: Option<KeystorePtr>,
}
@@ -120,6 +125,7 @@ impl RuntimeInfo {
Self {
session_index_cache: LruMap::new(ByLength::new(cfg.session_cache_lru_size.max(10))),
session_info_cache: LruMap::new(ByLength::new(cfg.session_cache_lru_size)),
pinned_blocks: LruMap::new(ByLength::new(cfg.session_cache_lru_size)),
keystore: cfg.keystore,
}
}
@@ -145,6 +151,17 @@ impl RuntimeInfo {
}
}
/// Pin a given block in the given session if none are pinned in that session.
/// Unpinning will happen automatically when LRU cache grows over the limit.
pub fn pin_block(&mut self, session_index: SessionIndex, unpin_handle: UnpinHandle) {
self.pinned_blocks.get_or_insert(session_index, || unpin_handle);
}
/// Get the hash of a pinned block for the given session index, if any.
pub fn get_block_in_session(&self, session_index: SessionIndex) -> Option<Hash> {
self.pinned_blocks.peek(&session_index).map(|h| h.hash())
}
/// Get `ExtendedSessionInfo` by relay parent hash.
pub async fn get_session_info<'a, Sender>(
&'a mut self,