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
@@ -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;