Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Request based availability distribution #2423

Merged
merged 66 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
6f2e0e9
WIP
eskimor Feb 4, 2021
da850f7
availability distribution, still very wip.
eskimor Feb 9, 2021
fbf0ec1
Some docs on what I intend to do.
eskimor Feb 9, 2021
ac543c1
Checkpoint of session cache implementation
eskimor Feb 10, 2021
07f6bc3
More work, mostly on cache
eskimor Feb 11, 2021
ef84ea5
Only derive MallocSizeOf and Debug for std.
eskimor Feb 12, 2021
1e35804
availability-distribution: Cache feature complete.
eskimor Feb 12, 2021
d8fda81
Sketch out logic in `FetchTask` for actual fetching.
eskimor Feb 13, 2021
47036c9
Format cleanup.
eskimor Feb 13, 2021
4ad902f
More format fixes.
eskimor Feb 13, 2021
fee9476
Almost feature complete `fetch_task`.
eskimor Feb 15, 2021
b9aa906
Finish FetchTask so far.
eskimor Feb 15, 2021
a65562f
Directly use AuthorityDiscoveryId in protocol and cache.
eskimor Feb 16, 2021
4a43561
Resolve `AuthorityDiscoveryId` on sending requests.
eskimor Feb 16, 2021
6543b30
Rework fetch_task
eskimor Feb 17, 2021
256e559
From<u32> implementation for `ValidatorIndex`.
eskimor Feb 17, 2021
f8d5fef
Fixes and more integration work.
eskimor Feb 17, 2021
5e77fb4
Make session cache proper lru cache.
eskimor Feb 18, 2021
72704ee
Use proper lru cache.
eskimor Feb 18, 2021
60a2faf
Requester finished.
eskimor Feb 18, 2021
452b55f
ProtocolState -> Requester
eskimor Feb 18, 2021
2b9b983
Cleanup + fixes.
eskimor Feb 18, 2021
d683f10
Remove unused functions
eskimor Feb 18, 2021
d7a8a31
availability-distribution responding side.
eskimor Feb 19, 2021
3fed607
Cleanup + Fixes.
eskimor Feb 19, 2021
39d6bc2
More fixes.
eskimor Feb 19, 2021
49b1764
More fixes.
eskimor Feb 19, 2021
a141330
Some docs.
eskimor Feb 19, 2021
fad4586
Docs.
eskimor Feb 19, 2021
e617e91
Fix reporting of bad guys.
eskimor Feb 19, 2021
789a3e9
Merge branch 'master' into rk-availability-distribution-2306
eskimor Feb 19, 2021
a4eef9b
Fix tests
eskimor Feb 19, 2021
ea5f6a4
Make all tests compile.
eskimor Feb 19, 2021
00e2f69
Fix test.
eskimor Feb 19, 2021
c837d98
Cleanup + get rid of some warnings.
eskimor Feb 19, 2021
09fa9fe
Merge branch 'master' into rk-availability-distribution-2306
eskimor Feb 22, 2021
8945fbb
state -> requester
eskimor Feb 22, 2021
c9984fb
Mostly doc fixes.
eskimor Feb 22, 2021
7707759
Fix test suite.
eskimor Feb 22, 2021
e7623d4
Get rid of now redundant message types.
eskimor Feb 22, 2021
e8d7e44
WIP
eskimor Feb 22, 2021
5fb8418
Rob's review remarks.
eskimor Feb 22, 2021
41f60e4
Merge branch 'rk-drop-redundant-messages-2306' into rk-availability-d…
eskimor Feb 22, 2021
9780f3a
Fix test suite.
eskimor Feb 22, 2021
5bbcea4
core.relay_parent -> leaf for session request.
eskimor Feb 22, 2021
b792a89
Style fix.
eskimor Feb 22, 2021
75e6af8
Decrease request timeout.
eskimor Feb 22, 2021
ca7c182
Merge branch 'rk-metrics-2306' into rk-availability-distribution-2306
eskimor Feb 23, 2021
53fdeb3
Cleanup obsolete errors.
eskimor Feb 23, 2021
ce21a10
Metrics + don't fail on non fatal errors.
eskimor Feb 23, 2021
64d7246
requester.rs -> requester/mod.rs
eskimor Feb 23, 2021
2a9650f
Panic on invalid BadValidator report.
eskimor Feb 23, 2021
4d05d00
Fix indentation.
eskimor Feb 23, 2021
aadc80f
Use typed default timeout constant.
eskimor Feb 23, 2021
e45f61c
Make channel size 0, as each sender gets one slot anyways.
eskimor Feb 23, 2021
43dfd1c
Fix incorrect metrics initialization.
eskimor Feb 23, 2021
e262782
Merge branch 'master' into rk-availability-distribution-2306
eskimor Feb 23, 2021
5353157
Fix build after merge.
eskimor Feb 23, 2021
ff94444
More fixes.
eskimor Feb 23, 2021
6b71e54
Hopefully valid metrics names.
eskimor Feb 24, 2021
190adaa
Better metrics names.
eskimor Feb 25, 2021
8901344
Some tests that already work.
eskimor Feb 25, 2021
1d29b5c
Slightly better docs.
eskimor Feb 25, 2021
83ff666
Some more tests.
eskimor Feb 26, 2021
e9210e5
Merge branch 'master' into rk-availability-distribution-2306
eskimor Feb 26, 2021
a0e01ec
Fix network bridge test.
eskimor Feb 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 35 additions & 35 deletions node/core/approval-voting/src/approval_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand All @@ -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));
}

Expand 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],
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions node/core/approval-voting/src/criteria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
};

Expand Down Expand Up @@ -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)
});
}
Expand Down
3 changes: 2 additions & 1 deletion node/core/approval-voting/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,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};
Expand Down Expand Up @@ -1555,7 +1556,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,
Expand Down
10 changes: 5 additions & 5 deletions node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,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),
);

Expand Down Expand Up @@ -910,7 +910,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)
};
Expand Down Expand Up @@ -1463,13 +1463,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(),
);

Expand All @@ -1488,7 +1488,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(),
);

Expand Down
10 changes: 5 additions & 5 deletions node/core/approval-voting/src/persisted_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
Loading