From ddd3a42564ca914135d572e1cdec795e61526867 Mon Sep 17 00:00:00 2001 From: Uncle Stretch Date: Tue, 9 Dec 2025 17:23:08 +0300 Subject: [PATCH] new slashing function for block commitment offence Signed-off-by: Uncle Stretch --- Cargo.lock | 2 +- pallets/slow-clap/Cargo.toml | 2 +- pallets/slow-clap/src/lib.rs | 7 +++++-- pallets/slow-clap/src/tests.rs | 11 ++++++++--- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b71dace..efb6db3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3837,7 +3837,7 @@ dependencies = [ [[package]] name = "ghost-slow-clap" -version = "0.4.8" +version = "0.4.9" dependencies = [ "frame-benchmarking", "frame-support", diff --git a/pallets/slow-clap/Cargo.toml b/pallets/slow-clap/Cargo.toml index ba48845..9bb6e9c 100644 --- a/pallets/slow-clap/Cargo.toml +++ b/pallets/slow-clap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ghost-slow-clap" -version = "0.4.9" +version = "0.4.10" 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 7a73ca8..8efd314 100644 --- a/pallets/slow-clap/src/lib.rs +++ b/pallets/slow-clap/src/lib.rs @@ -1398,8 +1398,11 @@ impl Offence for SlowClapOffence { missed_percent.saturating_mul(Perbill::from_rational(1, offenders_count)) } OffenceType::CommitmentOffence => offenders_count - .checked_sub(self.validator_set_count / 10 + 1) - .map(|threshold| Perbill::from_rational(3 * threshold, self.validator_set_count)) + .checked_sub(Perbill::from_percent(9).mul_ceil(self.validator_set_count)) + .map(|threshold| { + Perbill::from_rational(threshold.saturating_mul(4), self.validator_set_count) + .square() + }) .unwrap_or_default(), } } diff --git a/pallets/slow-clap/src/tests.rs b/pallets/slow-clap/src/tests.rs index 97b7ce5..6f3d1db 100644 --- a/pallets/slow-clap/src/tests.rs +++ b/pallets/slow-clap/src/tests.rs @@ -40,16 +40,21 @@ fn should_calculate_throttling_slash_function_correctly() { assert_eq!(dummy_offence.slash_fraction(5), Perbill::zero()); assert_eq!( dummy_offence.slash_fraction(15), - Perbill::from_parts(120_000_000) + Perbill::from_parts(57_600_000) ); assert_eq!( dummy_offence.slash_fraction(20), - Perbill::from_parts(270_000_000) + Perbill::from_parts(193_600_000) + ); + assert_eq!( + dummy_offence.slash_fraction(25), + Perbill::from_parts(409_600_000) ); assert_eq!( dummy_offence.slash_fraction(30), - Perbill::from_parts(570_000_000) + Perbill::from_parts(705_600_000) ); + assert_eq!(dummy_offence.slash_fraction(50), Perbill::one()); } #[test]