mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 20:31:13 +00:00
Request based availability distribution (#2423)
* WIP * availability distribution, still very wip. Work on the requesting side of things. * Some docs on what I intend to do. * Checkpoint of session cache implementation as I will likely replace it with something smarter. * More work, mostly on cache and getting things to type check. * Only derive MallocSizeOf and Debug for std. * availability-distribution: Cache feature complete. * Sketch out logic in `FetchTask` for actual fetching. - Compile fixes. - Cleanup. * Format cleanup. * More format fixes. * Almost feature complete `fetch_task`. Missing: - Check for cancel - Actual querying of peer ids. * Finish FetchTask so far. * Directly use AuthorityDiscoveryId in protocol and cache. * Resolve `AuthorityDiscoveryId` on sending requests. * Rework fetch_task - also make it impossible to check the wrong chunk index. - Export needed function in validator_discovery. * From<u32> implementation for `ValidatorIndex`. * Fixes and more integration work. * Make session cache proper lru cache. * Use proper lru cache. * Requester finished. * ProtocolState -> Requester Also make sure to not fetch our own chunk. * Cleanup + fixes. * Remove unused functions - FetchTask::is_finished - SessionCache::fetch_session_info * availability-distribution responding side. * Cleanup + Fixes. * More fixes. * More fixes. adder-collator is running! * Some docs. * Docs. * Fix reporting of bad guys. * Fix tests * Make all tests compile. * Fix test. * Cleanup + get rid of some warnings. * state -> requester * Mostly doc fixes. * Fix test suite. * Get rid of now redundant message types. * WIP * Rob's review remarks. * Fix test suite. * core.relay_parent -> leaf for session request. * Style fix. * Decrease request timeout. * Cleanup obsolete errors. * Metrics + don't fail on non fatal errors. * requester.rs -> requester/mod.rs * Panic on invalid BadValidator report. * Fix indentation. * Use typed default timeout constant. * Make channel size 0, as each sender gets one slot anyways. * Fix incorrect metrics initialization. * Fix build after merge. * More fixes. * Hopefully valid metrics names. * Better metrics names. * Some tests that already work. * Slightly better docs. * Some more tests. * Fix network bridge test.
This commit is contained in:
@@ -306,7 +306,7 @@ pub fn tranches_to_approve(
|
||||
assignments.iter()
|
||||
.map(|(v_index, tick)| (v_index, tick.saturating_sub(clock_drift) + no_show_duration))
|
||||
.filter(|&(v_index, no_show_at)| {
|
||||
let has_approved = approvals.get(*v_index as usize).map(|b| *b).unwrap_or(false);
|
||||
let has_approved = approvals.get(v_index.0 as usize).map(|b| *b).unwrap_or(false);
|
||||
|
||||
let is_no_show = !has_approved && no_show_at <= drifted_tick_now;
|
||||
|
||||
@@ -348,7 +348,7 @@ pub fn tranches_to_approve(
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use polkadot_primitives::v1::GroupIndex;
|
||||
use polkadot_primitives::v1::{GroupIndex, ValidatorIndex};
|
||||
use bitvec::bitvec;
|
||||
use bitvec::order::Lsb0 as BitOrderLsb0;
|
||||
|
||||
@@ -393,7 +393,7 @@ mod tests {
|
||||
}.into();
|
||||
|
||||
for i in 0..6 {
|
||||
candidate.mark_approval(i);
|
||||
candidate.mark_approval(ValidatorIndex(i));
|
||||
}
|
||||
|
||||
let approval_entry = approval_db::v1::ApprovalEntry {
|
||||
@@ -406,7 +406,7 @@ mod tests {
|
||||
|
||||
assert!(!check_approval(&candidate, &approval_entry, RequiredTranches::All));
|
||||
|
||||
candidate.mark_approval(6);
|
||||
candidate.mark_approval(ValidatorIndex(6));
|
||||
assert!(check_approval(&candidate, &approval_entry, RequiredTranches::All));
|
||||
}
|
||||
|
||||
@@ -420,22 +420,22 @@ mod tests {
|
||||
}.into();
|
||||
|
||||
for i in 0..6 {
|
||||
candidate.mark_approval(i);
|
||||
candidate.mark_approval(ValidatorIndex(i));
|
||||
}
|
||||
|
||||
let approval_entry = approval_db::v1::ApprovalEntry {
|
||||
tranches: vec![
|
||||
approval_db::v1::TrancheEntry {
|
||||
tranche: 0,
|
||||
assignments: (0..4).map(|i| (i, 0.into())).collect(),
|
||||
assignments: (0..4).map(|i| (ValidatorIndex(i), 0.into())).collect(),
|
||||
},
|
||||
approval_db::v1::TrancheEntry {
|
||||
tranche: 1,
|
||||
assignments: (4..6).map(|i| (i, 1.into())).collect(),
|
||||
assignments: (4..6).map(|i| (ValidatorIndex(i), 1.into())).collect(),
|
||||
},
|
||||
approval_db::v1::TrancheEntry {
|
||||
tranche: 2,
|
||||
assignments: (6..10).map(|i| (i, 0.into())).collect(),
|
||||
assignments: (6..10).map(|i| (ValidatorIndex(i), 0.into())).collect(),
|
||||
},
|
||||
],
|
||||
assignments: bitvec![BitOrderLsb0, u8; 1; 10],
|
||||
@@ -487,13 +487,13 @@ mod tests {
|
||||
approved: false,
|
||||
}.into();
|
||||
|
||||
approval_entry.import_assignment(0, 0, block_tick);
|
||||
approval_entry.import_assignment(0, 1, block_tick);
|
||||
approval_entry.import_assignment(0,ValidatorIndex(0), block_tick);
|
||||
approval_entry.import_assignment(0,ValidatorIndex(1), block_tick);
|
||||
|
||||
approval_entry.import_assignment(1, 2, block_tick + 1);
|
||||
approval_entry.import_assignment(1, 3, block_tick + 1);
|
||||
approval_entry.import_assignment(1,ValidatorIndex(2), block_tick + 1);
|
||||
approval_entry.import_assignment(1,ValidatorIndex(3), block_tick + 1);
|
||||
|
||||
approval_entry.import_assignment(2, 4, block_tick + 2);
|
||||
approval_entry.import_assignment(2,ValidatorIndex(4), block_tick + 2);
|
||||
|
||||
let approvals = bitvec![BitOrderLsb0, u8; 1; 5];
|
||||
|
||||
@@ -524,8 +524,8 @@ mod tests {
|
||||
approved: false,
|
||||
}.into();
|
||||
|
||||
approval_entry.import_assignment(0, 0, block_tick);
|
||||
approval_entry.import_assignment(1, 2, block_tick);
|
||||
approval_entry.import_assignment(0, ValidatorIndex(0), block_tick);
|
||||
approval_entry.import_assignment(1, ValidatorIndex(2), block_tick);
|
||||
|
||||
let approvals = bitvec![BitOrderLsb0, u8; 0; 10];
|
||||
|
||||
@@ -562,10 +562,10 @@ mod tests {
|
||||
approved: false,
|
||||
}.into();
|
||||
|
||||
approval_entry.import_assignment(0, 0, block_tick);
|
||||
approval_entry.import_assignment(0, 1, block_tick);
|
||||
approval_entry.import_assignment(0, ValidatorIndex(0), block_tick);
|
||||
approval_entry.import_assignment(0, ValidatorIndex(1), block_tick);
|
||||
|
||||
approval_entry.import_assignment(1, 2, block_tick);
|
||||
approval_entry.import_assignment(1, ValidatorIndex(2), block_tick);
|
||||
|
||||
let mut approvals = bitvec![BitOrderLsb0, u8; 0; 10];
|
||||
approvals.set(0, true);
|
||||
@@ -605,11 +605,11 @@ mod tests {
|
||||
approved: false,
|
||||
}.into();
|
||||
|
||||
approval_entry.import_assignment(0, 0, block_tick);
|
||||
approval_entry.import_assignment(0, 1, block_tick);
|
||||
approval_entry.import_assignment(0, ValidatorIndex(0), block_tick);
|
||||
approval_entry.import_assignment(0, ValidatorIndex(1), block_tick);
|
||||
|
||||
approval_entry.import_assignment(1, 2, block_tick);
|
||||
approval_entry.import_assignment(1, 3, block_tick);
|
||||
approval_entry.import_assignment(1, ValidatorIndex(2), block_tick);
|
||||
approval_entry.import_assignment(1, ValidatorIndex(3), block_tick);
|
||||
|
||||
let mut approvals = bitvec![BitOrderLsb0, u8; 0; n_validators];
|
||||
approvals.set(0, true);
|
||||
@@ -670,14 +670,14 @@ mod tests {
|
||||
approved: false,
|
||||
}.into();
|
||||
|
||||
approval_entry.import_assignment(0, 0, block_tick);
|
||||
approval_entry.import_assignment(0, 1, block_tick);
|
||||
approval_entry.import_assignment(0, ValidatorIndex(0), block_tick);
|
||||
approval_entry.import_assignment(0, ValidatorIndex(1), block_tick);
|
||||
|
||||
approval_entry.import_assignment(1, 2, block_tick + 1);
|
||||
approval_entry.import_assignment(1, 3, block_tick + 1);
|
||||
approval_entry.import_assignment(1, ValidatorIndex(2), block_tick + 1);
|
||||
approval_entry.import_assignment(1, ValidatorIndex(3), block_tick + 1);
|
||||
|
||||
approval_entry.import_assignment(2, 4, block_tick + no_show_duration + 2);
|
||||
approval_entry.import_assignment(2, 5, block_tick + no_show_duration + 2);
|
||||
approval_entry.import_assignment(2, ValidatorIndex(4), block_tick + no_show_duration + 2);
|
||||
approval_entry.import_assignment(2, ValidatorIndex(5), block_tick + no_show_duration + 2);
|
||||
|
||||
let mut approvals = bitvec![BitOrderLsb0, u8; 0; n_validators];
|
||||
approvals.set(0, true);
|
||||
@@ -757,14 +757,14 @@ mod tests {
|
||||
approved: false,
|
||||
}.into();
|
||||
|
||||
approval_entry.import_assignment(0, 0, block_tick);
|
||||
approval_entry.import_assignment(0, 1, block_tick);
|
||||
approval_entry.import_assignment(0, ValidatorIndex(0), block_tick);
|
||||
approval_entry.import_assignment(0, ValidatorIndex(1), block_tick);
|
||||
|
||||
approval_entry.import_assignment(1, 2, block_tick + 1);
|
||||
approval_entry.import_assignment(1, 3, block_tick + 1);
|
||||
approval_entry.import_assignment(1, ValidatorIndex(2), block_tick + 1);
|
||||
approval_entry.import_assignment(1, ValidatorIndex(3), block_tick + 1);
|
||||
|
||||
approval_entry.import_assignment(2, 4, block_tick + no_show_duration + 2);
|
||||
approval_entry.import_assignment(2, 5, block_tick + no_show_duration + 2);
|
||||
approval_entry.import_assignment(2, ValidatorIndex(4), block_tick + no_show_duration + 2);
|
||||
approval_entry.import_assignment(2, ValidatorIndex(5), block_tick + no_show_duration + 2);
|
||||
|
||||
let mut approvals = bitvec![BitOrderLsb0, u8; 0; n_validators];
|
||||
approvals.set(0, true);
|
||||
@@ -813,7 +813,7 @@ mod tests {
|
||||
},
|
||||
);
|
||||
|
||||
approval_entry.import_assignment(3, 6, block_tick);
|
||||
approval_entry.import_assignment(3, ValidatorIndex(6), block_tick);
|
||||
approvals.set(6, true);
|
||||
|
||||
let tranche_now = no_show_duration as DelayTranche + 3;
|
||||
|
||||
@@ -253,7 +253,7 @@ pub(crate) fn compute_assignments(
|
||||
let (index, assignments_key): (ValidatorIndex, AssignmentPair) = {
|
||||
let key = config.assignment_keys.iter().enumerate()
|
||||
.find_map(|(i, p)| match keystore.key_pair(p) {
|
||||
Ok(Some(pair)) => Some((i as ValidatorIndex, pair)),
|
||||
Ok(Some(pair)) => Some((ValidatorIndex(i as _), pair)),
|
||||
Ok(None) => None,
|
||||
Err(sc_keystore::Error::Unavailable) => None,
|
||||
Err(sc_keystore::Error::Io(e)) if e.kind() == std::io::ErrorKind::NotFound => None,
|
||||
@@ -422,7 +422,7 @@ pub(crate) fn check_assignment_cert(
|
||||
backing_group: GroupIndex,
|
||||
) -> Result<DelayTranche, InvalidAssignment> {
|
||||
let validator_public = config.assignment_keys
|
||||
.get(validator_index as usize)
|
||||
.get(validator_index.0 as usize)
|
||||
.ok_or(InvalidAssignment)?;
|
||||
|
||||
let public = schnorrkel::PublicKey::from_bytes(validator_public.as_slice())
|
||||
@@ -540,7 +540,7 @@ mod tests {
|
||||
(0..n_groups).map(|i| {
|
||||
(i * size .. (i + 1) *size)
|
||||
.chain(if i < big_groups { Some(scraps + i) } else { None })
|
||||
.map(|j| j as ValidatorIndex)
|
||||
.map(|j| ValidatorIndex(j as _))
|
||||
.collect::<Vec<_>>()
|
||||
}).collect()
|
||||
}
|
||||
@@ -570,7 +570,7 @@ mod tests {
|
||||
Sr25519Keyring::Bob,
|
||||
Sr25519Keyring::Charlie,
|
||||
]),
|
||||
validator_groups: vec![vec![0], vec![1, 2]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0)], vec![ValidatorIndex(1), ValidatorIndex(2)]],
|
||||
n_cores: 2,
|
||||
zeroth_delay_tranche_width: 10,
|
||||
relay_vrf_modulo_samples: 3,
|
||||
@@ -601,7 +601,7 @@ mod tests {
|
||||
Sr25519Keyring::Bob,
|
||||
Sr25519Keyring::Charlie,
|
||||
]),
|
||||
validator_groups: vec![vec![0], vec![1, 2]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0)], vec![ValidatorIndex(1), ValidatorIndex(2)]],
|
||||
n_cores: 2,
|
||||
zeroth_delay_tranche_width: 10,
|
||||
relay_vrf_modulo_samples: 3,
|
||||
@@ -693,7 +693,7 @@ mod tests {
|
||||
group: group_for_core(core.0 as _),
|
||||
cert: assignment.cert,
|
||||
own_group: GroupIndex(0),
|
||||
val_index: 0,
|
||||
val_index: ValidatorIndex(0),
|
||||
config: config.clone(),
|
||||
};
|
||||
|
||||
@@ -743,7 +743,7 @@ mod tests {
|
||||
#[test]
|
||||
fn check_rejects_nonexistent_key() {
|
||||
check_mutated_assignments(200, 100, 25, |m| {
|
||||
m.val_index += 200;
|
||||
m.val_index.0 += 200;
|
||||
Some(false)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -707,6 +707,7 @@ mod tests {
|
||||
use super::*;
|
||||
use polkadot_node_subsystem_test_helpers::make_subsystem_context;
|
||||
use polkadot_node_primitives::approval::{VRFOutput, VRFProof};
|
||||
use polkadot_primitives::v1::ValidatorIndex;
|
||||
use polkadot_subsystem::messages::AllMessages;
|
||||
use sp_core::testing::TaskExecutor;
|
||||
use sp_runtime::{Digest, DigestItem};
|
||||
@@ -1561,7 +1562,7 @@ mod tests {
|
||||
validators: vec![Sr25519Keyring::Alice.public().into(); 6],
|
||||
discovery_keys: Vec::new(),
|
||||
assignment_keys: Vec::new(),
|
||||
validator_groups: vec![vec![0; 5], vec![0; 2]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0); 5], vec![ValidatorIndex(0); 2]],
|
||||
n_cores: 6,
|
||||
needed_approvals: 2,
|
||||
zeroth_delay_tranche_width: irrelevant,
|
||||
|
||||
@@ -864,7 +864,7 @@ fn check_and_import_assignment(
|
||||
tracing::trace!(
|
||||
target: LOG_TARGET,
|
||||
"Imported assignment from validator {} on candidate {:?}",
|
||||
assignment.validator,
|
||||
assignment.validator.0,
|
||||
(assigned_candidate_hash, candidate_entry.candidate_receipt().descriptor.para_id),
|
||||
);
|
||||
|
||||
@@ -928,7 +928,7 @@ fn check_and_import_approval<T>(
|
||||
block_entry.session(),
|
||||
);
|
||||
|
||||
let pubkey = match session_info.validators.get(approval.validator as usize) {
|
||||
let pubkey = match session_info.validators.get(approval.validator.0 as usize) {
|
||||
Some(k) => k,
|
||||
None => respond_early!(ApprovalCheckResult::Bad)
|
||||
};
|
||||
@@ -1492,13 +1492,13 @@ async fn issue_approval(
|
||||
}
|
||||
};
|
||||
|
||||
let validator_pubkey = match session_info.validators.get(validator_index as usize) {
|
||||
let validator_pubkey = match session_info.validators.get(validator_index.0 as usize) {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
tracing::warn!(
|
||||
target: LOG_TARGET,
|
||||
"Validator index {} out of bounds in session {}",
|
||||
validator_index,
|
||||
validator_index.0,
|
||||
block_entry.session(),
|
||||
);
|
||||
|
||||
@@ -1517,7 +1517,7 @@ async fn issue_approval(
|
||||
tracing::warn!(
|
||||
target: LOG_TARGET,
|
||||
"Could not issue approval signature with validator index {} in session {}. Assignment key present but not validator key?",
|
||||
validator_index,
|
||||
validator_index.0,
|
||||
block_entry.session(),
|
||||
);
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ impl ApprovalEntry {
|
||||
|
||||
/// Whether a validator is already assigned.
|
||||
pub fn is_assigned(&self, validator_index: ValidatorIndex) -> bool {
|
||||
self.assignments.get(validator_index as usize).map(|b| *b).unwrap_or(false)
|
||||
self.assignments.get(validator_index.0 as usize).map(|b| *b).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Import an assignment. No-op if already assigned on the same tranche.
|
||||
@@ -143,7 +143,7 @@ impl ApprovalEntry {
|
||||
};
|
||||
|
||||
self.tranches[idx].assignments.push((validator_index, tick_now));
|
||||
self.assignments.set(validator_index as _, true);
|
||||
self.assignments.set(validator_index.0 as _, true);
|
||||
}
|
||||
|
||||
// Produce a bitvec indicating the assignments of all validators up to and
|
||||
@@ -153,7 +153,7 @@ impl ApprovalEntry {
|
||||
.take_while(|e| e.tranche <= tranche)
|
||||
.fold(bitvec::bitvec![BitOrderLsb0, u8; 0; self.assignments.len()], |mut a, e| {
|
||||
for &(v, _) in &e.assignments {
|
||||
a.set(v as _, true);
|
||||
a.set(v.0 as _, true);
|
||||
}
|
||||
|
||||
a
|
||||
@@ -235,8 +235,8 @@ impl CandidateEntry {
|
||||
|
||||
/// Note that a given validator has approved. Return the previous approval state.
|
||||
pub fn mark_approval(&mut self, validator: ValidatorIndex) -> bool {
|
||||
let prev = self.approvals.get(validator as usize).map(|b| *b).unwrap_or(false);
|
||||
self.approvals.set(validator as usize, true);
|
||||
let prev = self.approvals.get(validator.0 as usize).map(|b| *b).unwrap_or(false);
|
||||
self.approvals.set(validator.0 as usize, true);
|
||||
prev
|
||||
}
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ impl Default for StateConfig {
|
||||
slot: Slot::from(0),
|
||||
tick: 0,
|
||||
validators: vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob],
|
||||
validator_groups: vec![vec![0], vec![1]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0)], vec![ValidatorIndex(1)]],
|
||||
needed_approvals: 1,
|
||||
no_show_slots: 2,
|
||||
}
|
||||
@@ -364,7 +364,7 @@ fn rejects_bad_assignment() {
|
||||
let block_hash = Hash::repeat_byte(0x01);
|
||||
let assignment_good = IndirectAssignmentCert {
|
||||
block_hash,
|
||||
validator: 0,
|
||||
validator: ValidatorIndex(0),
|
||||
cert: garbage_assignment_cert(
|
||||
AssignmentCertKind::RelayVRFModulo {
|
||||
sample: 0,
|
||||
@@ -386,7 +386,7 @@ fn rejects_bad_assignment() {
|
||||
// unknown hash
|
||||
let assignment = IndirectAssignmentCert {
|
||||
block_hash: Hash::repeat_byte(0x02),
|
||||
validator: 0,
|
||||
validator: ValidatorIndex(0),
|
||||
cert: garbage_assignment_cert(
|
||||
AssignmentCertKind::RelayVRFModulo {
|
||||
sample: 0,
|
||||
@@ -423,7 +423,7 @@ fn rejects_assignment_in_future() {
|
||||
let candidate_index = 0;
|
||||
let assignment = IndirectAssignmentCert {
|
||||
block_hash,
|
||||
validator: 0,
|
||||
validator: ValidatorIndex(0),
|
||||
cert: garbage_assignment_cert(
|
||||
AssignmentCertKind::RelayVRFModulo {
|
||||
sample: 0,
|
||||
@@ -467,7 +467,7 @@ fn rejects_assignment_with_unknown_candidate() {
|
||||
let candidate_index = 1;
|
||||
let assignment = IndirectAssignmentCert {
|
||||
block_hash,
|
||||
validator: 0,
|
||||
validator: ValidatorIndex(0),
|
||||
cert: garbage_assignment_cert(
|
||||
AssignmentCertKind::RelayVRFModulo {
|
||||
sample: 0,
|
||||
@@ -493,7 +493,7 @@ fn assignment_import_updates_candidate_entry_and_schedules_wakeup() {
|
||||
let candidate_index = 0;
|
||||
let assignment = IndirectAssignmentCert {
|
||||
block_hash,
|
||||
validator: 0,
|
||||
validator: ValidatorIndex(0),
|
||||
cert: garbage_assignment_cert(
|
||||
AssignmentCertKind::RelayVRFModulo {
|
||||
sample: 0,
|
||||
@@ -534,7 +534,7 @@ fn assignment_import_updates_candidate_entry_and_schedules_wakeup() {
|
||||
actions.get(1).unwrap(),
|
||||
Action::WriteCandidateEntry(c, e) => {
|
||||
assert_eq!(c, &candidate_hash);
|
||||
assert!(e.approval_entry(&block_hash).unwrap().is_assigned(0));
|
||||
assert!(e.approval_entry(&block_hash).unwrap().is_assigned(ValidatorIndex(0)));
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -554,7 +554,7 @@ fn rejects_approval_before_assignment() {
|
||||
let vote = IndirectSignedApprovalVote {
|
||||
block_hash,
|
||||
candidate_index: 0,
|
||||
validator: 0,
|
||||
validator: ValidatorIndex(0),
|
||||
signature: sign_approval(Sr25519Keyring::Alice, candidate_hash, 1),
|
||||
};
|
||||
|
||||
@@ -583,7 +583,7 @@ fn rejects_approval_if_no_candidate_entry() {
|
||||
let vote = IndirectSignedApprovalVote {
|
||||
block_hash,
|
||||
candidate_index: 0,
|
||||
validator: 0,
|
||||
validator: ValidatorIndex(0),
|
||||
signature: sign_approval(Sr25519Keyring::Alice, candidate_hash, 1),
|
||||
};
|
||||
|
||||
@@ -603,7 +603,7 @@ fn rejects_approval_if_no_candidate_entry() {
|
||||
fn rejects_approval_if_no_block_entry() {
|
||||
let block_hash = Hash::repeat_byte(0x01);
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(0xCC));
|
||||
let validator_index = 0;
|
||||
let validator_index = ValidatorIndex(0);
|
||||
|
||||
let mut state = State {
|
||||
assignment_criteria: Box::new(MockAssignmentCriteria::check_only(|| {
|
||||
@@ -615,7 +615,7 @@ fn rejects_approval_if_no_block_entry() {
|
||||
let vote = IndirectSignedApprovalVote {
|
||||
block_hash,
|
||||
candidate_index: 0,
|
||||
validator: 0,
|
||||
validator: ValidatorIndex(0),
|
||||
signature: sign_approval(Sr25519Keyring::Alice, candidate_hash, 1),
|
||||
};
|
||||
|
||||
@@ -640,7 +640,7 @@ fn rejects_approval_if_no_block_entry() {
|
||||
fn accepts_and_imports_approval_after_assignment() {
|
||||
let block_hash = Hash::repeat_byte(0x01);
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(0xCC));
|
||||
let validator_index = 0;
|
||||
let validator_index = ValidatorIndex(0);
|
||||
|
||||
let candidate_index = 0;
|
||||
let mut state = State {
|
||||
@@ -649,7 +649,7 @@ fn accepts_and_imports_approval_after_assignment() {
|
||||
})),
|
||||
..some_state(StateConfig {
|
||||
validators: vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob, Sr25519Keyring::Charlie],
|
||||
validator_groups: vec![vec![0, 1], vec![2]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0), ValidatorIndex(1)], vec![ValidatorIndex(2)]],
|
||||
needed_approvals: 2,
|
||||
..Default::default()
|
||||
})
|
||||
@@ -680,7 +680,7 @@ fn accepts_and_imports_approval_after_assignment() {
|
||||
actions.get(0).unwrap(),
|
||||
Action::WriteCandidateEntry(c_hash, c_entry) => {
|
||||
assert_eq!(c_hash, &candidate_hash);
|
||||
assert!(c_entry.approvals().get(validator_index as usize).unwrap());
|
||||
assert!(c_entry.approvals().get(validator_index.0 as usize).unwrap());
|
||||
assert!(!c_entry.approval_entry(&block_hash).unwrap().is_approved());
|
||||
}
|
||||
);
|
||||
@@ -690,7 +690,7 @@ fn accepts_and_imports_approval_after_assignment() {
|
||||
fn second_approval_import_is_no_op() {
|
||||
let block_hash = Hash::repeat_byte(0x01);
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(0xCC));
|
||||
let validator_index = 0;
|
||||
let validator_index = ValidatorIndex(0);
|
||||
|
||||
let candidate_index = 0;
|
||||
let mut state = State {
|
||||
@@ -699,7 +699,7 @@ fn second_approval_import_is_no_op() {
|
||||
})),
|
||||
..some_state(StateConfig {
|
||||
validators: vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob, Sr25519Keyring::Charlie],
|
||||
validator_groups: vec![vec![0, 1], vec![2]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0), ValidatorIndex(1)], vec![ValidatorIndex(2)]],
|
||||
needed_approvals: 2,
|
||||
..Default::default()
|
||||
})
|
||||
@@ -734,8 +734,8 @@ fn second_approval_import_is_no_op() {
|
||||
fn check_and_apply_full_approval_sets_flag_and_bit() {
|
||||
let block_hash = Hash::repeat_byte(0x01);
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(0xCC));
|
||||
let validator_index_a = 0;
|
||||
let validator_index_b = 1;
|
||||
let validator_index_a = ValidatorIndex(0);
|
||||
let validator_index_b = ValidatorIndex(1);
|
||||
|
||||
let mut state = State {
|
||||
assignment_criteria: Box::new(MockAssignmentCriteria::check_only(|| {
|
||||
@@ -743,7 +743,7 @@ fn check_and_apply_full_approval_sets_flag_and_bit() {
|
||||
})),
|
||||
..some_state(StateConfig {
|
||||
validators: vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob, Sr25519Keyring::Charlie],
|
||||
validator_groups: vec![vec![0, 1], vec![2]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0), ValidatorIndex(1)], vec![ValidatorIndex(2)]],
|
||||
needed_approvals: 2,
|
||||
..Default::default()
|
||||
})
|
||||
@@ -795,8 +795,8 @@ fn check_and_apply_full_approval_sets_flag_and_bit() {
|
||||
fn check_and_apply_full_approval_does_not_load_cached_block_from_db() {
|
||||
let block_hash = Hash::repeat_byte(0x01);
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(0xCC));
|
||||
let validator_index_a = 0;
|
||||
let validator_index_b = 1;
|
||||
let validator_index_a = ValidatorIndex(0);
|
||||
let validator_index_b = ValidatorIndex(1);
|
||||
|
||||
let mut state = State {
|
||||
assignment_criteria: Box::new(MockAssignmentCriteria::check_only(|| {
|
||||
@@ -804,7 +804,7 @@ fn check_and_apply_full_approval_does_not_load_cached_block_from_db() {
|
||||
})),
|
||||
..some_state(StateConfig {
|
||||
validators: vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob, Sr25519Keyring::Charlie],
|
||||
validator_groups: vec![vec![0, 1], vec![2]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0), ValidatorIndex(1)], vec![ValidatorIndex(2)]],
|
||||
needed_approvals: 2,
|
||||
..Default::default()
|
||||
})
|
||||
@@ -867,7 +867,7 @@ fn assignment_triggered_by_all_with_less_than_supermajority() {
|
||||
AssignmentCertKind::RelayVRFModulo { sample: 0 }
|
||||
),
|
||||
tranche: 1,
|
||||
validator_index: 4,
|
||||
validator_index: ValidatorIndex(4),
|
||||
triggered: false,
|
||||
}),
|
||||
assignments: bitvec::bitvec![BitOrderLsb0, u8; 0; 4],
|
||||
@@ -886,15 +886,15 @@ fn assignment_triggered_by_all_with_less_than_supermajority() {
|
||||
candidate_entry
|
||||
.approval_entry_mut(&block_hash)
|
||||
.unwrap()
|
||||
.import_assignment(0, 0, 0);
|
||||
.import_assignment(0, ValidatorIndex(0), 0);
|
||||
|
||||
candidate_entry
|
||||
.approval_entry_mut(&block_hash)
|
||||
.unwrap()
|
||||
.import_assignment(0, 1, 0);
|
||||
.import_assignment(0, ValidatorIndex(1), 0);
|
||||
|
||||
candidate_entry.mark_approval(0);
|
||||
candidate_entry.mark_approval(1);
|
||||
candidate_entry.mark_approval(ValidatorIndex(0));
|
||||
candidate_entry.mark_approval(ValidatorIndex(1));
|
||||
|
||||
let tranche_now = 1;
|
||||
assert!(should_trigger_assignment(
|
||||
@@ -918,7 +918,7 @@ fn assignment_not_triggered_by_all_with_supermajority() {
|
||||
AssignmentCertKind::RelayVRFModulo { sample: 0 }
|
||||
),
|
||||
tranche: 1,
|
||||
validator_index: 4,
|
||||
validator_index: ValidatorIndex(4),
|
||||
triggered: false,
|
||||
}),
|
||||
assignments: bitvec::bitvec![BitOrderLsb0, u8; 0; 4],
|
||||
@@ -937,21 +937,21 @@ fn assignment_not_triggered_by_all_with_supermajority() {
|
||||
candidate_entry
|
||||
.approval_entry_mut(&block_hash)
|
||||
.unwrap()
|
||||
.import_assignment(0, 0, 0);
|
||||
.import_assignment(0, ValidatorIndex(0), 0);
|
||||
|
||||
candidate_entry
|
||||
.approval_entry_mut(&block_hash)
|
||||
.unwrap()
|
||||
.import_assignment(0, 1, 0);
|
||||
.import_assignment(0, ValidatorIndex(1), 0);
|
||||
|
||||
candidate_entry
|
||||
.approval_entry_mut(&block_hash)
|
||||
.unwrap()
|
||||
.import_assignment(0, 2, 0);
|
||||
.import_assignment(0, ValidatorIndex(2), 0);
|
||||
|
||||
candidate_entry.mark_approval(0);
|
||||
candidate_entry.mark_approval(1);
|
||||
candidate_entry.mark_approval(2);
|
||||
candidate_entry.mark_approval(ValidatorIndex(0));
|
||||
candidate_entry.mark_approval(ValidatorIndex(1));
|
||||
candidate_entry.mark_approval(ValidatorIndex(2));
|
||||
|
||||
let tranche_now = 1;
|
||||
assert!(!should_trigger_assignment(
|
||||
@@ -975,7 +975,7 @@ fn assignment_not_triggered_if_already_triggered() {
|
||||
AssignmentCertKind::RelayVRFModulo { sample: 0 }
|
||||
),
|
||||
tranche: 1,
|
||||
validator_index: 4,
|
||||
validator_index: ValidatorIndex(4),
|
||||
triggered: true,
|
||||
}),
|
||||
assignments: bitvec::bitvec![BitOrderLsb0, u8; 0; 4],
|
||||
@@ -1012,7 +1012,7 @@ fn assignment_not_triggered_by_exact() {
|
||||
AssignmentCertKind::RelayVRFModulo { sample: 0 }
|
||||
),
|
||||
tranche: 1,
|
||||
validator_index: 4,
|
||||
validator_index: ValidatorIndex(4),
|
||||
triggered: false,
|
||||
}),
|
||||
assignments: bitvec::bitvec![BitOrderLsb0, u8; 0; 4],
|
||||
@@ -1050,7 +1050,7 @@ fn assignment_not_triggered_more_than_maximum() {
|
||||
AssignmentCertKind::RelayVRFModulo { sample: 0 }
|
||||
),
|
||||
tranche: maximum_broadcast + 1,
|
||||
validator_index: 4,
|
||||
validator_index: ValidatorIndex(4),
|
||||
triggered: false,
|
||||
}),
|
||||
assignments: bitvec::bitvec![BitOrderLsb0, u8; 0; 4],
|
||||
@@ -1093,7 +1093,7 @@ fn assignment_triggered_if_at_maximum() {
|
||||
AssignmentCertKind::RelayVRFModulo { sample: 0 }
|
||||
),
|
||||
tranche: maximum_broadcast,
|
||||
validator_index: 4,
|
||||
validator_index: ValidatorIndex(4),
|
||||
triggered: false,
|
||||
}),
|
||||
assignments: bitvec::bitvec![BitOrderLsb0, u8; 0; 4],
|
||||
@@ -1136,7 +1136,7 @@ fn assignment_not_triggered_if_at_maximum_but_clock_is_before() {
|
||||
AssignmentCertKind::RelayVRFModulo { sample: 0 }
|
||||
),
|
||||
tranche: maximum_broadcast,
|
||||
validator_index: 4,
|
||||
validator_index: ValidatorIndex(4),
|
||||
triggered: false,
|
||||
}),
|
||||
assignments: bitvec::bitvec![BitOrderLsb0, u8; 0; 4],
|
||||
@@ -1179,7 +1179,7 @@ fn assignment_not_triggered_if_at_maximum_but_clock_is_before_with_drift() {
|
||||
AssignmentCertKind::RelayVRFModulo { sample: 0 }
|
||||
),
|
||||
tranche: maximum_broadcast,
|
||||
validator_index: 4,
|
||||
validator_index: ValidatorIndex(4),
|
||||
triggered: false,
|
||||
}),
|
||||
assignments: bitvec::bitvec![BitOrderLsb0, u8; 0; 4],
|
||||
@@ -1277,8 +1277,8 @@ fn block_not_approved_until_all_candidates_approved() {
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(0xCC));
|
||||
let candidate_hash_2 = CandidateHash(Hash::repeat_byte(0xDD));
|
||||
|
||||
let validator_index_a = 0;
|
||||
let validator_index_b = 1;
|
||||
let validator_index_a = ValidatorIndex(0);
|
||||
let validator_index_b = ValidatorIndex(1);
|
||||
|
||||
let mut state = State {
|
||||
assignment_criteria: Box::new(MockAssignmentCriteria::check_only(|| {
|
||||
@@ -1286,7 +1286,7 @@ fn block_not_approved_until_all_candidates_approved() {
|
||||
})),
|
||||
..some_state(StateConfig {
|
||||
validators: vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob, Sr25519Keyring::Charlie],
|
||||
validator_groups: vec![vec![0, 1], vec![2]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0), ValidatorIndex(1)], vec![ValidatorIndex(2)]],
|
||||
needed_approvals: 2,
|
||||
..Default::default()
|
||||
})
|
||||
@@ -1359,8 +1359,8 @@ fn candidate_approval_applied_to_all_blocks() {
|
||||
let block_hash = Hash::repeat_byte(0x01);
|
||||
let block_hash_2 = Hash::repeat_byte(0x02);
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(0xCC));
|
||||
let validator_index_a = 0;
|
||||
let validator_index_b = 1;
|
||||
let validator_index_a = ValidatorIndex(0);
|
||||
let validator_index_b = ValidatorIndex(1);
|
||||
|
||||
let slot = Slot::from(1);
|
||||
let session_index = 1;
|
||||
@@ -1371,7 +1371,7 @@ fn candidate_approval_applied_to_all_blocks() {
|
||||
})),
|
||||
..some_state(StateConfig {
|
||||
validators: vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob, Sr25519Keyring::Charlie],
|
||||
validator_groups: vec![vec![0, 1], vec![2]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0), ValidatorIndex(1)], vec![ValidatorIndex(2)]],
|
||||
needed_approvals: 2,
|
||||
session_index,
|
||||
slot,
|
||||
@@ -1474,7 +1474,7 @@ fn approved_ancestor_all_approved() {
|
||||
})),
|
||||
..some_state(StateConfig {
|
||||
validators: vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob],
|
||||
validator_groups: vec![vec![0], vec![1]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0)], vec![ValidatorIndex(1)]],
|
||||
needed_approvals: 2,
|
||||
session_index,
|
||||
slot,
|
||||
@@ -1556,7 +1556,7 @@ fn approved_ancestor_missing_approval() {
|
||||
})),
|
||||
..some_state(StateConfig {
|
||||
validators: vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob],
|
||||
validator_groups: vec![vec![0], vec![1]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0)], vec![ValidatorIndex(1)]],
|
||||
needed_approvals: 2,
|
||||
session_index,
|
||||
slot,
|
||||
@@ -1633,7 +1633,7 @@ fn process_wakeup_trigger_assignment_launch_approval() {
|
||||
})),
|
||||
..some_state(StateConfig {
|
||||
validators: vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob],
|
||||
validator_groups: vec![vec![0], vec![1]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0)], vec![ValidatorIndex(1)]],
|
||||
needed_approvals: 2,
|
||||
session_index,
|
||||
slot,
|
||||
@@ -1660,7 +1660,7 @@ fn process_wakeup_trigger_assignment_launch_approval() {
|
||||
AssignmentCertKind::RelayVRFModulo { sample: 0 }
|
||||
),
|
||||
tranche: 0,
|
||||
validator_index: 0,
|
||||
validator_index: ValidatorIndex(0),
|
||||
triggered: false,
|
||||
}.into());
|
||||
|
||||
@@ -1720,7 +1720,7 @@ fn process_wakeup_schedules_wakeup() {
|
||||
})),
|
||||
..some_state(StateConfig {
|
||||
validators: vec![Sr25519Keyring::Alice, Sr25519Keyring::Bob],
|
||||
validator_groups: vec![vec![0], vec![1]],
|
||||
validator_groups: vec![vec![ValidatorIndex(0)], vec![ValidatorIndex(1)]],
|
||||
needed_approvals: 2,
|
||||
session_index,
|
||||
slot,
|
||||
@@ -1738,7 +1738,7 @@ fn process_wakeup_schedules_wakeup() {
|
||||
AssignmentCertKind::RelayVRFModulo { sample: 0 }
|
||||
),
|
||||
tranche: 10,
|
||||
validator_index: 0,
|
||||
validator_index: ValidatorIndex(0),
|
||||
triggered: false,
|
||||
}.into());
|
||||
|
||||
|
||||
@@ -968,7 +968,7 @@ fn process_message(
|
||||
AvailabilityStoreMessage::QueryChunkAvailability(candidate, validator_index, tx) => {
|
||||
let a = load_meta(&subsystem.db, &candidate)?
|
||||
.map_or(false, |m|
|
||||
*m.chunks_stored.get(validator_index as usize).as_deref().unwrap_or(&false)
|
||||
*m.chunks_stored.get(validator_index.0 as usize).as_deref().unwrap_or(&false)
|
||||
);
|
||||
let _ = tx.send(a);
|
||||
}
|
||||
@@ -1034,10 +1034,10 @@ fn store_chunk(
|
||||
None => return Ok(false), // we weren't informed of this candidate by import events.
|
||||
};
|
||||
|
||||
match meta.chunks_stored.get(chunk.index as usize).map(|b| *b) {
|
||||
match meta.chunks_stored.get(chunk.index.0 as usize).map(|b| *b) {
|
||||
Some(true) => return Ok(true), // already stored.
|
||||
Some(false) => {
|
||||
meta.chunks_stored.set(chunk.index as usize, true);
|
||||
meta.chunks_stored.set(chunk.index.0 as usize, true);
|
||||
|
||||
write_chunk(&mut tx, &candidate_hash, chunk.index, &chunk);
|
||||
write_meta(&mut tx, &candidate_hash, &meta);
|
||||
@@ -1090,7 +1090,7 @@ fn store_available_data(
|
||||
.map(|(index, (chunk, proof))| ErasureChunk {
|
||||
chunk: chunk.clone(),
|
||||
proof,
|
||||
index: index as u32,
|
||||
index: ValidatorIndex(index as u32),
|
||||
});
|
||||
|
||||
for chunk in erasure_chunks {
|
||||
@@ -1142,7 +1142,7 @@ fn prune_all(db: &Arc<dyn KeyValueDB>, clock: &dyn Clock) -> Result<(), Error> {
|
||||
// delete chunks.
|
||||
for (i, b) in meta.chunks_stored.iter().enumerate() {
|
||||
if *b {
|
||||
delete_chunk(&mut tx, &candidate_hash, i as _);
|
||||
delete_chunk(&mut tx, &candidate_hash, ValidatorIndex(i as _));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
|
||||
// but that's fine, we're still alive
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(33));
|
||||
let validator_index = 5;
|
||||
let validator_index = ValidatorIndex(5);
|
||||
let query_chunk = AvailabilityStoreMessage::QueryChunk(
|
||||
candidate_hash,
|
||||
validator_index,
|
||||
@@ -281,7 +281,7 @@ fn store_chunk_works() {
|
||||
let TestHarness { mut virtual_overseer } = test_harness;
|
||||
let relay_parent = Hash::repeat_byte(32);
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(33));
|
||||
let validator_index = 5;
|
||||
let validator_index = ValidatorIndex(5);
|
||||
let n_validators = 10;
|
||||
|
||||
let chunk = ErasureChunk {
|
||||
@@ -333,7 +333,7 @@ fn store_chunk_does_nothing_if_no_entry_already() {
|
||||
let TestHarness { mut virtual_overseer } = test_harness;
|
||||
let relay_parent = Hash::repeat_byte(32);
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(33));
|
||||
let validator_index = 5;
|
||||
let validator_index = ValidatorIndex(5);
|
||||
|
||||
let chunk = ErasureChunk {
|
||||
chunk: vec![1, 2, 3],
|
||||
@@ -372,7 +372,7 @@ fn query_chunk_checks_meta() {
|
||||
test_harness(TestState::default(), store.clone(), |test_harness| async move {
|
||||
let TestHarness { mut virtual_overseer } = test_harness;
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(33));
|
||||
let validator_index = 5;
|
||||
let validator_index = ValidatorIndex(5);
|
||||
let n_validators = 10;
|
||||
|
||||
// Ensure an entry already exists. In reality this would come from watching
|
||||
@@ -382,7 +382,7 @@ fn query_chunk_checks_meta() {
|
||||
data_available: false,
|
||||
chunks_stored: {
|
||||
let mut v = bitvec::bitvec![BitOrderLsb0, u8; 0; n_validators];
|
||||
v.set(validator_index as usize, true);
|
||||
v.set(validator_index.0 as usize, true);
|
||||
v
|
||||
},
|
||||
state: State::Unavailable(BETimestamp(0)),
|
||||
@@ -402,7 +402,7 @@ fn query_chunk_checks_meta() {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
let query_chunk = AvailabilityStoreMessage::QueryChunkAvailability(
|
||||
candidate_hash,
|
||||
validator_index + 1,
|
||||
ValidatorIndex(validator_index.0 + 1),
|
||||
tx,
|
||||
);
|
||||
|
||||
@@ -418,7 +418,7 @@ fn store_block_works() {
|
||||
test_harness(test_state.clone(), store.clone(), |test_harness| async move {
|
||||
let TestHarness { mut virtual_overseer } = test_harness;
|
||||
let candidate_hash = CandidateHash(Hash::repeat_byte(1));
|
||||
let validator_index = 5;
|
||||
let validator_index = ValidatorIndex(5);
|
||||
let n_validators = 10;
|
||||
|
||||
let pov = PoV {
|
||||
@@ -455,7 +455,7 @@ fn store_block_works() {
|
||||
let branch = branches.nth(5).unwrap();
|
||||
let expected_chunk = ErasureChunk {
|
||||
chunk: branch.1.to_vec(),
|
||||
index: 5,
|
||||
index: ValidatorIndex(5),
|
||||
proof: branch.0,
|
||||
};
|
||||
|
||||
@@ -497,10 +497,10 @@ fn store_pov_and_query_chunk_works() {
|
||||
|
||||
assert_eq!(rx.await.unwrap(), Ok(()));
|
||||
|
||||
for validator_index in 0..n_validators {
|
||||
let chunk = query_chunk(&mut virtual_overseer, candidate_hash, validator_index).await.unwrap();
|
||||
for i in 0..n_validators {
|
||||
let chunk = query_chunk(&mut virtual_overseer, candidate_hash, ValidatorIndex(i as _)).await.unwrap();
|
||||
|
||||
assert_eq!(chunk.chunk, chunks_expected[validator_index as usize]);
|
||||
assert_eq!(chunk.chunk, chunks_expected[i as usize]);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -842,7 +842,7 @@ async fn query_available_data(
|
||||
async fn query_chunk(
|
||||
virtual_overseer: &mut test_helpers::TestSubsystemContextHandle<AvailabilityStoreMessage>,
|
||||
candidate_hash: CandidateHash,
|
||||
index: u32,
|
||||
index: ValidatorIndex,
|
||||
) -> Option<ErasureChunk> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
|
||||
@@ -859,7 +859,7 @@ async fn query_all_chunks(
|
||||
expect_present: bool,
|
||||
) -> bool {
|
||||
for i in 0..n_validators {
|
||||
if query_chunk(virtual_overseer, candidate_hash, i).await.is_some() != expect_present {
|
||||
if query_chunk(virtual_overseer, candidate_hash, ValidatorIndex(i)).await.is_some() != expect_present {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -899,7 +899,7 @@ impl CandidateBackingJob {
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(self), fields(subsystem = LOG_TARGET))]
|
||||
fn check_statement_signature(&self, statement: &SignedFullStatement) -> Result<(), Error> {
|
||||
let idx = statement.validator_index() as usize;
|
||||
let idx = statement.validator_index().0 as usize;
|
||||
|
||||
if self.table_context.validators.len() > idx {
|
||||
statement.check_signature(
|
||||
@@ -1282,7 +1282,8 @@ mod tests {
|
||||
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
let validator_groups = vec![vec![2, 0, 3, 5], vec![1], vec![4]];
|
||||
let validator_groups = vec![vec![2, 0, 3, 5], vec![1], vec![4]]
|
||||
.into_iter().map(|g| g.into_iter().map(ValidatorIndex).collect()).collect();
|
||||
let group_rotation_info = GroupRotationInfo {
|
||||
session_start_block: 0,
|
||||
group_rotation_frequency: 100,
|
||||
@@ -1599,7 +1600,7 @@ mod tests {
|
||||
&test_state.keystore,
|
||||
Statement::Seconded(candidate_a.clone()),
|
||||
&test_state.signing_context,
|
||||
2,
|
||||
ValidatorIndex(2),
|
||||
&public2.into(),
|
||||
).await.ok().flatten().expect("should be signed");
|
||||
|
||||
@@ -1607,7 +1608,7 @@ mod tests {
|
||||
&test_state.keystore,
|
||||
Statement::Valid(candidate_a_hash),
|
||||
&test_state.signing_context,
|
||||
5,
|
||||
ValidatorIndex(5),
|
||||
&public1.into(),
|
||||
).await.ok().flatten().expect("should be signed");
|
||||
|
||||
@@ -1741,7 +1742,7 @@ mod tests {
|
||||
&test_state.keystore,
|
||||
Statement::Seconded(candidate_a.clone()),
|
||||
&test_state.signing_context,
|
||||
2,
|
||||
ValidatorIndex(2),
|
||||
&public2.into(),
|
||||
).await.ok().flatten().expect("should be signed");
|
||||
|
||||
@@ -1749,7 +1750,7 @@ mod tests {
|
||||
&test_state.keystore,
|
||||
Statement::Valid(candidate_a_hash),
|
||||
&test_state.signing_context,
|
||||
5,
|
||||
ValidatorIndex(5),
|
||||
&public1.into(),
|
||||
).await.ok().flatten().expect("should be signed");
|
||||
|
||||
@@ -1757,7 +1758,7 @@ mod tests {
|
||||
&test_state.keystore,
|
||||
Statement::Valid(candidate_a_hash),
|
||||
&test_state.signing_context,
|
||||
3,
|
||||
ValidatorIndex(3),
|
||||
&public3.into(),
|
||||
).await.ok().flatten().expect("should be signed");
|
||||
|
||||
@@ -1894,7 +1895,7 @@ mod tests {
|
||||
&test_state.keystore,
|
||||
Statement::Seconded(candidate_a.clone()),
|
||||
&test_state.signing_context,
|
||||
2,
|
||||
ValidatorIndex(2),
|
||||
&public2.into(),
|
||||
).await.ok().flatten().expect("should be signed");
|
||||
|
||||
@@ -1902,7 +1903,7 @@ mod tests {
|
||||
&test_state.keystore,
|
||||
Statement::Invalid(candidate_a_hash),
|
||||
&test_state.signing_context,
|
||||
2,
|
||||
ValidatorIndex(2),
|
||||
&public2.into(),
|
||||
).await.ok().flatten().expect("should be signed");
|
||||
|
||||
@@ -1910,7 +1911,7 @@ mod tests {
|
||||
&test_state.keystore,
|
||||
Statement::Invalid(candidate_a_hash),
|
||||
&test_state.signing_context,
|
||||
0,
|
||||
ValidatorIndex(0),
|
||||
&public0.into(),
|
||||
).await.ok().flatten().expect("should be signed");
|
||||
|
||||
@@ -2002,7 +2003,7 @@ mod tests {
|
||||
validator_index,
|
||||
s1,
|
||||
&test_state.signing_context,
|
||||
&test_state.validator_public[validator_index as usize],
|
||||
&test_state.validator_public[validator_index.0 as usize],
|
||||
).expect("signature must be valid");
|
||||
|
||||
SignedFullStatement::new(
|
||||
@@ -2010,7 +2011,7 @@ mod tests {
|
||||
validator_index,
|
||||
s2,
|
||||
&test_state.signing_context,
|
||||
&test_state.validator_public[validator_index as usize],
|
||||
&test_state.validator_public[validator_index.0 as usize],
|
||||
).expect("signature must be valid");
|
||||
}
|
||||
);
|
||||
@@ -2042,7 +2043,7 @@ mod tests {
|
||||
validator_index,
|
||||
s1,
|
||||
&test_state.signing_context,
|
||||
&test_state.validator_public[validator_index as usize],
|
||||
&test_state.validator_public[validator_index.0 as usize],
|
||||
).expect("signature must be valid");
|
||||
|
||||
SignedFullStatement::new(
|
||||
@@ -2050,7 +2051,7 @@ mod tests {
|
||||
validator_index,
|
||||
s2,
|
||||
&test_state.signing_context,
|
||||
&test_state.validator_public[validator_index as usize],
|
||||
&test_state.validator_public[validator_index.0 as usize],
|
||||
).expect("signature must be valid");
|
||||
}
|
||||
);
|
||||
@@ -2223,7 +2224,7 @@ mod tests {
|
||||
&test_state.keystore,
|
||||
Statement::Seconded(candidate.clone()),
|
||||
&test_state.signing_context,
|
||||
2,
|
||||
ValidatorIndex(2),
|
||||
&validator2.into(),
|
||||
).await.ok().flatten().expect("should be signed");
|
||||
|
||||
@@ -2361,7 +2362,7 @@ mod tests {
|
||||
&test_state.keystore,
|
||||
Statement::Seconded(candidate.clone()),
|
||||
&test_state.signing_context,
|
||||
2,
|
||||
ValidatorIndex(2),
|
||||
&public2.into(),
|
||||
).await.ok().flatten().expect("should be signed");
|
||||
|
||||
@@ -2503,7 +2504,7 @@ mod tests {
|
||||
&test_state.keystore,
|
||||
Statement::Seconded(candidate_a.clone()),
|
||||
&test_state.signing_context,
|
||||
2,
|
||||
ValidatorIndex(2),
|
||||
&public2.into(),
|
||||
).await.ok().flatten().expect("should be signed");
|
||||
|
||||
@@ -2542,7 +2543,7 @@ mod tests {
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
let validator_groups = {
|
||||
let mut validator_groups = HashMap::new();
|
||||
validator_groups.insert(para_id, vec![0, 1, 2, 3, 4, 5]);
|
||||
validator_groups.insert(para_id, vec![0, 1, 2, 3, 4, 5].into_iter().map(ValidatorIndex).collect());
|
||||
validator_groups
|
||||
};
|
||||
|
||||
@@ -2567,9 +2568,9 @@ mod tests {
|
||||
let attested = TableAttestedCandidate {
|
||||
candidate: Default::default(),
|
||||
validity_votes: vec![
|
||||
(5, fake_attestation(5)),
|
||||
(3, fake_attestation(3)),
|
||||
(1, fake_attestation(1)),
|
||||
(ValidatorIndex(5), fake_attestation(5)),
|
||||
(ValidatorIndex(3), fake_attestation(3)),
|
||||
(ValidatorIndex(1), fake_attestation(1)),
|
||||
],
|
||||
group_id: para_id,
|
||||
};
|
||||
|
||||
@@ -333,7 +333,7 @@ mod tests {
|
||||
block_on(async move {
|
||||
let (mut sender, mut receiver) = mpsc::channel(10);
|
||||
let relay_parent = Hash::default();
|
||||
let validator_index = 1u32;
|
||||
let validator_index = ValidatorIndex(1u32);
|
||||
|
||||
let future = construct_availability_bitfield(
|
||||
relay_parent,
|
||||
|
||||
@@ -501,7 +501,7 @@ fn bitfields_indicate_availability(
|
||||
let availability_len = availability.len();
|
||||
|
||||
for bitfield in bitfields {
|
||||
let validator_idx = bitfield.validator_index() as usize;
|
||||
let validator_idx = bitfield.validator_index().0 as usize;
|
||||
match availability.get_mut(validator_idx) {
|
||||
None => {
|
||||
// in principle, this function might return a `Result<bool, Error>` so that we can more clearly express this error condition
|
||||
|
||||
@@ -78,9 +78,9 @@ mod select_availability_bitfields {
|
||||
// we pass in three bitfields with two validators
|
||||
// this helps us check the postcondition that we get two bitfields back, for which the validators differ
|
||||
let bitfields = vec![
|
||||
block_on(signed_bitfield(&keystore, bitvec.clone(), 0)),
|
||||
block_on(signed_bitfield(&keystore, bitvec.clone(), 1)),
|
||||
block_on(signed_bitfield(&keystore, bitvec, 1)),
|
||||
block_on(signed_bitfield(&keystore, bitvec.clone(), ValidatorIndex(0))),
|
||||
block_on(signed_bitfield(&keystore, bitvec.clone(), ValidatorIndex(1))),
|
||||
block_on(signed_bitfield(&keystore, bitvec, ValidatorIndex(1))),
|
||||
];
|
||||
|
||||
let mut selected_bitfields = select_availability_bitfields(&cores, &bitfields);
|
||||
@@ -116,9 +116,9 @@ mod select_availability_bitfields {
|
||||
];
|
||||
|
||||
let bitfields = vec![
|
||||
block_on(signed_bitfield(&keystore, bitvec0, 0)),
|
||||
block_on(signed_bitfield(&keystore, bitvec1, 1)),
|
||||
block_on(signed_bitfield(&keystore, bitvec2.clone(), 2)),
|
||||
block_on(signed_bitfield(&keystore, bitvec0, ValidatorIndex(0))),
|
||||
block_on(signed_bitfield(&keystore, bitvec1, ValidatorIndex(1))),
|
||||
block_on(signed_bitfield(&keystore, bitvec2.clone(), ValidatorIndex(2))),
|
||||
];
|
||||
|
||||
let selected_bitfields = select_availability_bitfields(&cores, &bitfields);
|
||||
@@ -140,8 +140,8 @@ mod select_availability_bitfields {
|
||||
let cores = vec![occupied_core(0), occupied_core(1)];
|
||||
|
||||
let bitfields = vec![
|
||||
block_on(signed_bitfield(&keystore, bitvec, 1)),
|
||||
block_on(signed_bitfield(&keystore, bitvec1.clone(), 1)),
|
||||
block_on(signed_bitfield(&keystore, bitvec, ValidatorIndex(1))),
|
||||
block_on(signed_bitfield(&keystore, bitvec1.clone(), ValidatorIndex(1))),
|
||||
];
|
||||
|
||||
let selected_bitfields = select_availability_bitfields(&cores, &bitfields);
|
||||
@@ -174,11 +174,11 @@ mod select_availability_bitfields {
|
||||
// these are out of order but will be selected in order. The better
|
||||
// bitfield for 3 will be selected.
|
||||
let bitfields = vec![
|
||||
block_on(signed_bitfield(&keystore, bitvec2.clone(), 3)),
|
||||
block_on(signed_bitfield(&keystore, bitvec3.clone(), 3)),
|
||||
block_on(signed_bitfield(&keystore, bitvec0.clone(), 0)),
|
||||
block_on(signed_bitfield(&keystore, bitvec2.clone(), 2)),
|
||||
block_on(signed_bitfield(&keystore, bitvec1.clone(), 1)),
|
||||
block_on(signed_bitfield(&keystore, bitvec2.clone(), ValidatorIndex(3))),
|
||||
block_on(signed_bitfield(&keystore, bitvec3.clone(), ValidatorIndex(3))),
|
||||
block_on(signed_bitfield(&keystore, bitvec0.clone(), ValidatorIndex(0))),
|
||||
block_on(signed_bitfield(&keystore, bitvec2.clone(), ValidatorIndex(2))),
|
||||
block_on(signed_bitfield(&keystore, bitvec1.clone(), ValidatorIndex(1))),
|
||||
];
|
||||
|
||||
let selected_bitfields = select_availability_bitfields(&cores, &bitfields);
|
||||
|
||||
Reference in New Issue
Block a user