mirror of
https://git.ghostchain.io/proxmio/ghost-node.git
synced 2025-12-27 03:09:56 +00:00
ability to do self applause if claps received
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
@@ -323,6 +323,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
NotEnoughClaps,
|
||||
NotAnAuthority,
|
||||
ClapForWrongSession,
|
||||
CurrentValidatorIsDisabled,
|
||||
@@ -404,13 +405,23 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[pallet::call_index(1)]
|
||||
#[pallet::weight(T::WeightInfo::applause())]
|
||||
pub fn applause(
|
||||
#[pallet::weight(T::WeightInfo::self_applause())]
|
||||
pub fn self_applause(
|
||||
origin: OriginFor<T>,
|
||||
_clap: Clap<T::AccountId, NetworkIdOf<T>, BalanceOf<T>>,
|
||||
network_id: NetworkIdOf<T>,
|
||||
session_index: SessionIndex,
|
||||
transaction_hash: H256,
|
||||
receiver: T::AccountId,
|
||||
amount: BalanceOf<T>,
|
||||
) -> DispatchResult {
|
||||
let _ = ensure_signed(origin)?;
|
||||
Ok(())
|
||||
Self::applause_if_posible(
|
||||
network_id,
|
||||
session_index,
|
||||
transaction_hash,
|
||||
receiver,
|
||||
amount,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -598,6 +609,38 @@ impl<T: Config> Pallet<T> {
|
||||
})
|
||||
}
|
||||
|
||||
fn applause_if_posible(
|
||||
network_id: NetworkIdOf<T>,
|
||||
session_index: SessionIndex,
|
||||
transaction_hash: H256,
|
||||
receiver: T::AccountId,
|
||||
amount: BalanceOf<T>,
|
||||
) -> DispatchResult{
|
||||
let clap_unique_hash = Self::generate_unique_hash(&receiver, &amount, &network_id);
|
||||
let received_claps_key = (session_index, &transaction_hash, &clap_unique_hash);
|
||||
|
||||
let clap = Clap {
|
||||
authority_index: Default::default(),
|
||||
block_number: Default::default(),
|
||||
removed: false,
|
||||
session_index,
|
||||
network_id,
|
||||
receiver,
|
||||
amount,
|
||||
transaction_hash,
|
||||
};
|
||||
|
||||
let enough_authorities = Perbill::from_rational(
|
||||
ReceivedClaps::<T>::get(&received_claps_key).len() as u32,
|
||||
Authorities::<T>::get().len() as u32,
|
||||
) > Perbill::from_percent(T::ApplauseThreshold::get());
|
||||
|
||||
ensure!(enough_authorities, Error::<T>::NotEnoughClaps);
|
||||
Self::try_applause(&clap, &received_claps_key)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn start_slow_clapping(
|
||||
block_number: BlockNumberFor<T>,
|
||||
networks_len: usize,
|
||||
@@ -914,6 +957,11 @@ impl<T: Config> Pallet<T> {
|
||||
.expect("more than the maximum number of authorities");
|
||||
Authorities::<T>::put(bounded_authorities);
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
fn trigger_nullification_for_benchmark() {
|
||||
T::NetworkDataHandler::trigger_nullification();
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> sp_runtime::BoundToRuntimeAppPublic for Pallet<T> {
|
||||
|
||||
Reference in New Issue
Block a user