back look during the slashing

Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
Uncle Stinky 2025-11-05 15:55:37 +03:00
parent eb181c7f44
commit c872eca8ac
Signed by: st1nky
GPG Key ID: 016064BD97603B40
2 changed files with 19 additions and 2 deletions

View File

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

View File

@ -294,6 +294,16 @@ pub mod pallet {
ValueQuery,
>;
#[pallet::storage]
#[pallet::getter(fn validators)]
pub(super) type Validators<T: Config> = StorageMap<
_,
Twox64Concat,
SessionIndex,
WeakBoundedVec<ValidatorId<T>, T::MaxAuthorities>,
OptionQuery,
>;
#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
@ -1075,16 +1085,23 @@ impl<T: Config> Pallet<T> {
let bounded_authorities = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(authorities)
.expect("more than the maximum number of authorities");
let validators = T::ValidatorSet::validators();
let bounded_validators = WeakBoundedVec::<_, T::MaxAuthorities>::try_from(validators)
.expect("more than the maximum number of validators");
if let Some(target_session_index) = session_index.checked_sub(T::HistoryDepth::get()) {
Self::clear_history(&target_session_index);
}
Validators::<T>::insert(&session_index, bounded_validators);
Authorities::<T>::set(&session_index, bounded_authorities);
ClapsInSession::<T>::set(&session_index, Default::default());
}
fn clear_history(target_session_index: &SessionIndex) {
ClapsInSession::<T>::remove(target_session_index);
Authorities::<T>::remove(target_session_index);
Validators::<T>::remove(target_session_index);
let mut cursor = ReceivedClaps::<T>::clear_prefix((target_session_index,), u32::MAX, None);
debug_assert!(cursor.maybe_cursor.is_none());
cursor =
@ -1136,8 +1153,8 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
}
fn on_before_session_ending() {
let validators = T::ValidatorSet::validators();
let session_index = T::ValidatorSet::session_index().saturating_sub(1);
let validators = Validators::<T>::get(&session_index).unwrap_or_default();
let authorities_len = Authorities::<T>::get(&session_index).len();
let claps_in_session = ClapsInSession::<T>::get(&session_index);