mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 03:17:56 +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:
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user