fixes for self_applause function
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
parent
c872eca8ac
commit
ebae9fadbe
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "ghost-slow-clap"
|
name = "ghost-slow-clap"
|
||||||
version = "0.3.44"
|
version = "0.3.45"
|
||||||
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
|
||||||
|
|||||||
@ -35,7 +35,11 @@ use sp_staking::{
|
|||||||
offence::{Kind, Offence, ReportOffence},
|
offence::{Kind, Offence, ReportOffence},
|
||||||
SessionIndex,
|
SessionIndex,
|
||||||
};
|
};
|
||||||
use sp_std::{collections::btree_map::BTreeMap, prelude::*, vec::Vec};
|
use sp_std::{
|
||||||
|
collections::{btree_map::BTreeMap, btree_set::BTreeSet},
|
||||||
|
prelude::*,
|
||||||
|
vec::Vec,
|
||||||
|
};
|
||||||
|
|
||||||
use ghost_networks::{
|
use ghost_networks::{
|
||||||
NetworkData, NetworkDataBasicHandler, NetworkDataInspectHandler, NetworkDataMutateHandler,
|
NetworkData, NetworkDataBasicHandler, NetworkDataInspectHandler, NetworkDataMutateHandler,
|
||||||
@ -238,7 +242,6 @@ pub mod pallet {
|
|||||||
#[pallet::error]
|
#[pallet::error]
|
||||||
pub enum Error<T> {
|
pub enum Error<T> {
|
||||||
NotEnoughClaps,
|
NotEnoughClaps,
|
||||||
NotAnAuthority,
|
|
||||||
CurrentValidatorIsDisabled,
|
CurrentValidatorIsDisabled,
|
||||||
AlreadyClapped,
|
AlreadyClapped,
|
||||||
UnregisteredClapRemove,
|
UnregisteredClapRemove,
|
||||||
@ -340,7 +343,7 @@ pub mod pallet {
|
|||||||
pub fn self_applause(
|
pub fn self_applause(
|
||||||
origin: OriginFor<T>,
|
origin: OriginFor<T>,
|
||||||
network_id: NetworkIdOf<T>,
|
network_id: NetworkIdOf<T>,
|
||||||
session_index: SessionIndex,
|
prev_session_index: SessionIndex,
|
||||||
transaction_hash: H256,
|
transaction_hash: H256,
|
||||||
receiver: T::AccountId,
|
receiver: T::AccountId,
|
||||||
amount: BalanceOf<T>,
|
amount: BalanceOf<T>,
|
||||||
@ -348,7 +351,7 @@ pub mod pallet {
|
|||||||
let _ = ensure_signed(origin)?;
|
let _ = ensure_signed(origin)?;
|
||||||
Self::applause_if_posible(
|
Self::applause_if_posible(
|
||||||
network_id,
|
network_id,
|
||||||
session_index,
|
prev_session_index,
|
||||||
transaction_hash,
|
transaction_hash,
|
||||||
receiver,
|
receiver,
|
||||||
amount,
|
amount,
|
||||||
@ -614,29 +617,35 @@ impl<T: Config> Pallet<T> {
|
|||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
let curr_session_index = prev_session_index.saturating_add(1);
|
let curr_session_index = prev_session_index.saturating_add(1);
|
||||||
let clap_unique_hash = Self::generate_unique_hash(&receiver, &amount, &network_id);
|
let clap_unique_hash = Self::generate_unique_hash(&receiver, &amount, &network_id);
|
||||||
let prev_received_claps_key = (prev_session_index, &transaction_hash, &clap_unique_hash);
|
|
||||||
let curr_received_claps_key = (curr_session_index, &transaction_hash, &clap_unique_hash);
|
|
||||||
|
|
||||||
let prev_authorities = Authorities::<T>::get(&prev_session_index);
|
let prev_authorities = Authorities::<T>::get(&prev_session_index);
|
||||||
let curr_authorities = Authorities::<T>::get(&curr_session_index);
|
let curr_authorities = Authorities::<T>::get(&curr_session_index);
|
||||||
|
|
||||||
let prev_received_claps = ReceivedClaps::<T>::get(&prev_received_claps_key).into_inner();
|
let prev_received_claps_key = (prev_session_index, &transaction_hash, &clap_unique_hash);
|
||||||
let curr_received_claps = ReceivedClaps::<T>::get(&curr_received_claps_key).into_inner();
|
let curr_received_claps_key = (curr_session_index, &transaction_hash, &clap_unique_hash);
|
||||||
|
|
||||||
|
let prev_received_claps = ReceivedClaps::<T>::get(&prev_received_claps_key)
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|auth_index| prev_authorities.get(auth_index as usize))
|
||||||
|
.cloned()
|
||||||
|
.collect::<BTreeSet<T::AuthorityId>>();
|
||||||
|
|
||||||
|
let curr_received_claps = ReceivedClaps::<T>::get(&curr_received_claps_key)
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|auth_index| curr_authorities.get(auth_index as usize))
|
||||||
|
.cloned()
|
||||||
|
.collect::<BTreeSet<T::AuthorityId>>();
|
||||||
|
|
||||||
|
let disabled_authorites = ClapsInSession::<T>::get(&prev_session_index)
|
||||||
|
.values()
|
||||||
|
.filter(|info| info.disabled)
|
||||||
|
.count();
|
||||||
|
|
||||||
|
let active_authorities = prev_authorities.len().saturating_sub(disabled_authorites);
|
||||||
|
|
||||||
let summary_authority_claps_length = curr_received_claps
|
let summary_authority_claps_length = curr_received_claps
|
||||||
.difference(&prev_received_claps)
|
.symmetric_difference(&prev_received_claps)
|
||||||
.filter_map(|&index| {
|
.count();
|
||||||
curr_authorities
|
|
||||||
.get(index as usize)
|
|
||||||
.map(|curr_authority| {
|
|
||||||
prev_authorities
|
|
||||||
.iter()
|
|
||||||
.position(|prev_authority| curr_authority == prev_authority)
|
|
||||||
})
|
|
||||||
.flatten()
|
|
||||||
})
|
|
||||||
.count()
|
|
||||||
.saturating_add(curr_received_claps.len());
|
|
||||||
|
|
||||||
let clap = Clap {
|
let clap = Clap {
|
||||||
authority_index: Default::default(),
|
authority_index: Default::default(),
|
||||||
@ -651,7 +660,7 @@ impl<T: Config> Pallet<T> {
|
|||||||
|
|
||||||
let enough_authorities = Perbill::from_rational(
|
let enough_authorities = Perbill::from_rational(
|
||||||
summary_authority_claps_length as u32,
|
summary_authority_claps_length as u32,
|
||||||
Authorities::<T>::get(prev_session_index).len() as u32,
|
active_authorities as u32,
|
||||||
) > Perbill::from_percent(T::ApplauseThreshold::get());
|
) > Perbill::from_percent(T::ApplauseThreshold::get());
|
||||||
|
|
||||||
ensure!(enough_authorities, Error::<T>::NotEnoughClaps);
|
ensure!(enough_authorities, Error::<T>::NotEnoughClaps);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user