fixes for the inconsistency of the slow claps
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
5307afe352
commit
eb181c7f44
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ghost-slow-clap"
|
name = "ghost-slow-clap"
|
||||||
version = "0.3.42"
|
version = "0.3.43"
|
||||||
description = "Applause protocol for the EVM bridge"
|
description = "Applause protocol for the EVM bridge"
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|||||||
@ -72,7 +72,7 @@ const LOG_TARGET: &str = "runtime::ghost-slow-clap";
|
|||||||
const DB_PREFIX: &[u8] = b"slow_clap::";
|
const DB_PREFIX: &[u8] = b"slow_clap::";
|
||||||
|
|
||||||
const FETCH_TIMEOUT_PERIOD: u64 = 3_000;
|
const FETCH_TIMEOUT_PERIOD: u64 = 3_000;
|
||||||
const LOCK_BLOCK_EXPIRATION: u64 = 10;
|
const LOCK_BLOCK_EXPIRATION: u64 = 20;
|
||||||
|
|
||||||
pub type AuthIndex = u32;
|
pub type AuthIndex = u32;
|
||||||
|
|
||||||
@ -378,7 +378,8 @@ pub mod pallet {
|
|||||||
|
|
||||||
fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
|
fn validate_unsigned(_source: TransactionSource, call: &Self::Call) -> TransactionValidity {
|
||||||
if let Call::slow_clap { clap, signature } = call {
|
if let Call::slow_clap { clap, signature } = call {
|
||||||
let authorities = Authorities::<T>::get(&clap.session_index);
|
let (session_index, _) = Self::mended_session_index(&clap);
|
||||||
|
let authorities = Authorities::<T>::get(&session_index);
|
||||||
let authority = match authorities.get(clap.authority_index as usize) {
|
let authority = match authorities.get(clap.authority_index as usize) {
|
||||||
Some(authority) => authority,
|
Some(authority) => authority,
|
||||||
None => return InvalidTransaction::BadSigner.into(),
|
None => return InvalidTransaction::BadSigner.into(),
|
||||||
@ -459,27 +460,49 @@ impl<T: Config> Pallet<T> {
|
|||||||
hex_str
|
hex_str
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_slow_clap(clap: &Clap<T::AccountId, NetworkIdOf<T>, BalanceOf<T>>) -> DispatchResult {
|
fn mended_session_index(
|
||||||
let authorities = Authorities::<T>::get(&clap.session_index);
|
clap: &Clap<T::AccountId, NetworkIdOf<T>, BalanceOf<T>>,
|
||||||
ensure!(
|
) -> (SessionIndex, H256) {
|
||||||
authorities.get(clap.authority_index as usize).is_some(),
|
let prev_session_index = clap.session_index.saturating_sub(1);
|
||||||
Error::<T>::NotAnAuthority
|
let clap_unique_hash =
|
||||||
|
Self::generate_unique_hash(&clap.receiver, &clap.amount, &clap.network_id);
|
||||||
|
|
||||||
|
let received_claps_key = (
|
||||||
|
prev_session_index,
|
||||||
|
&clap.transaction_hash,
|
||||||
|
&clap_unique_hash,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let session_index = ReceivedClaps::<T>::get(&received_claps_key)
|
||||||
|
.is_empty()
|
||||||
|
.then(|| clap.session_index)
|
||||||
|
.unwrap_or(prev_session_index);
|
||||||
|
|
||||||
|
(session_index, clap_unique_hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_slow_clap(clap: &Clap<T::AccountId, NetworkIdOf<T>, BalanceOf<T>>) -> DispatchResult {
|
||||||
|
let (session_index, clap_unique_hash) = Self::mended_session_index(&clap);
|
||||||
|
let mut claps_in_session = ClapsInSession::<T>::get(&session_index);
|
||||||
|
|
||||||
ensure!(
|
ensure!(
|
||||||
ClapsInSession::<T>::get(&clap.session_index)
|
claps_in_session
|
||||||
.get(&clap.authority_index)
|
.get(&clap.authority_index)
|
||||||
.map(|info| !info.disabled)
|
.map(|info| !info.disabled)
|
||||||
.unwrap_or(true),
|
.unwrap_or(true),
|
||||||
Error::<T>::CurrentValidatorIsDisabled
|
Error::<T>::CurrentValidatorIsDisabled
|
||||||
);
|
);
|
||||||
|
|
||||||
let clap_unique_hash =
|
let disabled_authorites = claps_in_session
|
||||||
Self::generate_unique_hash(&clap.receiver, &clap.amount, &clap.network_id);
|
.values()
|
||||||
let received_claps_key = (
|
.filter(|info| info.disabled)
|
||||||
clap.session_index,
|
.count();
|
||||||
&clap.transaction_hash,
|
|
||||||
&clap_unique_hash,
|
let active_authorities = Authorities::<T>::get(&session_index)
|
||||||
);
|
.len()
|
||||||
|
.saturating_sub(disabled_authorites);
|
||||||
|
|
||||||
|
let received_claps_key = (session_index, &clap.transaction_hash, &clap_unique_hash);
|
||||||
|
|
||||||
let number_of_received_claps =
|
let number_of_received_claps =
|
||||||
ReceivedClaps::<T>::try_mutate(&received_claps_key, |tree_of_claps| {
|
ReceivedClaps::<T>::try_mutate(&received_claps_key, |tree_of_claps| {
|
||||||
@ -498,15 +521,15 @@ impl<T: Config> Pallet<T> {
|
|||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
ClapsInSession::<T>::mutate(&clap.session_index, |claps_details| {
|
claps_in_session
|
||||||
(*claps_details)
|
|
||||||
.entry(clap.authority_index)
|
.entry(clap.authority_index)
|
||||||
.and_modify(|individual| (*individual).claps.saturating_inc())
|
.and_modify(|individual| individual.claps.saturating_inc())
|
||||||
.or_insert(SessionAuthorityInfo {
|
.or_insert(SessionAuthorityInfo {
|
||||||
claps: 1u32,
|
claps: 1u32,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
ClapsInSession::<T>::insert(&session_index, claps_in_session);
|
||||||
|
|
||||||
Self::deposit_event(Event::<T>::Clapped {
|
Self::deposit_event(Event::<T>::Clapped {
|
||||||
authority_id: clap.authority_index,
|
authority_id: clap.authority_index,
|
||||||
@ -517,7 +540,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let enough_authorities =
|
let enough_authorities =
|
||||||
Perbill::from_rational(number_of_received_claps as u32, authorities.len() as u32)
|
Perbill::from_rational(number_of_received_claps as u32, active_authorities as u32)
|
||||||
> Perbill::from_percent(T::ApplauseThreshold::get());
|
> Perbill::from_percent(T::ApplauseThreshold::get());
|
||||||
|
|
||||||
if enough_authorities {
|
if enough_authorities {
|
||||||
@ -1113,8 +1136,8 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_before_session_ending() {
|
fn on_before_session_ending() {
|
||||||
let session_index = T::ValidatorSet::session_index();
|
|
||||||
let validators = T::ValidatorSet::validators();
|
let validators = T::ValidatorSet::validators();
|
||||||
|
let session_index = T::ValidatorSet::session_index().saturating_sub(1);
|
||||||
let authorities_len = Authorities::<T>::get(&session_index).len();
|
let authorities_len = Authorities::<T>::get(&session_index).len();
|
||||||
let claps_in_session = ClapsInSession::<T>::get(&session_index);
|
let claps_in_session = ClapsInSession::<T>::get(&session_index);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user