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
@@ -29,3 +29,4 @@ sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master
sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" }
futures-timer = "3.0.2"
assert_matches = "1.4.0"
polkadot-primitives-test-helpers = { path = "../../../primitives/test-helpers" }
@@ -27,6 +27,9 @@ use polkadot_primitives::v1::{
GroupIndex, Hash, HeadData, Id as ParaId, OccupiedCore, PersistedValidationData, SessionInfo,
ValidatorIndex,
};
use polkadot_primitives_test_helpers::{
dummy_collator, dummy_collator_signature, dummy_hash, dummy_validation_code,
};
/// Create dummy session info with two validator groups.
pub fn make_session_info() -> SessionInfo {
@@ -114,7 +117,11 @@ impl TestCandidateBuilder {
pov_hash: self.pov_hash,
relay_parent: self.relay_parent,
erasure_root: self.erasure_root,
..Default::default()
collator: dummy_collator(),
persisted_validation_data_hash: dummy_hash(),
signature: dummy_collator_signature(),
para_head: dummy_hash(),
validation_code_hash: dummy_validation_code().hash(),
},
commitments: CandidateCommitments { head_data: self.head_data, ..Default::default() },
}
@@ -31,4 +31,5 @@ sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" }
polkadot-subsystem-testhelpers = { package = "polkadot-node-subsystem-test-helpers", path = "../../subsystem-test-helpers" }
polkadot-subsystem-test-helpers = { package = "polkadot-node-subsystem-test-helpers", path = "../../subsystem-test-helpers" }
polkadot-primitives-test-helpers = { path = "../../../primitives/test-helpers" }
@@ -31,14 +31,15 @@ use polkadot_erasure_coding::{branches, obtain_chunks_v1 as obtain_chunks};
use polkadot_node_primitives::{BlockData, PoV, Proof};
use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_primitives::v1::{AuthorityDiscoveryId, HeadData, PersistedValidationData};
use polkadot_primitives_test_helpers::{dummy_candidate_receipt, dummy_hash};
use polkadot_subsystem::{
jaeger,
messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest},
ActivatedLeaf, LeafStatus,
};
use polkadot_subsystem_testhelpers as test_helpers;
use polkadot_subsystem_test_helpers::{make_subsystem_context, TestSubsystemContextHandle};
type VirtualOverseer = test_helpers::TestSubsystemContextHandle<AvailabilityRecoveryMessage>;
type VirtualOverseer = TestSubsystemContextHandle<AvailabilityRecoveryMessage>;
fn test_harness_fast_path<T: Future<Output = (VirtualOverseer, RequestResponseConfig)>>(
test: impl FnOnce(VirtualOverseer, RequestResponseConfig) -> T,
@@ -50,7 +51,7 @@ fn test_harness_fast_path<T: Future<Output = (VirtualOverseer, RequestResponseCo
let pool = sp_core::testing::TaskExecutor::new();
let (context, virtual_overseer) = test_helpers::make_subsystem_context(pool.clone());
let (context, virtual_overseer) = make_subsystem_context(pool.clone());
let (collation_req_receiver, req_cfg) = IncomingRequest::get_config_receiver();
let subsystem =
@@ -84,7 +85,7 @@ fn test_harness_chunks_only<T: Future<Output = (VirtualOverseer, RequestResponse
let pool = sp_core::testing::TaskExecutor::new();
let (context, virtual_overseer) = test_helpers::make_subsystem_context(pool.clone());
let (context, virtual_overseer) = make_subsystem_context(pool.clone());
let (collation_req_receiver, req_cfg) = IncomingRequest::get_config_receiver();
let subsystem = AvailabilityRecoverySubsystem::with_chunks_only(
@@ -118,7 +119,7 @@ macro_rules! delay {
}
async fn overseer_signal(
overseer: &mut test_helpers::TestSubsystemContextHandle<AvailabilityRecoveryMessage>,
overseer: &mut TestSubsystemContextHandle<AvailabilityRecoveryMessage>,
signal: OverseerSignal,
) {
delay!(50);
@@ -130,7 +131,7 @@ async fn overseer_signal(
}
async fn overseer_send(
overseer: &mut test_helpers::TestSubsystemContextHandle<AvailabilityRecoveryMessage>,
overseer: &mut TestSubsystemContextHandle<AvailabilityRecoveryMessage>,
msg: AvailabilityRecoveryMessage,
) {
tracing::trace!(msg = ?msg, "sending message");
@@ -142,7 +143,7 @@ async fn overseer_send(
}
async fn overseer_recv(
overseer: &mut test_helpers::TestSubsystemContextHandle<AvailabilityRecoveryMessage>,
overseer: &mut TestSubsystemContextHandle<AvailabilityRecoveryMessage>,
) -> AllMessages {
tracing::trace!("waiting for message ...");
let msg = overseer.recv().timeout(TIMEOUT).await.expect("TIMEOUT is enough to recv.");
@@ -212,7 +213,13 @@ impl TestState {
discovery_keys: self.validator_authority_id.clone(),
// all validators in the same group.
validator_groups: vec![(0..self.validators.len()).map(|i| ValidatorIndex(i as _)).collect()],
..Default::default()
assignment_keys: vec![],
n_cores: 0,
zeroth_delay_tranche_width: 0,
relay_vrf_modulo_samples: 0,
n_delay_tranches: 0,
no_show_slots: 0,
needed_approvals: 0,
}))).unwrap();
}
);
@@ -416,7 +423,7 @@ impl Default for TestState {
let current = Hash::repeat_byte(1);
let mut candidate = CandidateReceipt::default();
let mut candidate = dummy_candidate_receipt(dummy_hash());
let session_index = 10;
@@ -508,7 +515,7 @@ fn availability_is_recovered_from_chunks_if_no_group_provided() {
let (tx, rx) = oneshot::channel();
// Test another candidate, send no chunks.
let mut new_candidate = CandidateReceipt::default();
let mut new_candidate = dummy_candidate_receipt(dummy_hash());
new_candidate.descriptor.relay_parent = test_state.candidate.descriptor.relay_parent;
@@ -594,7 +601,7 @@ fn availability_is_recovered_from_chunks_even_if_backing_group_supplied_if_chunk
let (tx, rx) = oneshot::channel();
// Test another candidate, send no chunks.
let mut new_candidate = CandidateReceipt::default();
let mut new_candidate = dummy_candidate_receipt(dummy_hash());
new_candidate.descriptor.relay_parent = test_state.candidate.descriptor.relay_parent;
+1
View File
@@ -24,3 +24,4 @@ polkadot-node-subsystem-test-helpers = { path = "../../subsystem-test-helpers" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master" }
futures-timer = "3"
polkadot-primitives-test-helpers = { path = "../../../primitives/test-helpers" }
+3 -2
View File
@@ -34,6 +34,7 @@ use polkadot_node_subsystem_test_helpers::{
};
use polkadot_node_subsystem_util::metered;
use polkadot_primitives::v1::AuthorityDiscoveryId;
use polkadot_primitives_test_helpers::dummy_collator_signature;
use polkadot_subsystem::{
jaeger,
messages::{
@@ -1158,8 +1159,8 @@ fn send_messages_to_peers() {
{
let collator_protocol_message = protocol_v1::CollatorProtocolMessage::Declare(
Sr25519Keyring::Alice.public().into(),
Default::default(),
Default::default(),
0_u32.into(),
dummy_collator_signature(),
);
let message =
@@ -33,3 +33,4 @@ sc-network = { git = "https://github.com/paritytech/substrate", branch = "master
parity-scale-codec = { version = "2.3.1", features = ["std"] }
polkadot-subsystem-testhelpers = { package = "polkadot-node-subsystem-test-helpers", path = "../../subsystem-test-helpers" }
polkadot-primitives-test-helpers = { path = "../../../primitives/test-helpers" }
@@ -33,9 +33,10 @@ use polkadot_node_network_protocol::{our_view, request_response::IncomingRequest
use polkadot_node_primitives::BlockData;
use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_primitives::v1::{
AuthorityDiscoveryId, CandidateDescriptor, CollatorPair, GroupRotationInfo, ScheduledCore,
SessionIndex, SessionInfo, ValidatorId, ValidatorIndex,
AuthorityDiscoveryId, CollatorPair, GroupRotationInfo, ScheduledCore, SessionIndex,
SessionInfo, ValidatorId, ValidatorIndex,
};
use polkadot_primitives_test_helpers::TestCandidateBuilder;
use polkadot_subsystem::{
jaeger,
messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest},
@@ -43,28 +44,6 @@ use polkadot_subsystem::{
};
use polkadot_subsystem_testhelpers as test_helpers;
#[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 TestState {
para_id: ParaId,
@@ -124,7 +103,13 @@ impl Default for TestState {
validators: validator_public,
discovery_keys,
validator_groups,
..Default::default()
assignment_keys: vec![],
n_cores: 0,
zeroth_delay_tranche_width: 0,
relay_vrf_modulo_samples: 0,
n_delay_tranches: 0,
no_show_slots: 0,
needed_approvals: 0,
},
group_rotation_info,
validator_peer_id,
@@ -30,8 +30,11 @@ use polkadot_node_network_protocol::{
use polkadot_node_primitives::BlockData;
use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_primitives::v1::{
CandidateDescriptor, CollatorPair, CoreState, GroupIndex, GroupRotationInfo, OccupiedCore,
ScheduledCore, ValidatorId, ValidatorIndex,
CollatorPair, CoreState, GroupIndex, GroupRotationInfo, OccupiedCore, ScheduledCore,
ValidatorId, ValidatorIndex,
};
use polkadot_primitives_test_helpers::{
dummy_candidate_descriptor, dummy_candidate_receipt_bad_sig, dummy_hash,
};
use polkadot_subsystem::messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest};
use polkadot_subsystem_testhelpers as test_helpers;
@@ -89,7 +92,7 @@ impl Default for TestState {
group_responsible: GroupIndex(0),
candidate_hash: Default::default(),
candidate_descriptor: {
let mut d = CandidateDescriptor::default();
let mut d = dummy_candidate_descriptor(dummy_hash());
d.para_id = chain_ids[1];
d
@@ -551,7 +554,8 @@ fn fetch_collations_works() {
);
let pov = PoV { block_data: BlockData(vec![]) };
let mut candidate_a = CandidateReceipt::default();
let mut candidate_a =
dummy_candidate_receipt_bad_sig(dummy_hash(), Some(Default::default()));
candidate_a.descriptor.para_id = test_state.chain_ids[0];
candidate_a.descriptor.relay_parent = test_state.relay_parent;
response_channel
@@ -643,7 +647,8 @@ fn fetch_collations_works() {
.await;
let pov = PoV { block_data: BlockData(vec![1]) };
let mut candidate_a = CandidateReceipt::default();
let mut candidate_a =
dummy_candidate_receipt_bad_sig(dummy_hash(), Some(Default::default()));
candidate_a.descriptor.para_id = test_state.chain_ids[0];
candidate_a.descriptor.relay_parent = second;
@@ -767,7 +772,8 @@ fn fetch_next_collation_on_invalid_collation() {
.await;
let pov = PoV { block_data: BlockData(vec![]) };
let mut candidate_a = CandidateReceipt::default();
let mut candidate_a =
dummy_candidate_receipt_bad_sig(dummy_hash(), Some(Default::default()));
candidate_a.descriptor.para_id = test_state.chain_ids[0];
candidate_a.descriptor.relay_parent = test_state.relay_parent;
response_channel
@@ -30,3 +30,4 @@ sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "maste
futures-timer = "3.0.2"
assert_matches = "1.4.0"
lazy_static = "1.4.0"
polkadot-primitives-test-helpers = { path = "../../../primitives/test-helpers" }
@@ -33,9 +33,10 @@ use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};
use polkadot_node_primitives::{DisputeMessage, SignedDisputeStatement};
use polkadot_primitives::v1::{
AuthorityDiscoveryId, CandidateDescriptor, CandidateHash, CandidateReceipt, Hash, SessionIndex,
SessionInfo, ValidatorId, ValidatorIndex,
AuthorityDiscoveryId, CandidateHash, CandidateReceipt, Hash, SessionIndex, SessionInfo,
ValidatorId, ValidatorIndex,
};
use polkadot_primitives_test_helpers::dummy_candidate_descriptor;
pub const MOCK_SESSION_INDEX: SessionIndex = 1;
pub const MOCK_NEXT_SESSION_INDEX: SessionIndex = 2;
@@ -77,7 +78,14 @@ pub static ref MOCK_SESSION_INFO: SessionInfo =
.iter()
.map(|k| MOCK_VALIDATORS_DISCOVERY_KEYS.get(&k).unwrap().clone())
.collect(),
..Default::default()
assignment_keys: vec![],
validator_groups: vec![],
n_cores: 0,
zeroth_delay_tranche_width: 0,
relay_vrf_modulo_samples: 0,
n_delay_tranches: 0,
no_show_slots: 0,
needed_approvals: 0,
};
/// `SessionInfo` for the second session. (No more validators, but two more authorities.
@@ -88,13 +96,21 @@ pub static ref MOCK_NEXT_SESSION_INFO: SessionInfo =
.iter()
.map(|k| MOCK_VALIDATORS_DISCOVERY_KEYS.get(&k).unwrap().clone())
.collect(),
..Default::default()
validators: vec![],
assignment_keys: vec![],
validator_groups: vec![],
n_cores: 0,
zeroth_delay_tranche_width: 0,
relay_vrf_modulo_samples: 0,
n_delay_tranches: 0,
no_show_slots: 0,
needed_approvals: 0,
};
}
pub fn make_candidate_receipt(relay_parent: Hash) -> CandidateReceipt {
CandidateReceipt {
descriptor: CandidateDescriptor { relay_parent, ..Default::default() },
descriptor: dummy_candidate_descriptor(relay_parent),
commitments_hash: Hash::random(),
}
}
@@ -32,3 +32,4 @@ sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "master" }
futures-timer = "3.0.2"
polkadot-primitives-test-helpers = { path = "../../../primitives/test-helpers" }
@@ -28,7 +28,8 @@ use polkadot_node_network_protocol::{
};
use polkadot_node_primitives::Statement;
use polkadot_node_subsystem_test_helpers::mock::make_ferdie_keystore;
use polkadot_primitives::v1::{CommittedCandidateReceipt, SessionInfo, ValidationCode};
use polkadot_primitives::v1::{SessionInfo, ValidationCode};
use polkadot_primitives_test_helpers::{dummy_committed_candidate_receipt, dummy_hash};
use polkadot_subsystem::{
jaeger,
messages::{RuntimeApiMessage, RuntimeApiRequest},
@@ -53,21 +54,21 @@ fn active_head_accepts_only_2_seconded_per_validator() {
let signing_context = SigningContext { parent_hash, session_index };
let candidate_a = {
let mut c = CommittedCandidateReceipt::default();
let mut c = dummy_committed_candidate_receipt(dummy_hash());
c.descriptor.relay_parent = parent_hash;
c.descriptor.para_id = 1.into();
c
};
let candidate_b = {
let mut c = CommittedCandidateReceipt::default();
let mut c = dummy_committed_candidate_receipt(dummy_hash());
c.descriptor.relay_parent = parent_hash;
c.descriptor.para_id = 2.into();
c
};
let candidate_c = {
let mut c = CommittedCandidateReceipt::default();
let mut c = dummy_committed_candidate_receipt(dummy_hash());
c.descriptor.relay_parent = parent_hash;
c.descriptor.para_id = 3.into();
c
@@ -369,7 +370,7 @@ fn peer_view_update_sends_messages() {
let hash_c = Hash::repeat_byte(3);
let candidate = {
let mut c = CommittedCandidateReceipt::default();
let mut c = dummy_committed_candidate_receipt(dummy_hash());
c.descriptor.relay_parent = hash_c;
c.descriptor.para_id = 1.into();
c
@@ -547,7 +548,7 @@ fn circulated_statement_goes_to_all_peers_with_view() {
let hash_c = Hash::repeat_byte(3);
let candidate = {
let mut c = CommittedCandidateReceipt::default();
let mut c = dummy_committed_candidate_receipt(dummy_hash());
c.descriptor.relay_parent = hash_b;
c.descriptor.para_id = 1.into();
c
@@ -677,7 +678,7 @@ fn receiving_from_one_sends_to_another_and_to_candidate_backing() {
let hash_a = Hash::repeat_byte(1);
let candidate = {
let mut c = CommittedCandidateReceipt::default();
let mut c = dummy_committed_candidate_receipt(dummy_hash());
c.descriptor.relay_parent = hash_a;
c.descriptor.para_id = 1.into();
c
@@ -864,7 +865,7 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
let hash_b = Hash::repeat_byte(2);
let candidate = {
let mut c = CommittedCandidateReceipt::default();
let mut c = dummy_committed_candidate_receipt(dummy_hash());
c.descriptor.relay_parent = hash_a;
c.descriptor.para_id = 1.into();
c.commitments.new_validation_code = Some(ValidationCode(vec![1, 2, 3]));
@@ -1345,7 +1346,7 @@ fn share_prioritizes_backing_group() {
let hash_a = Hash::repeat_byte(1);
let candidate = {
let mut c = CommittedCandidateReceipt::default();
let mut c = dummy_committed_candidate_receipt(dummy_hash());
c.descriptor.relay_parent = hash_a;
c.descriptor.para_id = 1.into();
c.commitments.new_validation_code = Some(ValidationCode(vec![1, 2, 3]));
@@ -1649,7 +1650,7 @@ fn peer_cant_flood_with_large_statements() {
let hash_a = Hash::repeat_byte(1);
let candidate = {
let mut c = CommittedCandidateReceipt::default();
let mut c = dummy_committed_candidate_receipt(dummy_hash());
c.descriptor.relay_parent = hash_a;
c.descriptor.para_id = 1.into();
c.commitments.new_validation_code = Some(ValidationCode(vec![1, 2, 3]));