forked from ghostchain/ghost-node
		
	make sure that disabled validator will not be checked with is_good_actor
Signed-off-by: Uncle Stinky <uncle.stinky@ghostchain.io>
This commit is contained in:
		
							parent
							
								
									9bdb7b5d5c
								
							
						
					
					
						commit
						b969081cbf
					
				@ -1,6 +1,6 @@
 | 
				
			|||||||
[package]
 | 
					[package]
 | 
				
			||||||
name = "ghost-slow-clap"
 | 
					name = "ghost-slow-clap"
 | 
				
			||||||
version = "0.3.37"
 | 
					version = "0.3.38"
 | 
				
			||||||
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
 | 
				
			||||||
 | 
				
			|||||||
@ -969,9 +969,9 @@ impl<T: Config> Pallet<T> {
 | 
				
			|||||||
        authorities_len: usize,
 | 
					        authorities_len: usize,
 | 
				
			||||||
    ) -> u32 {
 | 
					    ) -> u32 {
 | 
				
			||||||
        let mut claps_in_session = (0..authorities_len)
 | 
					        let mut claps_in_session = (0..authorities_len)
 | 
				
			||||||
            .filter_map(|index| {
 | 
					            .filter_map(|authority_index| {
 | 
				
			||||||
                let clap_info = actual_claps_in_session
 | 
					                let clap_info = actual_claps_in_session
 | 
				
			||||||
                    .get(&(index as u32))
 | 
					                    .get(&(authority_index as AuthIndex))
 | 
				
			||||||
                    .copied()
 | 
					                    .copied()
 | 
				
			||||||
                    .unwrap_or_default();
 | 
					                    .unwrap_or_default();
 | 
				
			||||||
                (!clap_info.disabled).then(|| clap_info.claps)
 | 
					                (!clap_info.disabled).then(|| clap_info.claps)
 | 
				
			||||||
@ -996,17 +996,21 @@ impl<T: Config> Pallet<T> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    fn is_good_actor(
 | 
					    fn is_good_actor(
 | 
				
			||||||
        authority_index: usize,
 | 
					        authority_index: usize,
 | 
				
			||||||
        session_index: SessionIndex,
 | 
					 | 
				
			||||||
        median_claps: u32,
 | 
					        median_claps: u32,
 | 
				
			||||||
 | 
					        claps_in_session: &BTreeMap<AuthIndex, SessionAuthorityInfo>,
 | 
				
			||||||
    ) -> bool {
 | 
					    ) -> bool {
 | 
				
			||||||
        if median_claps == 0 {
 | 
					        if median_claps == 0 {
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let number_of_claps = ClapsInSession::<T>::get(session_index)
 | 
					        let number_of_claps = claps_in_session
 | 
				
			||||||
            .entry(authority_index as AuthIndex)
 | 
					            .get(&(authority_index as AuthIndex))
 | 
				
			||||||
            .or_default()
 | 
					            .copied()
 | 
				
			||||||
            .claps;
 | 
					            .map(|info| match info.disabled {
 | 
				
			||||||
 | 
					                true => median_claps,
 | 
				
			||||||
 | 
					                false => info.claps,
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					            .unwrap_or_default();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let authority_deviation = if number_of_claps < median_claps {
 | 
					        let authority_deviation = if number_of_claps < median_claps {
 | 
				
			||||||
            Perbill::from_rational(median_claps - number_of_claps, median_claps)
 | 
					            Perbill::from_rational(median_claps - number_of_claps, median_claps)
 | 
				
			||||||
@ -1089,14 +1093,14 @@ impl<T: Config> OneSessionHandler<T::AccountId> for Pallet<T> {
 | 
				
			|||||||
        let session_index = T::ValidatorSet::session_index();
 | 
					        let session_index = T::ValidatorSet::session_index();
 | 
				
			||||||
        let validators = T::ValidatorSet::validators();
 | 
					        let validators = T::ValidatorSet::validators();
 | 
				
			||||||
        let authorities_len = Authorities::<T>::get(&session_index).len();
 | 
					        let authorities_len = Authorities::<T>::get(&session_index).len();
 | 
				
			||||||
        let actual_claps_in_session = ClapsInSession::<T>::get(&session_index);
 | 
					        let claps_in_session = ClapsInSession::<T>::get(&session_index);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let median_claps = Self::calculate_median_claps(&actual_claps_in_session, authorities_len);
 | 
					        let median_claps = Self::calculate_median_claps(&claps_in_session, authorities_len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let offenders = validators
 | 
					        let offenders = validators
 | 
				
			||||||
            .into_iter()
 | 
					            .into_iter()
 | 
				
			||||||
            .enumerate()
 | 
					            .enumerate()
 | 
				
			||||||
            .filter(|(index, _)| !Self::is_good_actor(*index, session_index, median_claps))
 | 
					            .filter(|(index, _)| !Self::is_good_actor(*index, median_claps, &claps_in_session))
 | 
				
			||||||
            .filter_map(|(_, id)| {
 | 
					            .filter_map(|(_, id)| {
 | 
				
			||||||
                <T::ValidatorSet as ValidatorSetWithIdentification<T::AccountId>>::IdentificationOf::convert(
 | 
					                <T::ValidatorSet as ValidatorSetWithIdentification<T::AccountId>>::IdentificationOf::convert(
 | 
				
			||||||
                    id.clone(),
 | 
					                    id.clone(),
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user