From 0d796420f2843f27b8b7bdaf70ba3a74431f3a3a Mon Sep 17 00:00:00 2001 From: Uncle Stinky Date: Thu, 30 Jan 2025 15:12:55 +0300 Subject: [PATCH] fix incorrect definition of good actor Signed-off-by: Uncle Stinky --- Cargo.lock | 2 +- pallets/slow-clap/Cargo.toml | 2 +- pallets/slow-clap/src/lib.rs | 12 +++++++++--- pallets/slow-clap/src/tests.rs | 1 - 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 20babe6..e53af05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3832,7 +3832,7 @@ dependencies = [ [[package]] name = "ghost-slow-clap" -version = "0.3.14" +version = "0.3.15" dependencies = [ "frame-benchmarking", "frame-support", diff --git a/pallets/slow-clap/Cargo.toml b/pallets/slow-clap/Cargo.toml index 1947232..3e88662 100755 --- a/pallets/slow-clap/Cargo.toml +++ b/pallets/slow-clap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-slow-clap" -version = "0.3.14" +version = "0.3.15" 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 baaabf5..a9d996e 100755 --- a/pallets/slow-clap/src/lib.rs +++ b/pallets/slow-clap/src/lib.rs @@ -1162,16 +1162,22 @@ impl Pallet { session_index: SessionIndex, average_claps: u32, ) -> bool { + if average_claps == 0 { + return true; + } + let claps_in_session = AuthorityInfoInSession::::get(session_index); match claps_in_session.get(authority_index) { Some(clap_in_session) => { let number_of_claps = &clap_in_session.actions; let authority_deviation = if *number_of_claps < average_claps { - Perbill::from_rational(*number_of_claps, average_claps) - } else { Perbill::from_rational(average_claps, *number_of_claps) }; + Perbill::from_rational(average_claps - *number_of_claps, average_claps) + } else { + Perbill::from_rational(*number_of_claps - average_claps, average_claps) + }; authority_deviation < Perbill::from_percent(T::OffenceThreshold::get()) }, - _ => false, + None => false, } } diff --git a/pallets/slow-clap/src/tests.rs b/pallets/slow-clap/src/tests.rs index 5af06d6..4eca1eb 100644 --- a/pallets/slow-clap/src/tests.rs +++ b/pallets/slow-clap/src/tests.rs @@ -35,7 +35,6 @@ fn prepare_companion(amount: u64) -> Companion, BalanceOf