optimize offenders gathering with a single pass over the data

Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
Uncle Stinky 2025-08-27 15:31:32 +03:00
parent 46aa18aafe
commit 7edc8935b6
Signed by: st1nky
GPG Key ID: 016064BD97603B40
2 changed files with 8 additions and 6 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "ghost-slow-clap"
version = "0.3.41"
version = "0.3.42"
description = "Applause protocol for the EVM bridge"
license.workspace = true
authors.workspace = true

View File

@ -1123,12 +1123,14 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
let offenders = validators
.into_iter()
.enumerate()
.filter(|(index, _)| !Self::is_good_actor(*index, median_claps, &claps_in_session))
.filter_map(|(_, id)| {
.filter_map(|(index, id)| {
(!Self::is_good_actor(index, median_claps, &claps_in_session)).then(|| {
<T::ValidatorSet as ValidatorSetWithIdentification<T::AccountId>>::IdentificationOf::convert(
id.clone(),
).map(|full_id| (id, full_id))
})
.flatten()
})
.collect::<Vec<IdentificationTuple<T>>>();
if offenders.is_empty() {