move complaints matrix to flat Vec, eliminate dynamic allocations
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
8d097990a7
commit
3d2d905629
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ghost-exodus"
|
name = "ghost-exodus"
|
||||||
version = "0.0.10"
|
version = "0.0.11"
|
||||||
description = "Threshold signature generation with DKG included"
|
description = "Threshold signature generation with DKG included"
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|||||||
@ -2417,6 +2417,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
let mut number_of_leaked_keys = 0;
|
let mut number_of_leaked_keys = 0;
|
||||||
|
|
||||||
let qualified_indexes = dkg_qualification.get_indexes();
|
let qualified_indexes = dkg_qualification.get_indexes();
|
||||||
|
let total_authorities_len = qualified_indexes.count_ones::<usize>();
|
||||||
|
|
||||||
let mut failed_authorities = ParticipantsBitmap::<T>::empty_from(
|
let mut failed_authorities = ParticipantsBitmap::<T>::empty_from(
|
||||||
&qualified_indexes,
|
&qualified_indexes,
|
||||||
@ -2426,17 +2427,17 @@ impl<T: Config> Pallet<T> {
|
|||||||
&qualified_indexes,
|
&qualified_indexes,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut complaints_matrix: BTreeMap<AuthIndex, ParticipantsBitmap<T>> =
|
let mut complaints_matrix = vec![
|
||||||
BTreeMap::new();
|
ParticipantsBitmap::<T>::empty_from(&qualified_indexes);
|
||||||
|
total_authorities_len
|
||||||
|
];
|
||||||
|
|
||||||
complaints_bitmap.iter().for_each(|(&accuser_index, offenders_bitmap)| {
|
complaints_bitmap.iter().for_each(|(&accuser_index, offenders_bitmap)| {
|
||||||
offenders_bitmap.iter().for_each(|offended_index| {
|
offenders_bitmap.iter().for_each(|offended_index: AuthIndex| {
|
||||||
complaints_matrix
|
let idx = offended_index as usize;
|
||||||
.entry(offended_index)
|
if idx >= complaints_matrix.len() { return; }
|
||||||
.or_insert_with(|| {
|
|
||||||
ParticipantsBitmap::<T>::empty_from(&qualified_indexes)
|
complaints_matrix[idx].insert(accuser_index);
|
||||||
})
|
|
||||||
.insert(accuser_index);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -2447,13 +2448,17 @@ impl<T: Config> Pallet<T> {
|
|||||||
number_of_leaked_keys.saturating_inc();
|
number_of_leaked_keys.saturating_inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(accusers_bitmap) = complaints_matrix.get(&offended_index) {
|
let idx = offended_index as usize;
|
||||||
let successful_justifications = accusers_bitmap & recipients_bitmap;
|
if idx >= complaints_matrix.len() { return; }
|
||||||
let failed_to_justify = successful_justifications != *accusers_bitmap;
|
|
||||||
|
|
||||||
if failed_to_justify {
|
let accusers_bitmap = &complaints_matrix[idx];
|
||||||
failed_authorities.insert(offended_index);
|
if accusers_bitmap.is_empty() { return; }
|
||||||
}
|
|
||||||
|
let successful_justifications = accusers_bitmap & recipients_bitmap;
|
||||||
|
let failed_to_justify = successful_justifications != *accusers_bitmap;
|
||||||
|
|
||||||
|
if failed_to_justify {
|
||||||
|
failed_authorities.insert(offended_index);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user