mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-22 10:21:04 +00:00
Improve approval tracing (#2697)
* improve tracing for approval voting * assignment criteria tracing * new syntax
This commit is contained in:
committed by
GitHub
parent
e16479e16e
commit
e49b3e5ca9
@@ -20,7 +20,7 @@ use polkadot_node_primitives::approval::{
|
||||
self as approval_types, AssignmentCert, AssignmentCertKind, DelayTranche, RelayVRFStory,
|
||||
};
|
||||
use polkadot_primitives::v1::{
|
||||
CoreIndex, ValidatorIndex, SessionInfo, AssignmentPair, AssignmentId, GroupIndex,
|
||||
CoreIndex, ValidatorIndex, SessionInfo, AssignmentPair, AssignmentId, GroupIndex, CandidateHash,
|
||||
};
|
||||
use sc_keystore::LocalKeystore;
|
||||
use parity_scale_codec::{Encode, Decode};
|
||||
@@ -178,7 +178,7 @@ pub(crate) trait AssignmentCriteria {
|
||||
keystore: &LocalKeystore,
|
||||
relay_vrf_story: RelayVRFStory,
|
||||
config: &Config,
|
||||
leaving_cores: Vec<(CoreIndex, GroupIndex)>,
|
||||
leaving_cores: Vec<(CandidateHash, CoreIndex, GroupIndex)>,
|
||||
) -> HashMap<CoreIndex, OurAssignment>;
|
||||
|
||||
fn check_assignment_cert(
|
||||
@@ -200,7 +200,7 @@ impl AssignmentCriteria for RealAssignmentCriteria {
|
||||
keystore: &LocalKeystore,
|
||||
relay_vrf_story: RelayVRFStory,
|
||||
config: &Config,
|
||||
leaving_cores: Vec<(CoreIndex, GroupIndex)>,
|
||||
leaving_cores: Vec<(CandidateHash, CoreIndex, GroupIndex)>,
|
||||
) -> HashMap<CoreIndex, OurAssignment> {
|
||||
compute_assignments(
|
||||
keystore,
|
||||
@@ -244,7 +244,7 @@ pub(crate) fn compute_assignments(
|
||||
keystore: &LocalKeystore,
|
||||
relay_vrf_story: RelayVRFStory,
|
||||
config: &Config,
|
||||
leaving_cores: impl IntoIterator<Item = (CoreIndex, GroupIndex)> + Clone,
|
||||
leaving_cores: impl IntoIterator<Item = (CandidateHash, CoreIndex, GroupIndex)> + Clone,
|
||||
) -> HashMap<CoreIndex, OurAssignment> {
|
||||
if config.n_cores == 0 || config.assignment_keys.is_empty() || config.validator_groups.is_empty() {
|
||||
return HashMap::new()
|
||||
@@ -271,8 +271,8 @@ pub(crate) fn compute_assignments(
|
||||
|
||||
// Ignore any cores where the assigned group is our own.
|
||||
let leaving_cores = leaving_cores.into_iter()
|
||||
.filter(|&(_, ref g)| !is_in_backing_group(&config.validator_groups, index, *g))
|
||||
.map(|(c, _)| c)
|
||||
.filter(|&(_, _, ref g)| !is_in_backing_group(&config.validator_groups, index, *g))
|
||||
.map(|(c_hash, core, _)| (c_hash, core))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let assignments_key: &sp_application_crypto::sr25519::Pair = assignments_key.as_ref();
|
||||
@@ -308,7 +308,7 @@ fn compute_relay_vrf_modulo_assignments(
|
||||
validator_index: ValidatorIndex,
|
||||
config: &Config,
|
||||
relay_vrf_story: RelayVRFStory,
|
||||
leaving_cores: impl IntoIterator<Item = CoreIndex> + Clone,
|
||||
leaving_cores: impl IntoIterator<Item = (CandidateHash, CoreIndex)> + Clone,
|
||||
assignments: &mut HashMap<CoreIndex, OurAssignment>,
|
||||
) {
|
||||
for rvm_sample in 0..config.relay_vrf_modulo_samples {
|
||||
@@ -322,7 +322,18 @@ fn compute_relay_vrf_modulo_assignments(
|
||||
relay_vrf_modulo_transcript(relay_vrf_story.clone(), rvm_sample),
|
||||
|vrf_in_out| {
|
||||
*core = relay_vrf_modulo_core(&vrf_in_out, config.n_cores);
|
||||
if leaving_cores.clone().into_iter().any(|c| c == *core) {
|
||||
if let Some((candidate_hash, _))
|
||||
= leaving_cores.clone().into_iter().find(|(_, c)| c == core)
|
||||
{
|
||||
tracing::trace!(
|
||||
target: LOG_TARGET,
|
||||
?candidate_hash,
|
||||
?core,
|
||||
?validator_index,
|
||||
tranche = 0,
|
||||
"RelayVRFModulo Assignment."
|
||||
);
|
||||
|
||||
Some(assigned_core_transcript(*core))
|
||||
} else {
|
||||
None
|
||||
@@ -355,10 +366,10 @@ fn compute_relay_vrf_delay_assignments(
|
||||
validator_index: ValidatorIndex,
|
||||
config: &Config,
|
||||
relay_vrf_story: RelayVRFStory,
|
||||
leaving_cores: impl IntoIterator<Item = CoreIndex>,
|
||||
leaving_cores: impl IntoIterator<Item = (CandidateHash, CoreIndex)>,
|
||||
assignments: &mut HashMap<CoreIndex, OurAssignment>,
|
||||
) {
|
||||
for core in leaving_cores {
|
||||
for (candidate_hash, core) in leaving_cores {
|
||||
let (vrf_in_out, vrf_proof, _) = assignments_key.vrf_sign(
|
||||
relay_vrf_delay_transcript(relay_vrf_story.clone(), core),
|
||||
);
|
||||
@@ -381,11 +392,25 @@ fn compute_relay_vrf_delay_assignments(
|
||||
triggered: false,
|
||||
};
|
||||
|
||||
match assignments.entry(core) {
|
||||
Entry::Vacant(e) => { let _ = e.insert(our_assignment); }
|
||||
let used = match assignments.entry(core) {
|
||||
Entry::Vacant(e) => { let _ = e.insert(our_assignment); true }
|
||||
Entry::Occupied(mut e) => if e.get().tranche > our_assignment.tranche {
|
||||
e.insert(our_assignment);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
},
|
||||
};
|
||||
|
||||
if used {
|
||||
tracing::trace!(
|
||||
target: LOG_TARGET,
|
||||
?candidate_hash,
|
||||
?core,
|
||||
?validator_index,
|
||||
tranche,
|
||||
"RelayVRFDelay Assignment",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -500,7 +525,7 @@ mod tests {
|
||||
use sp_keyring::sr25519::Keyring as Sr25519Keyring;
|
||||
use sp_application_crypto::sr25519;
|
||||
use sp_core::crypto::Pair as PairT;
|
||||
use polkadot_primitives::v1::ASSIGNMENT_KEY_TYPE_ID;
|
||||
use polkadot_primitives::v1::{ASSIGNMENT_KEY_TYPE_ID, Hash};
|
||||
use polkadot_node_primitives::approval::{VRFOutput, VRFProof};
|
||||
|
||||
// sets up a keystore with the given keyring accounts.
|
||||
@@ -560,6 +585,9 @@ mod tests {
|
||||
make_keystore(&[Sr25519Keyring::Alice])
|
||||
);
|
||||
|
||||
let c_a = CandidateHash(Hash::repeat_byte(0));
|
||||
let c_b = CandidateHash(Hash::repeat_byte(1));
|
||||
|
||||
let relay_vrf_story = RelayVRFStory([42u8; 32]);
|
||||
let assignments = compute_assignments(
|
||||
&keystore,
|
||||
@@ -576,7 +604,7 @@ mod tests {
|
||||
relay_vrf_modulo_samples: 3,
|
||||
n_delay_tranches: 40,
|
||||
},
|
||||
vec![(CoreIndex(0), GroupIndex(1)), (CoreIndex(1), GroupIndex(0))],
|
||||
vec![(c_a, CoreIndex(0), GroupIndex(1)), (c_b, CoreIndex(1), GroupIndex(0))],
|
||||
);
|
||||
|
||||
// Note that alice is in group 0, which was the backing group for core 1.
|
||||
@@ -591,6 +619,9 @@ mod tests {
|
||||
make_keystore(&[Sr25519Keyring::Alice])
|
||||
);
|
||||
|
||||
let c_a = CandidateHash(Hash::repeat_byte(0));
|
||||
let c_b = CandidateHash(Hash::repeat_byte(1));
|
||||
|
||||
let relay_vrf_story = RelayVRFStory([42u8; 32]);
|
||||
let assignments = compute_assignments(
|
||||
&keystore,
|
||||
@@ -607,7 +638,7 @@ mod tests {
|
||||
relay_vrf_modulo_samples: 3,
|
||||
n_delay_tranches: 40,
|
||||
},
|
||||
vec![(CoreIndex(0), GroupIndex(0)), (CoreIndex(1), GroupIndex(1))],
|
||||
vec![(c_a, CoreIndex(0), GroupIndex(0)), (c_b, CoreIndex(1), GroupIndex(1))],
|
||||
);
|
||||
|
||||
assert_eq!(assignments.len(), 1);
|
||||
@@ -680,6 +711,7 @@ mod tests {
|
||||
&config,
|
||||
(0..n_cores)
|
||||
.map(|i| (
|
||||
CandidateHash(Hash::repeat_byte(i as u8)),
|
||||
CoreIndex(i as u32),
|
||||
group_for_core(i),
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user