remove Default from CandidateDescriptor (#4484)

* remove Default from CandidateHash

* Apply suggestions from code review

Co-authored-by: Andronik Ordian <write@reusable.software>

* chore: fmt

* remove backed candidate default

* Partial migration away from CandidateReceipt::default

* Remove more CandidateReceipt defaults

* fmt

* Mostly remove CommittedCandidateReceipt default usage

* Remove CommittedCandidateReceipt

* Remove more Defaults from polakdot primitives v1 + fmt

* Remove more Default from polkadot primites v1

* WIP trying to get overseer example + tests to compile

* feat: add primitives test helpers

* reduce deps of helper

* update primitive helpers

* make candidate validation compile

* fixup cargo lock

* make av-store compile

* fixup disputes coordinator tests

* test: fixup backing

* test: fixup approval voting

* fixup bitfield signing

* test: fixup runtime-api

* test: fixup availability dist

* foxi[ pverseer test]

* remove some Defaults, remove bounds from `dummy`

All `fn dummy` in primitives need to be removed anyways.
This aids in the transition.

* it's a test helper, so always use std

* test: fixup parachains runtime tests

Excluding benches.

* fix keyring

* fix paras runtime properly, no more default

* Remove fn dummy() usage from approval voting

* Move TestCandidateBuilder out of av store to test helpers

* Make candidate validation tests pass

* Make most dispute coirdinator tests pass

* Make provisioner tests work

* Make availability recovery tests work with test helpers

* Update polkadot-collator-protocol tests

* Update statement distribution tests

* Update polkadot overseer examples and tests

* Derive default for validation code so we don't break unrelated things

* Make para runtime test pass (no bench)

* Some more work

* chore: cargo fmt

* cargo fix

* avoid some Default::default

* fixup dispute coordinator test

* remove unused crate deps

* remove Default::default wherever possible, replace by dummy_* for the most part

* chore: cargo fmt

* Remove some warnings

* Remove CommittedCandidateReceipt dummy

* Remove CandidateReceipt dummy

* Remove CandidateDescriptor dummy

* Remove commented out code

* Fix para runtime tests

* chore: nightly

* Some updates to the builder

* Dynamically adjust mock head data size

* Make dispute cooridinator tests work

* Fix test candidate_backing_reorders_votes work

* +nightly-2021-10-29 fmt

* Spelling and remove a default use in builder

* Various clean up

* More small updates

* fmt

* More small updates

* Doc comments for test helpers

* cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_parachains::paras_inherent --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_parachains_paras_inherent.rs

* cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=polkadot-dev --steps=50 --repeat=20 --pallet=runtime_parachains::paras_inherent --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/polkadot/src/weights/runtime_parachains_paras_inherent.rs

* Update lib.rs

* review comments

* fix warnings

* fix test by using correct candidate receipt relay parent

Co-authored-by: Andronik Ordian <write@reusable.software>
Co-authored-by: emostov <32168567+emostov@users.noreply.github.com>
Co-authored-by: Parity Bot <admin@parity.io>
Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
Bernhard Schuster
2021-12-10 13:12:07 +01:00
committed by GitHub
parent 916497e5db
commit 0f1a9fb1eb
68 changed files with 993 additions and 500 deletions
@@ -39,3 +39,4 @@ sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch =
polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
assert_matches = "1.4.0"
kvdb-memorydb = "0.10.0"
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
@@ -457,25 +457,24 @@ pub fn tranches_to_approve(
#[cfg(test)]
mod tests {
use super::*;
use bitvec::{bitvec, order::Lsb0 as BitOrderLsb0};
use crate::{approval_db, BTreeMap};
use ::test_helpers::{dummy_candidate_receipt, dummy_hash};
use bitvec::{bitvec, order::Lsb0 as BitOrderLsb0, vec::BitVec};
use polkadot_primitives::v1::GroupIndex;
use crate::approval_db;
#[test]
fn pending_is_not_approved() {
let candidate = approval_db::v1::CandidateEntry {
candidate: Default::default(),
candidate: dummy_candidate_receipt(dummy_hash()),
session: 0,
block_assignments: Default::default(),
approvals: Default::default(),
block_assignments: BTreeMap::default(),
approvals: BitVec::default(),
}
.into();
let approval_entry = approval_db::v1::ApprovalEntry {
tranches: Vec::new(),
assignments: Default::default(),
assignments: BitVec::default(),
our_assignment: None,
our_approval_sig: None,
backing_group: GroupIndex(0),
@@ -499,9 +498,9 @@ mod tests {
#[test]
fn exact_takes_only_assignments_up_to() {
let mut candidate: CandidateEntry = approval_db::v1::CandidateEntry {
candidate: Default::default(),
candidate: dummy_candidate_receipt(dummy_hash()),
session: 0,
block_assignments: Default::default(),
block_assignments: BTreeMap::default(),
approvals: bitvec![BitOrderLsb0, u8; 0; 10],
}
.into();
@@ -571,9 +570,9 @@ mod tests {
#[test]
fn one_honest_node_always_approves() {
let mut candidate: CandidateEntry = approval_db::v1::CandidateEntry {
candidate: Default::default(),
candidate: dummy_candidate_receipt(dummy_hash()),
session: 0,
block_assignments: Default::default(),
block_assignments: BTreeMap::default(),
approvals: bitvec![BitOrderLsb0, u8; 0; 10],
}
.into();
@@ -1031,9 +1030,9 @@ mod tests {
let needed_approvals = 3;
let mut candidate: CandidateEntry = approval_db::v1::CandidateEntry {
candidate: Default::default(),
candidate: dummy_candidate_receipt(dummy_hash()),
session: 0,
block_assignments: Default::default(),
block_assignments: BTreeMap::default(),
approvals: bitvec![BitOrderLsb0, u8; 0; 3],
}
.into();
@@ -25,6 +25,8 @@ use kvdb::KeyValueDB;
use polkadot_primitives::v1::Id as ParaId;
use std::{collections::HashMap, sync::Arc};
use ::test_helpers::{dummy_candidate_receipt, dummy_candidate_receipt_bad_sig, dummy_hash};
const DATA_COL: u32 = 0;
const NUM_COLUMNS: u32 = 1;
@@ -59,7 +61,7 @@ fn make_block_entry(
}
fn make_candidate(para_id: ParaId, relay_parent: Hash) -> CandidateReceipt {
let mut c = CandidateReceipt::default();
let mut c = dummy_candidate_receipt(dummy_hash());
c.descriptor.para_id = para_id;
c.descriptor.relay_parent = relay_parent;
@@ -73,7 +75,7 @@ fn read_write() {
let hash_a = Hash::repeat_byte(1);
let hash_b = Hash::repeat_byte(2);
let candidate_hash = CandidateReceipt::<Hash>::default().hash();
let candidate_hash = dummy_candidate_receipt_bad_sig(dummy_hash(), None).hash();
let range = StoredBlockRange(10, 20);
let at_height = vec![hash_a, hash_b];
@@ -82,7 +84,7 @@ fn read_write() {
make_block_entry(hash_a, Default::default(), 1, vec![(CoreIndex(0), candidate_hash)]);
let candidate_entry = CandidateEntry {
candidate: Default::default(),
candidate: dummy_candidate_receipt_bad_sig(dummy_hash(), None),
session: 5,
block_assignments: vec![(
hash_a,
@@ -264,7 +264,7 @@ pub(crate) fn compute_assignments(
match key {
None => {
tracing::trace!(target: LOG_TARGET, "No assignment key");
return Default::default()
return HashMap::new()
},
Some(k) => k,
}
@@ -320,7 +320,7 @@ fn compute_relay_vrf_modulo_assignments(
assignments: &mut HashMap<CoreIndex, OurAssignment>,
) {
for rvm_sample in 0..config.relay_vrf_modulo_samples {
let mut core = Default::default();
let mut core = CoreIndex::default();
let maybe_assignment = {
// Extra scope to ensure borrowing instead of moving core
@@ -575,6 +575,7 @@ pub(crate) async fn handle_new_head(
pub(crate) mod tests {
use super::*;
use crate::approval_db::v1::DbBackend;
use ::test_helpers::{dummy_candidate_receipt, dummy_hash};
use assert_matches::assert_matches;
use kvdb::KeyValueDB;
use merlin::Transcript;
@@ -715,7 +716,7 @@ pub(crate) mod tests {
let hash = header.hash();
let make_candidate = |para_id| {
let mut r = CandidateReceipt::default();
let mut r = dummy_candidate_receipt(dummy_hash());
r.descriptor.para_id = para_id;
r.descriptor.relay_parent = hash;
r
@@ -829,7 +830,7 @@ pub(crate) mod tests {
let hash = header.hash();
let make_candidate = |para_id| {
let mut r = CandidateReceipt::default();
let mut r = dummy_candidate_receipt(dummy_hash());
r.descriptor.para_id = para_id;
r.descriptor.relay_parent = hash;
r
@@ -931,7 +932,7 @@ pub(crate) mod tests {
let hash = header.hash();
let make_candidate = |para_id| {
let mut r = CandidateReceipt::default();
let mut r = dummy_candidate_receipt(dummy_hash());
r.descriptor.para_id = para_id;
r.descriptor.relay_parent = hash;
r
@@ -1021,7 +1022,7 @@ pub(crate) mod tests {
let hash = header.hash();
let make_candidate = |para_id| {
let mut r = CandidateReceipt::default();
let mut r = dummy_candidate_receipt(dummy_hash());
r.descriptor.para_id = para_id;
r.descriptor.relay_parent = hash;
r
@@ -1163,7 +1164,7 @@ pub(crate) mod tests {
let hash = header.hash();
let make_candidate = |para_id| {
let mut r = CandidateReceipt::default();
let mut r = dummy_candidate_receipt(dummy_hash());
r.descriptor.para_id = para_id;
r.descriptor.relay_parent = hash;
r
+15 -12
View File
@@ -51,6 +51,8 @@ use super::{
},
};
use ::test_helpers::{dummy_candidate_receipt, dummy_candidate_receipt_bad_sig};
const SLOT_DURATION_MILLIS: u64 = 5000;
#[derive(Clone)]
@@ -547,9 +549,8 @@ where
}
fn make_candidate(para_id: ParaId, hash: &Hash) -> CandidateReceipt {
let mut r = CandidateReceipt::default();
let mut r = dummy_candidate_receipt_bad_sig(hash.clone(), Some(Default::default()));
r.descriptor.para_id = para_id;
r.descriptor.relay_parent = hash.clone();
r
}
@@ -1132,7 +1133,7 @@ fn subsystem_rejects_approval_if_no_block_entry() {
let block_hash = Hash::repeat_byte(0x01);
let candidate_index = 0;
let validator = ValidatorIndex(0);
let candidate_hash = CandidateReceipt::<Hash>::default().hash();
let candidate_hash = dummy_candidate_receipt(block_hash).hash();
let session_index = 1;
let rx = check_and_import_approval(
@@ -1168,7 +1169,8 @@ fn subsystem_rejects_approval_before_assignment() {
let block_hash = Hash::repeat_byte(0x01);
let candidate_hash = {
let mut candidate_receipt = CandidateReceipt::<Hash>::default();
let mut candidate_receipt =
dummy_candidate_receipt_bad_sig(block_hash, Some(Default::default()));
candidate_receipt.descriptor.para_id = 0.into();
candidate_receipt.descriptor.relay_parent = block_hash;
candidate_receipt.hash()
@@ -1358,7 +1360,8 @@ fn subsystem_accepts_and_imports_approval_after_assignment() {
let block_hash = Hash::repeat_byte(0x01);
let candidate_hash = {
let mut candidate_receipt = CandidateReceipt::<Hash>::default();
let mut candidate_receipt =
dummy_candidate_receipt_bad_sig(block_hash, Some(Default::default()));
candidate_receipt.descriptor.para_id = 0.into();
candidate_receipt.descriptor.relay_parent = block_hash;
candidate_receipt.hash()
@@ -1423,7 +1426,8 @@ fn subsystem_second_approval_import_only_schedules_wakeups() {
let block_hash = Hash::repeat_byte(0x01);
let candidate_hash = {
let mut candidate_receipt = CandidateReceipt::<Hash>::default();
let mut candidate_receipt =
dummy_candidate_receipt_bad_sig(block_hash, Some(Default::default()));
candidate_receipt.descriptor.para_id = 0.into();
candidate_receipt.descriptor.relay_parent = block_hash;
candidate_receipt.hash()
@@ -1886,12 +1890,12 @@ fn subsystem_import_checked_approval_sets_one_block_bit_at_a_time() {
let block_hash = Hash::repeat_byte(0x01);
let candidate_receipt1 = {
let mut receipt = CandidateReceipt::<Hash>::default();
let mut receipt = dummy_candidate_receipt(block_hash);
receipt.descriptor.para_id = 1.into();
receipt
};
let candidate_receipt2 = {
let mut receipt = CandidateReceipt::<Hash>::default();
let mut receipt = dummy_candidate_receipt(block_hash);
receipt.descriptor.para_id = 2.into();
receipt
};
@@ -2032,9 +2036,8 @@ fn approved_ancestor_test(
.iter()
.enumerate()
.map(|(i, hash)| {
let mut candidate_receipt = CandidateReceipt::<Hash>::default();
let mut candidate_receipt = dummy_candidate_receipt(*hash);
candidate_receipt.descriptor.para_id = i.into();
candidate_receipt.descriptor.relay_parent = *hash;
candidate_receipt
})
.collect();
@@ -2183,7 +2186,7 @@ fn subsystem_process_wakeup_trigger_assignment_launch_approval() {
} = test_harness;
let block_hash = Hash::repeat_byte(0x01);
let candidate_receipt = CandidateReceipt::<Hash>::default();
let candidate_receipt = dummy_candidate_receipt(block_hash);
let candidate_hash = candidate_receipt.hash();
let slot = Slot::from(1);
let candidate_index = 0;
@@ -2317,7 +2320,7 @@ where
} = test_harness;
let block_hash = Hash::repeat_byte(0x01);
let candidate_receipt = CandidateReceipt::<Hash>::default();
let candidate_receipt = dummy_candidate_receipt(block_hash);
let candidate_hash = candidate_receipt.hash();
let slot = Slot::from(1);
let candidate_index = 0;
+1
View File
@@ -31,3 +31,4 @@ polkadot-node-subsystem-util = { path = "../../subsystem-util" }
polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
parking_lot = "0.11.1"
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
+3 -24
View File
@@ -21,13 +21,14 @@ use std::convert::TryFrom;
use assert_matches::assert_matches;
use futures::{channel::oneshot, executor, future, Future};
use ::test_helpers::TestCandidateBuilder;
use parking_lot::Mutex;
use polkadot_node_primitives::{AvailableData, BlockData, PoV, Proof};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_primitives::v1::{
CandidateDescriptor, CandidateHash, CandidateReceipt, CoreIndex, GroupIndex, HeadData, Header,
Id as ParaId, PersistedValidationData, ValidatorId,
CandidateHash, CandidateReceipt, CoreIndex, GroupIndex, HeadData, Header,
PersistedValidationData, ValidatorId,
};
use polkadot_subsystem::{
errors::RuntimeApiError,
@@ -47,28 +48,6 @@ const TEST_CONFIG: Config = Config { col_data: columns::DATA, col_meta: columns:
type VirtualOverseer = test_helpers::TestSubsystemContextHandle<AvailabilityStoreMessage>;
#[derive(Default)]
struct TestCandidateBuilder {
para_id: ParaId,
pov_hash: Hash,
relay_parent: Hash,
commitments_hash: Hash,
}
impl TestCandidateBuilder {
fn build(self) -> CandidateReceipt {
CandidateReceipt {
descriptor: CandidateDescriptor {
para_id: self.para_id,
pov_hash: self.pov_hash,
relay_parent: self.relay_parent,
..Default::default()
},
commitments_hash: self.commitments_hash,
}
}
}
#[derive(Clone)]
struct TestClock {
inner: Arc<Mutex<Duration>>,
+1
View File
@@ -26,3 +26,4 @@ sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master
futures = { version = "0.3.17", features = ["thread-pool"] }
assert_matches = "1.4.0"
polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
+23 -7
View File
@@ -15,12 +15,16 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use super::*;
use ::test_helpers::{
dummy_candidate_receipt_bad_sig, dummy_collator, dummy_collator_signature,
dummy_committed_candidate_receipt, dummy_hash, dummy_validation_code,
};
use assert_matches::assert_matches;
use futures::{future, Future};
use polkadot_node_primitives::{BlockData, InvalidCandidate};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_primitives::v1::{
GroupRotationInfo, HeadData, PersistedValidationData, ScheduledCore,
CollatorId, GroupRotationInfo, HeadData, PersistedValidationData, ScheduledCore,
};
use polkadot_subsystem::{
messages::{CollatorProtocolMessage, RuntimeApiMessage, RuntimeApiRequest},
@@ -118,9 +122,9 @@ impl Default for TestState {
let validation_data = PersistedValidationData {
parent_head: HeadData(vec![7, 8, 9]),
relay_parent_number: Default::default(),
relay_parent_number: 0_u32.into(),
max_pov_size: 1024,
relay_parent_storage_root: Default::default(),
relay_parent_storage_root: dummy_hash(),
};
Self {
@@ -189,9 +193,20 @@ impl TestCandidateBuilder {
pov_hash: self.pov_hash,
relay_parent: self.relay_parent,
erasure_root: self.erasure_root,
..Default::default()
collator: dummy_collator(),
signature: dummy_collator_signature(),
para_head: dummy_hash(),
validation_code_hash: dummy_validation_code().hash(),
persisted_validation_data_hash: dummy_hash(),
},
commitments: CandidateCommitments {
head_data: self.head_data,
upward_messages: vec![],
horizontal_messages: vec![],
new_validation_code: None,
processed_downward_messages: 0,
hrmp_watermark: 0_u32,
},
commitments: CandidateCommitments { head_data: self.head_data, ..Default::default() },
}
}
}
@@ -1445,7 +1460,8 @@ fn candidate_backing_reorders_votes() {
};
let fake_attestation = |idx: u32| {
let candidate: CommittedCandidateReceipt = Default::default();
let candidate =
dummy_candidate_receipt_bad_sig(Default::default(), Some(Default::default()));
let hash = candidate.hash();
let mut data = vec![0; 64];
data[0..32].copy_from_slice(hash.0.as_bytes());
@@ -1456,7 +1472,7 @@ fn candidate_backing_reorders_votes() {
};
let attested = TableAttestedCandidate {
candidate: Default::default(),
candidate: dummy_committed_candidate_receipt(dummy_hash()),
validity_votes: vec![
(ValidatorIndex(5), fake_attestation(5)),
(ValidatorIndex(3), fake_attestation(3)),
@@ -16,3 +16,4 @@ thiserror = "1.0.30"
[dev-dependencies]
polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
@@ -18,6 +18,7 @@ use super::*;
use futures::{executor::block_on, pin_mut};
use polkadot_node_subsystem::messages::AllMessages;
use polkadot_primitives::v1::{CandidateHash, OccupiedCore};
use test_helpers::dummy_candidate_descriptor;
fn occupied_core(para_id: u32, candidate_hash: CandidateHash) -> CoreState {
CoreState::Occupied(OccupiedCore {
@@ -28,7 +29,7 @@ fn occupied_core(para_id: u32, candidate_hash: CandidateHash) -> CoreState {
next_up_on_time_out: None,
availability: Default::default(),
candidate_hash,
candidate_descriptor: Default::default(),
candidate_descriptor: dummy_candidate_descriptor(Hash::zero()),
})
}
@@ -27,3 +27,4 @@ futures = { version = "0.3.17", features = ["thread-pool"] }
assert_matches = "1.4.0"
polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
@@ -15,6 +15,7 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use super::*;
use ::test_helpers::{dummy_hash, make_valid_candidate_descriptor};
use assert_matches::assert_matches;
use futures::executor;
use polkadot_node_core_pvf::PrepareError;
@@ -25,20 +26,6 @@ use polkadot_primitives::v1::{HeadData, UpwardMessage};
use sp_core::testing::TaskExecutor;
use sp_keyring::Sr25519Keyring;
fn collator_sign(descriptor: &mut CandidateDescriptor, collator: Sr25519Keyring) {
descriptor.collator = collator.public().into();
let payload = polkadot_primitives::v1::collator_signature_payload(
&descriptor.relay_parent,
&descriptor.para_id,
&descriptor.persisted_validation_data_hash,
&descriptor.pov_hash,
&descriptor.validation_code_hash,
);
descriptor.signature = collator.sign(&payload[..]).into();
assert!(descriptor.check_collator_signature().is_ok());
}
#[test]
fn correctly_checks_included_assumption() {
let validation_data: PersistedValidationData = Default::default();
@@ -48,10 +35,16 @@ fn correctly_checks_included_assumption() {
let relay_parent = [2; 32].into();
let para_id = 5.into();
let mut candidate = CandidateDescriptor::default();
candidate.relay_parent = relay_parent;
candidate.persisted_validation_data_hash = persisted_validation_data_hash;
candidate.para_id = para_id;
let descriptor = make_valid_candidate_descriptor(
para_id,
relay_parent,
persisted_validation_data_hash,
dummy_hash(),
dummy_hash(),
dummy_hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let pool = TaskExecutor::new();
let (mut ctx, mut ctx_handle) =
@@ -59,7 +52,7 @@ fn correctly_checks_included_assumption() {
let (check_fut, check_result) = check_assumption_validation_data(
ctx.sender(),
&candidate,
&descriptor,
OccupiedCoreAssumption::Included,
)
.remote_handle();
@@ -114,10 +107,16 @@ fn correctly_checks_timed_out_assumption() {
let relay_parent = [2; 32].into();
let para_id = 5.into();
let mut candidate = CandidateDescriptor::default();
candidate.relay_parent = relay_parent;
candidate.persisted_validation_data_hash = persisted_validation_data_hash;
candidate.para_id = para_id;
let descriptor = make_valid_candidate_descriptor(
para_id,
relay_parent,
persisted_validation_data_hash,
dummy_hash(),
dummy_hash(),
dummy_hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let pool = TaskExecutor::new();
let (mut ctx, mut ctx_handle) =
@@ -125,7 +124,7 @@ fn correctly_checks_timed_out_assumption() {
let (check_fut, check_result) = check_assumption_validation_data(
ctx.sender(),
&candidate,
&descriptor,
OccupiedCoreAssumption::TimedOut,
)
.remote_handle();
@@ -178,10 +177,16 @@ fn check_is_bad_request_if_no_validation_data() {
let relay_parent = [2; 32].into();
let para_id = 5.into();
let mut candidate = CandidateDescriptor::default();
candidate.relay_parent = relay_parent;
candidate.persisted_validation_data_hash = persisted_validation_data_hash;
candidate.para_id = para_id;
let descriptor = make_valid_candidate_descriptor(
para_id,
relay_parent,
persisted_validation_data_hash,
dummy_hash(),
dummy_hash(),
dummy_hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let pool = TaskExecutor::new();
let (mut ctx, mut ctx_handle) =
@@ -189,7 +194,7 @@ fn check_is_bad_request_if_no_validation_data() {
let (check_fut, check_result) = check_assumption_validation_data(
ctx.sender(),
&candidate,
&descriptor,
OccupiedCoreAssumption::Included,
)
.remote_handle();
@@ -226,10 +231,16 @@ fn check_is_bad_request_if_no_validation_code() {
let relay_parent = [2; 32].into();
let para_id = 5.into();
let mut candidate = CandidateDescriptor::default();
candidate.relay_parent = relay_parent;
candidate.persisted_validation_data_hash = persisted_validation_data_hash;
candidate.para_id = para_id;
let descriptor = make_valid_candidate_descriptor(
para_id,
relay_parent,
persisted_validation_data_hash,
dummy_hash(),
dummy_hash(),
dummy_hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let pool = TaskExecutor::new();
let (mut ctx, mut ctx_handle) =
@@ -237,7 +248,7 @@ fn check_is_bad_request_if_no_validation_code() {
let (check_fut, check_result) = check_assumption_validation_data(
ctx.sender(),
&candidate,
&descriptor,
OccupiedCoreAssumption::TimedOut,
)
.remote_handle();
@@ -286,10 +297,16 @@ fn check_does_not_match() {
let relay_parent = [2; 32].into();
let para_id = 5.into();
let mut candidate = CandidateDescriptor::default();
candidate.relay_parent = relay_parent;
candidate.persisted_validation_data_hash = [3; 32].into();
candidate.para_id = para_id;
let descriptor = make_valid_candidate_descriptor(
para_id,
relay_parent,
Hash::from([3; 32]),
dummy_hash(),
dummy_hash(),
dummy_hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let pool = TaskExecutor::new();
let (mut ctx, mut ctx_handle) =
@@ -297,7 +314,7 @@ fn check_does_not_match() {
let (check_fut, check_result) = check_assumption_validation_data(
ctx.sender(),
&candidate,
&descriptor,
OccupiedCoreAssumption::Included,
)
.remote_handle();
@@ -361,11 +378,16 @@ fn candidate_validation_ok_is_ok() {
let head_data = HeadData(vec![1, 1, 1]);
let validation_code = ValidationCode(vec![2; 16]);
let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov.hash();
descriptor.para_head = head_data.hash();
descriptor.validation_code_hash = validation_code.hash();
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
let descriptor = make_valid_candidate_descriptor(
1.into(),
dummy_hash(),
validation_data.hash(),
pov.hash(),
validation_code.hash(),
head_data.hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let check = perform_basic_checks(
&descriptor,
@@ -412,10 +434,16 @@ fn candidate_validation_bad_return_is_invalid() {
let pov = PoV { block_data: BlockData(vec![1; 32]) };
let validation_code = ValidationCode(vec![2; 16]);
let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov.hash();
descriptor.validation_code_hash = validation_code.hash();
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
let descriptor = make_valid_candidate_descriptor(
1.into(),
dummy_hash(),
validation_data.hash(),
pov.hash(),
validation_code.hash(),
dummy_hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let check = perform_basic_checks(
&descriptor,
@@ -448,10 +476,16 @@ fn candidate_validation_timeout_is_internal_error() {
let pov = PoV { block_data: BlockData(vec![1; 32]) };
let validation_code = ValidationCode(vec![2; 16]);
let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov.hash();
descriptor.validation_code_hash = validation_code.hash();
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
let descriptor = make_valid_candidate_descriptor(
1.into(),
dummy_hash(),
validation_data.hash(),
pov.hash(),
validation_code.hash(),
dummy_hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let check = perform_basic_checks(
&descriptor,
@@ -483,10 +517,16 @@ fn candidate_validation_code_mismatch_is_invalid() {
let pov = PoV { block_data: BlockData(vec![1; 32]) };
let validation_code = ValidationCode(vec![2; 16]);
let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov.hash();
descriptor.validation_code_hash = ValidationCode(vec![1; 16]).hash();
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
let descriptor = make_valid_candidate_descriptor(
1.into(),
dummy_hash(),
validation_data.hash(),
pov.hash(),
ValidationCode(vec![1; 16]).hash(),
dummy_hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let check = perform_basic_checks(
&descriptor,
@@ -523,11 +563,16 @@ fn compressed_code_works() {
.map(ValidationCode)
.unwrap();
let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov.hash();
descriptor.para_head = head_data.hash();
descriptor.validation_code_hash = validation_code.hash();
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
let descriptor = make_valid_candidate_descriptor(
1.into(),
dummy_hash(),
validation_data.hash(),
pov.hash(),
validation_code.hash(),
head_data.hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let validation_result = WasmValidationResult {
head_data,
@@ -563,11 +608,16 @@ fn code_decompression_failure_is_invalid() {
.map(ValidationCode)
.unwrap();
let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov.hash();
descriptor.para_head = head_data.hash();
descriptor.validation_code_hash = validation_code.hash();
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
let descriptor = make_valid_candidate_descriptor(
1.into(),
dummy_hash(),
validation_data.hash(),
pov.hash(),
validation_code.hash(),
head_data.hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let validation_result = WasmValidationResult {
head_data,
@@ -604,11 +654,16 @@ fn pov_decompression_failure_is_invalid() {
let validation_code = ValidationCode(vec![2; 16]);
let mut descriptor = CandidateDescriptor::default();
descriptor.pov_hash = pov.hash();
descriptor.para_head = head_data.hash();
descriptor.validation_code_hash = validation_code.hash();
collator_sign(&mut descriptor, Sr25519Keyring::Alice);
let descriptor = make_valid_candidate_descriptor(
1.into(),
dummy_hash(),
validation_data.hash(),
pov.hash(),
validation_code.hash(),
head_data.hash(),
dummy_hash(),
Sr25519Keyring::Alice,
);
let validation_result = WasmValidationResult {
head_data,
@@ -5,12 +5,10 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
bitvec = { version = "0.20.1", default-features = false, features = ["alloc"] }
futures = "0.3.17"
tracing = "0.1.29"
parity-scale-codec = "2"
kvdb = "0.10.0"
derive_more = "0.99.17"
thiserror = "1.0.30"
polkadot-primitives = { path = "../../../primitives" }
@@ -27,6 +25,7 @@ sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
assert_matches = "1.4.0"
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
[features]
# If not enabled, the dispute coordinator will do nothing.
@@ -252,6 +252,7 @@ pub(crate) fn note_current_session(
#[cfg(test)]
mod tests {
use super::*;
use ::test_helpers::{dummy_candidate_receipt, dummy_hash};
use polkadot_primitives::v1::{Hash, Id as ParaId};
fn make_db() -> DbBackend {
@@ -285,7 +286,7 @@ mod tests {
1,
CandidateHash(Hash::repeat_byte(1)),
CandidateVotes {
candidate_receipt: Default::default(),
candidate_receipt: dummy_candidate_receipt(dummy_hash()),
valid: Vec::new(),
invalid: Vec::new(),
},
@@ -295,7 +296,7 @@ mod tests {
CandidateHash(Hash::repeat_byte(1)),
CandidateVotes {
candidate_receipt: {
let mut receipt = CandidateReceipt::default();
let mut receipt = dummy_candidate_receipt(dummy_hash());
receipt.descriptor.para_id = 5.into();
receipt
@@ -362,7 +363,7 @@ mod tests {
1,
CandidateHash(Hash::repeat_byte(1)),
CandidateVotes {
candidate_receipt: Default::default(),
candidate_receipt: dummy_candidate_receipt(dummy_hash()),
valid: Vec::new(),
invalid: Vec::new(),
},
@@ -379,7 +380,7 @@ mod tests {
.candidate_receipt
.descriptor
.para_id,
ParaId::from(0),
ParaId::from(1),
);
let mut overlay_db = OverlayedBackend::new(&backend);
@@ -388,7 +389,7 @@ mod tests {
CandidateHash(Hash::repeat_byte(1)),
CandidateVotes {
candidate_receipt: {
let mut receipt = CandidateReceipt::default();
let mut receipt = dummy_candidate_receipt(dummy_hash());
receipt.descriptor.para_id = 5.into();
receipt
@@ -427,7 +428,7 @@ mod tests {
let very_recent = current_session - 1;
let blank_candidate_votes = || CandidateVotes {
candidate_receipt: Default::default(),
candidate_receipt: dummy_candidate_receipt(dummy_hash()),
valid: Vec::new(),
invalid: Vec::new(),
};
@@ -62,6 +62,7 @@ pub struct OrderingProvider {
/// we are already too late. The ordering mechanism here serves to prevent this from happening in
/// the first place.
#[derive(Copy, Clone)]
#[cfg_attr(test, derive(Debug))]
pub struct CandidateComparator {
/// Block number of the relay parent.
///
@@ -150,7 +151,7 @@ impl OrderingProvider {
None => {
tracing::warn!(
target: LOG_TARGET,
candidate_hash = ?candidate.hash(),
candidate_hash = ?candidate_hash,
"Candidate's relay_parent could not be found via chain API, but we saw candidate included?!"
);
return Ok(None)
@@ -22,6 +22,7 @@ use futures::FutureExt;
use parity_scale_codec::Encode;
use sp_core::testing::TaskExecutor;
use ::test_helpers::{dummy_collator, dummy_collator_signature, dummy_hash};
use polkadot_node_subsystem::{
jaeger,
messages::{
@@ -35,8 +36,8 @@ use polkadot_node_subsystem_test_helpers::{
};
use polkadot_node_subsystem_util::reexports::SubsystemContext;
use polkadot_primitives::v1::{
BlakeTwo256, BlockNumber, CandidateEvent, CandidateReceipt, CoreIndex, GroupIndex, Hash, HashT,
HeadData,
BlakeTwo256, BlockNumber, CandidateDescriptor, CandidateEvent, CandidateReceipt, CoreIndex,
GroupIndex, Hash, HashT, HeadData,
};
use super::OrderingProvider;
@@ -90,12 +91,14 @@ fn launch_virtual_overseer(ctx: &mut impl SubsystemContext, ctx_handle: VirtualO
}
async fn virtual_overseer(mut ctx_handle: VirtualOverseer) {
let ev = vec![CandidateEvent::CandidateIncluded(
CandidateReceipt::default(),
HeadData::default(),
CoreIndex::from(0),
GroupIndex::from(0),
)];
let create_ev = |relay_parent: Hash| {
vec![CandidateEvent::CandidateIncluded(
make_candidate_receipt(relay_parent),
HeadData::default(),
CoreIndex::from(0),
GroupIndex::from(0),
)]
};
assert_matches!(
ctx_handle.recv().await,
@@ -111,17 +114,17 @@ async fn virtual_overseer(mut ctx_handle: VirtualOverseer) {
assert_matches!(
ctx_handle.recv().await,
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
_,
relay_parent,
RuntimeApiRequest::CandidateEvents(
tx,
)
)) => {
tx.send(Ok(ev)).unwrap();
tx.send(Ok(create_ev(relay_parent))).unwrap();
}
);
assert_matches!(
ctx_handle.recv().await,
AllMessages::ChainApi(ChainApiMessage::BlockNumber(_, tx)) => {
AllMessages::ChainApi(ChainApiMessage::BlockNumber(_relay_parent, tx)) => {
tx.send(Ok(Some(1))).unwrap();
}
);
@@ -142,24 +145,39 @@ fn get_block_number_hash(n: BlockNumber) -> Hash {
BlakeTwo256::hash(&n.encode())
}
fn make_candidate_receipt(relay_parent: Hash) -> CandidateReceipt {
let zeros = dummy_hash();
let descriptor = CandidateDescriptor {
para_id: 0.into(),
relay_parent,
collator: dummy_collator(),
persisted_validation_data_hash: zeros,
pov_hash: zeros,
erasure_root: zeros,
signature: dummy_collator_signature(),
para_head: zeros,
validation_code_hash: zeros.into(),
};
let candidate = CandidateReceipt { descriptor, commitments_hash: zeros };
candidate
}
#[test]
fn ordering_provider_provides_ordering_when_initialized() {
let candidate = make_candidate_receipt(get_block_number_hash(2));
futures::executor::block_on(async {
let mut state = TestState::new().await;
let r = state
.ordering
.candidate_comparator(state.ctx.sender(), &CandidateReceipt::default())
.candidate_comparator(state.ctx.sender(), &candidate)
.await
.unwrap();
assert!(r.is_none());
assert_matches!(r, None);
// After next active leaves update we should have a comparator:
state.process_active_leaves_update().await;
let r = state
.ordering
.candidate_comparator(state.ctx.sender(), &CandidateReceipt::default())
.await
.unwrap();
assert!(r.is_some());
assert_eq!(r.unwrap().relay_parent_block_number, 1);
let r = state.ordering.candidate_comparator(state.ctx.sender(), &candidate).await;
assert_matches!(r, Ok(Some(r2)) => {
assert_eq!(r2.relay_parent_block_number, 1);
});
});
}
@@ -14,8 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
use ::test_helpers::{dummy_candidate_receipt, dummy_hash};
use assert_matches::assert_matches;
use polkadot_primitives::v1::{BlockNumber, CandidateReceipt, Hash};
use polkadot_primitives::v1::{BlockNumber, Hash};
use crate::real::ordering::CandidateComparator;
@@ -23,7 +24,7 @@ use super::{Error, ParticipationRequest, Queues};
/// Make a `ParticipationRequest` based on the given commitments hash.
fn make_participation_request(hash: Hash) -> ParticipationRequest {
let mut receipt = CandidateReceipt::default();
let mut receipt = dummy_candidate_receipt(dummy_hash());
// make it differ:
receipt.commitments_hash = hash;
ParticipationRequest::new(receipt, 1, 100)
@@ -22,6 +22,9 @@ use std::{sync::Arc, time::Duration};
use sp_core::testing::TaskExecutor;
use super::*;
use ::test_helpers::{
dummy_candidate_commitments, dummy_candidate_receipt_bad_sig, dummy_digest, dummy_hash,
};
use parity_scale_codec::Encode;
use polkadot_node_primitives::{AvailableData, BlockData, InvalidCandidate, PoV};
use polkadot_node_subsystem::{
@@ -35,7 +38,9 @@ use polkadot_node_subsystem::{
use polkadot_node_subsystem_test_helpers::{
make_subsystem_context, TestSubsystemContext, TestSubsystemContextHandle,
};
use polkadot_primitives::v1::{BlakeTwo256, CandidateCommitments, HashT, Header, ValidationCode};
use polkadot_primitives::v1::{
BlakeTwo256, CandidateCommitments, HashT, Header, PersistedValidationData, ValidationCode,
};
type VirtualOverseer = TestSubsystemContextHandle<DisputeCoordinatorMessage>;
@@ -62,7 +67,7 @@ async fn participate_with_commitments_hash(
commitments_hash: Hash,
) -> Result<()> {
let candidate_receipt = {
let mut receipt = CandidateReceipt::default();
let mut receipt = dummy_candidate_receipt_bad_sig(dummy_hash(), dummy_hash());
receipt.commitments_hash = commitments_hash;
receipt
};
@@ -82,9 +87,9 @@ async fn activate_leaf(
let block_header = Header {
parent_hash: BlakeTwo256::hash(&block_number.encode()),
number: block_number,
digest: Default::default(),
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: dummy_digest(),
state_root: dummy_hash(),
extrinsics_root: dummy_hash(),
};
let block_hash = block_header.hash();
@@ -113,7 +118,7 @@ pub async fn participation_full_happy_path(ctx_handle: &mut VirtualOverseer) {
AllMessages::CandidateValidation(
CandidateValidationMessage::ValidateFromExhaustive(_, _, _, _, timeout, tx)
) if timeout == APPROVAL_EXECUTION_TIMEOUT => {
tx.send(Ok(ValidationResult::Valid(Default::default(), Default::default()))).unwrap();
tx.send(Ok(ValidationResult::Valid(dummy_candidate_commitments(None), PersistedValidationData::default()))).unwrap();
},
"overseer did not receive candidate validation message",
);
@@ -135,8 +140,10 @@ pub async fn participation_missing_availability(ctx_handle: &mut VirtualOverseer
async fn recover_available_data(virtual_overseer: &mut VirtualOverseer) {
let pov_block = PoV { block_data: BlockData(Vec::new()) };
let available_data =
AvailableData { pov: Arc::new(pov_block), validation_data: Default::default() };
let available_data = AvailableData {
pov: Arc::new(pov_block),
validation_data: PersistedValidationData::default(),
};
assert_matches!(
virtual_overseer.recv().await,
@@ -456,7 +463,7 @@ fn cast_invalid_vote_if_validation_passes_but_commitments_dont_match() {
// this should lead to a commitments hash mismatch
commitments.processed_downward_messages = 42;
tx.send(Ok(ValidationResult::Valid(commitments, Default::default()))).unwrap();
tx.send(Ok(ValidationResult::Valid(commitments, PersistedValidationData::default()))).unwrap();
},
"overseer did not receive candidate validation message",
);
@@ -494,7 +501,7 @@ fn cast_valid_vote_if_validation_passes() {
AllMessages::CandidateValidation(
CandidateValidationMessage::ValidateFromExhaustive(_, _, _, _, timeout, tx)
) if timeout == APPROVAL_EXECUTION_TIMEOUT => {
tx.send(Ok(ValidationResult::Valid(Default::default(), Default::default()))).unwrap();
tx.send(Ok(ValidationResult::Valid(dummy_candidate_commitments(None), PersistedValidationData::default()))).unwrap();
},
"overseer did not receive candidate validation message",
);
@@ -44,6 +44,7 @@ use sp_core::testing::TaskExecutor;
use sp_keyring::Sr25519Keyring;
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
use ::test_helpers::{dummy_candidate_receipt_bad_sig, dummy_digest, dummy_hash};
use polkadot_node_subsystem::{
jaeger,
messages::{AllMessages, BlockDescription, RuntimeApiMessage, RuntimeApiRequest},
@@ -52,7 +53,8 @@ use polkadot_node_subsystem::{
use polkadot_node_subsystem_test_helpers::{make_subsystem_context, TestSubsystemContextHandle};
use polkadot_primitives::v1::{
BlakeTwo256, BlockNumber, CandidateCommitments, CandidateHash, CandidateReceipt, Hash, HashT,
Header, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidatorId, ValidatorIndex,
Header, MultiDisputeStatementSet, ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidatorId,
ValidatorIndex,
};
use crate::{
@@ -179,9 +181,9 @@ impl TestState {
let block_header = Header {
parent_hash,
number: block_number,
digest: Default::default(),
state_root: Default::default(),
extrinsics_root: Default::default(),
digest: dummy_digest(),
state_root: dummy_hash(),
extrinsics_root: dummy_hash(),
};
let block_hash = block_header.hash();
@@ -251,7 +253,11 @@ impl TestState {
RuntimeApiRequest::FetchOnChainVotes(tx),
)) => {
//add some `BackedCandidates` or resolved disputes here as needed
tx.send(Ok(Some(ScrapedOnChainVotes::default()))).unwrap();
tx.send(Ok(Some(ScrapedOnChainVotes {
session,
backing_validators_per_candidate: Vec::default(),
disputes: MultiDisputeStatementSet::default(),
}))).unwrap();
}
)
}
@@ -358,14 +364,14 @@ async fn participation_with_distribution(
}
fn make_valid_candidate_receipt() -> CandidateReceipt {
let mut candidate_receipt = CandidateReceipt::default();
let mut candidate_receipt = dummy_candidate_receipt_bad_sig(dummy_hash(), dummy_hash());
candidate_receipt.commitments_hash = CandidateCommitments::default().hash();
candidate_receipt
}
fn make_invalid_candidate_receipt() -> CandidateReceipt {
// Commitments hash will be 0, which is not correct:
CandidateReceipt::default()
dummy_candidate_receipt_bad_sig(Default::default(), Some(Default::default()))
}
#[test]
@@ -18,3 +18,4 @@ futures-timer = "3.0.2"
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
+29 -26
View File
@@ -1,4 +1,5 @@
use super::*;
use ::test_helpers::{dummy_candidate_descriptor, dummy_hash};
use bitvec::bitvec;
use polkadot_primitives::v1::{OccupiedCore, ScheduledCore};
@@ -10,7 +11,7 @@ pub fn occupied_core(para_id: u32) -> CoreState {
time_out_at: 200_u32,
next_up_on_time_out: None,
availability: bitvec![bitvec::order::Lsb0, u8; 0; 32],
candidate_descriptor: Default::default(),
candidate_descriptor: dummy_candidate_descriptor(dummy_hash()),
candidate_hash: Default::default(),
})
}
@@ -34,13 +35,13 @@ pub fn default_bitvec(n_cores: usize) -> CoreAvailability {
}
pub fn scheduled_core(id: u32) -> ScheduledCore {
ScheduledCore { para_id: id.into(), ..Default::default() }
ScheduledCore { para_id: id.into(), collator: None }
}
mod select_availability_bitfields {
use super::{super::*, default_bitvec, occupied_core};
use futures::executor::block_on;
use polkadot_primitives::v1::{SigningContext, ValidatorId, ValidatorIndex};
use polkadot_primitives::v1::{ScheduledCore, SigningContext, ValidatorId, ValidatorIndex};
use sp_application_crypto::AppKey;
use sp_keystore::{testing::KeyStore, CryptoStore, SyncCryptoStorePtr};
use std::sync::Arc;
@@ -109,8 +110,11 @@ mod select_availability_bitfields {
let mut bitvec2 = bitvec.clone();
bitvec2.set(2, true);
let cores =
vec![CoreState::Free, CoreState::Scheduled(Default::default()), occupied_core(2)];
let cores = vec![
CoreState::Free,
CoreState::Scheduled(ScheduledCore { para_id: Default::default(), collator: None }),
occupied_core(2),
];
let bitfields = vec![
block_on(signed_bitfield(&keystore, bitvec0, ValidatorIndex(0))),
@@ -189,6 +193,7 @@ mod select_availability_bitfields {
mod select_candidates {
use super::{super::*, build_occupied_core, default_bitvec, occupied_core, scheduled_core};
use ::test_helpers::{dummy_candidate_descriptor, dummy_hash};
use polkadot_node_subsystem::messages::{
AllMessages, RuntimeApiMessage,
RuntimeApiRequest::{
@@ -197,8 +202,7 @@ mod select_candidates {
};
use polkadot_node_subsystem_test_helpers::TestSubsystemSender;
use polkadot_primitives::v1::{
BlockNumber, CandidateCommitments, CandidateDescriptor, CommittedCandidateReceipt,
PersistedValidationData,
BlockNumber, CandidateCommitments, CommittedCandidateReceipt, PersistedValidationData,
};
const BLOCK_UNDER_PRODUCTION: BlockNumber = 128;
@@ -346,11 +350,10 @@ mod select_candidates {
let empty_hash = PersistedValidationData::<Hash, BlockNumber>::default().hash();
let mut descriptor_template = dummy_candidate_descriptor(dummy_hash());
descriptor_template.persisted_validation_data_hash = empty_hash;
let candidate_template = CandidateReceipt {
descriptor: CandidateDescriptor {
persisted_validation_data_hash: empty_hash,
..Default::default()
},
descriptor: descriptor_template,
commitments_hash: CandidateCommitments::default().hash(),
};
@@ -389,7 +392,7 @@ mod select_candidates {
.map(|c| BackedCandidate {
candidate: CommittedCandidateReceipt {
descriptor: c.descriptor.clone(),
..Default::default()
commitments: Default::default(),
},
validity_votes: Vec::new(),
validator_indices: default_bitvec(n_cores),
@@ -428,21 +431,21 @@ mod select_candidates {
let cores_with_code = [1, 4, 8];
let committed_receipts: Vec<_> = (0..mock_cores.len())
.map(|i| CommittedCandidateReceipt {
descriptor: CandidateDescriptor {
para_id: i.into(),
persisted_validation_data_hash: empty_hash,
..Default::default()
},
commitments: CandidateCommitments {
new_validation_code: if cores_with_code.contains(&i) {
Some(vec![].into())
} else {
None
.map(|i| {
let mut descriptor = dummy_candidate_descriptor(dummy_hash());
descriptor.para_id = i.into();
descriptor.persisted_validation_data_hash = empty_hash;
CommittedCandidateReceipt {
descriptor,
commitments: CandidateCommitments {
new_validation_code: if cores_with_code.contains(&i) {
Some(vec![].into())
} else {
None
},
..Default::default()
},
..Default::default()
},
..Default::default()
}
})
.collect();
@@ -24,3 +24,4 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
futures = { version = "0.3.17", features = ["thread-pool"] }
polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
polkadot-node-primitives = { path = "../../primitives" }
test-helpers = { package = "polkadot-primitives-test-helpers", path = "../../../primitives/test-helpers" }
+43 -24
View File
@@ -16,9 +16,10 @@
use super::*;
use ::test_helpers::{dummy_committed_candidate_receipt, dummy_validation_code};
use futures::channel::oneshot;
use polkadot_node_primitives::{BabeAllowedSlots, BabeEpoch, BabeEpochConfiguration};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_test_helpers::make_subsystem_context;
use polkadot_primitives::v1::{
AuthorityDiscoveryId, CandidateEvent, CommittedCandidateReceipt, CoreState, GroupRotationInfo,
Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, OccupiedCoreAssumption,
@@ -208,7 +209,7 @@ sp_api::mock_impl_runtime_apis! {
#[test]
fn requests_authorities() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let runtime_api = Arc::new(MockRuntimeApi::default());
let relay_parent = [1; 32].into();
let spawner = sp_core::testing::TaskExecutor::new();
@@ -234,7 +235,7 @@ fn requests_authorities() {
#[test]
fn requests_validators() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let runtime_api = Arc::new(MockRuntimeApi::default());
let relay_parent = [1; 32].into();
let spawner = sp_core::testing::TaskExecutor::new();
@@ -260,7 +261,7 @@ fn requests_validators() {
#[test]
fn requests_validator_groups() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let runtime_api = Arc::new(MockRuntimeApi::default());
let relay_parent = [1; 32].into();
let spawner = sp_core::testing::TaskExecutor::new();
@@ -286,7 +287,7 @@ fn requests_validator_groups() {
#[test]
fn requests_availability_cores() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let runtime_api = Arc::new(MockRuntimeApi::default());
let relay_parent = [1; 32].into();
let spawner = sp_core::testing::TaskExecutor::new();
@@ -312,7 +313,7 @@ fn requests_availability_cores() {
#[test]
fn requests_persisted_validation_data() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let relay_parent = [1; 32].into();
let para_a = 5.into();
let para_b = 6.into();
@@ -358,7 +359,7 @@ fn requests_persisted_validation_data() {
#[test]
fn requests_assumed_validation_data() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let relay_parent = [1; 32].into();
let para_a = 5.into();
let para_b = 6.into();
@@ -410,7 +411,7 @@ fn requests_assumed_validation_data() {
#[test]
fn requests_check_validation_outputs() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let mut runtime_api = MockRuntimeApi::default();
let relay_parent = [1; 32].into();
let para_a = 5.into();
@@ -457,7 +458,7 @@ fn requests_check_validation_outputs() {
#[test]
fn requests_session_index_for_child() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let runtime_api = Arc::new(MockRuntimeApi::default());
let relay_parent = [1; 32].into();
let spawner = sp_core::testing::TaskExecutor::new();
@@ -481,12 +482,26 @@ fn requests_session_index_for_child() {
futures::executor::block_on(future::join(subsystem_task, test_task));
}
fn dummy_session_info() -> SessionInfo {
SessionInfo {
validators: vec![],
discovery_keys: vec![],
assignment_keys: vec![],
validator_groups: vec![],
n_cores: 4u32,
zeroth_delay_tranche_width: 0u32,
relay_vrf_modulo_samples: 0u32,
n_delay_tranches: 2u32,
no_show_slots: 0u32,
needed_approvals: 1u32,
}
}
#[test]
fn requests_session_info() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let mut runtime_api = MockRuntimeApi::default();
let session_index = 1;
runtime_api.session_info.insert(session_index, Default::default());
runtime_api.session_info.insert(session_index, dummy_session_info());
let runtime_api = Arc::new(runtime_api);
let spawner = sp_core::testing::TaskExecutor::new();
@@ -506,7 +521,7 @@ fn requests_session_info() {
})
.await;
assert_eq!(rx.await.unwrap().unwrap(), Some(Default::default()));
assert_eq!(rx.await.unwrap().unwrap(), Some(dummy_session_info()));
ctx_handle.send(FromOverseer::Signal(OverseerSignal::Conclude)).await;
};
@@ -516,15 +531,16 @@ fn requests_session_info() {
#[test]
fn requests_validation_code() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let relay_parent = [1; 32].into();
let para_a = 5.into();
let para_b = 6.into();
let spawner = sp_core::testing::TaskExecutor::new();
let validation_code = dummy_validation_code();
let mut runtime_api = MockRuntimeApi::default();
runtime_api.validation_code.insert(para_a, Default::default());
runtime_api.validation_code.insert(para_a, validation_code.clone());
let runtime_api = Arc::new(runtime_api);
let subsystem = RuntimeApiSubsystem::new(runtime_api.clone(), Metrics(None), spawner);
@@ -541,7 +557,7 @@ fn requests_validation_code() {
})
.await;
assert_eq!(rx.await.unwrap().unwrap(), Some(Default::default()));
assert_eq!(rx.await.unwrap().unwrap(), Some(validation_code));
let (tx, rx) = oneshot::channel();
ctx_handle
@@ -563,14 +579,17 @@ fn requests_validation_code() {
#[test]
fn requests_candidate_pending_availability() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let relay_parent = [1; 32].into();
let para_a = 5.into();
let para_b = 6.into();
let spawner = sp_core::testing::TaskExecutor::new();
let candidate_receipt = dummy_committed_candidate_receipt(relay_parent);
let mut runtime_api = MockRuntimeApi::default();
runtime_api.candidate_pending_availability.insert(para_a, Default::default());
runtime_api
.candidate_pending_availability
.insert(para_a, candidate_receipt.clone());
let runtime_api = Arc::new(runtime_api);
let subsystem = RuntimeApiSubsystem::new(runtime_api.clone(), Metrics(None), spawner);
@@ -587,7 +606,7 @@ fn requests_candidate_pending_availability() {
})
.await;
assert_eq!(rx.await.unwrap().unwrap(), Some(Default::default()));
assert_eq!(rx.await.unwrap().unwrap(), Some(candidate_receipt));
let (tx, rx) = oneshot::channel();
@@ -610,7 +629,7 @@ fn requests_candidate_pending_availability() {
#[test]
fn requests_candidate_events() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let runtime_api = Arc::new(MockRuntimeApi::default());
let relay_parent = [1; 32].into();
let spawner = sp_core::testing::TaskExecutor::new();
@@ -636,7 +655,7 @@ fn requests_candidate_events() {
#[test]
fn requests_dmq_contents() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let relay_parent = [1; 32].into();
let para_a = 5.into();
@@ -684,7 +703,7 @@ fn requests_dmq_contents() {
#[test]
fn requests_inbound_hrmp_channels_contents() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let relay_parent = [1; 32].into();
let para_a = 99.into();
@@ -741,7 +760,7 @@ fn requests_inbound_hrmp_channels_contents() {
#[test]
fn requests_validation_code_by_hash() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let spawner = sp_core::testing::TaskExecutor::new();
let (runtime_api, validation_code) = {
@@ -784,7 +803,7 @@ fn requests_validation_code_by_hash() {
#[test]
fn multiple_requests_in_parallel_are_working() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let runtime_api = Arc::new(MockRuntimeApi::default());
let relay_parent = [1; 32].into();
let spawner = sp_core::testing::TaskExecutor::new();
@@ -826,7 +845,7 @@ fn multiple_requests_in_parallel_are_working() {
#[test]
fn request_babe_epoch() {
let (ctx, mut ctx_handle) = test_helpers::make_subsystem_context(TaskExecutor::new());
let (ctx, mut ctx_handle) = make_subsystem_context(TaskExecutor::new());
let mut runtime_api = MockRuntimeApi::default();
let epoch = BabeEpoch {
epoch_index: 100,