diff --git a/pallets/slow-clap/Cargo.toml b/pallets/slow-clap/Cargo.toml index a499bcb..f8dea97 100644 --- a/pallets/slow-clap/Cargo.toml +++ b/pallets/slow-clap/Cargo.toml @@ -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 diff --git a/pallets/slow-clap/src/lib.rs b/pallets/slow-clap/src/lib.rs index 3e932ca..a8c77b5 100644 --- a/pallets/slow-clap/src/lib.rs +++ b/pallets/slow-clap/src/lib.rs @@ -294,6 +294,16 @@ pub mod pallet { ValueQuery, >; + #[pallet::storage] + #[pallet::getter(fn validators)] + pub(super) type Validators = StorageMap< + _, + Twox64Concat, + SessionIndex, + WeakBoundedVec, T::MaxAuthorities>, + OptionQuery, + >; + #[pallet::genesis_config] #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { @@ -1075,16 +1085,23 @@ impl Pallet { 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::::insert(&session_index, bounded_validators); Authorities::::set(&session_index, bounded_authorities); ClapsInSession::::set(&session_index, Default::default()); } fn clear_history(target_session_index: &SessionIndex) { ClapsInSession::::remove(target_session_index); + Authorities::::remove(target_session_index); + Validators::::remove(target_session_index); let mut cursor = ReceivedClaps::::clear_prefix((target_session_index,), u32::MAX, None); debug_assert!(cursor.maybe_cursor.is_none()); cursor = @@ -1136,8 +1153,8 @@ impl OneSessionHandler for Pallet { } fn on_before_session_ending() { - let validators = T::ValidatorSet::validators(); let session_index = T::ValidatorSet::session_index().saturating_sub(1); + let validators = Validators::::get(&session_index).unwrap_or_default(); let authorities_len = Authorities::::get(&session_index).len(); let claps_in_session = ClapsInSession::::get(&session_index);