Skip to content

Commit

Permalink
fix: test to pass CI
Browse files Browse the repository at this point in the history
update: more reasonable slash fraction
  • Loading branch information
AurevoirXavier committed Dec 26, 2019
1 parent b4c245e commit 327553c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions srml/im-online/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use rstd::convert::TryInto;
use rstd::prelude::*;
use session::historical::IdentificationTuple;
use sr_primitives::{
traits::{Convert, Member, Printable},
traits::{Convert, Member, Printable, Saturating},
transaction_validity::{InvalidTransaction, TransactionPriority, TransactionValidity, ValidTransaction},
Perbill, RuntimeDebug,
};
Expand Down Expand Up @@ -626,7 +626,9 @@ impl<Offender: Clone> Offence<Offender> for UnresponsivenessOffence<Offender> {
self.session_index
}

fn slash_fraction(_offenders: u32, _validator_set_count: u32) -> Perbill {
Perbill::from_percent(5)
fn slash_fraction(offenders: u32, validator_set_count: u32) -> Perbill {
// the formula is min((3 * max((k - 1), 1)) / n, 1) * 0.05
let x = Perbill::from_rational_approximation(3 * (offenders - 1).max(1), validator_set_count);
x.saturating_mul(Perbill::from_percent(5))
}
}
2 changes: 1 addition & 1 deletion srml/im-online/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ parameter_types! {
impl session::Trait for Runtime {
type ShouldEndSession = session::PeriodicSessions<Period, Offset>;
type OnSessionEnding = session::historical::NoteHistoricalRoot<Runtime, TestOnSessionEnding>;
type SessionHandler = (ImOnline);
type SessionHandler = (ImOnline,);
type ValidatorId = u64;
type ValidatorIdOf = ConvertInto;
type Keys = UintAuthorityId;
Expand Down
5 changes: 4 additions & 1 deletion srml/im-online/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ use support::{assert_noop, dispatch};
#[test]
fn test_unresponsiveness_slash_fraction() {
// A single case of unresponsiveness is not slashed.
assert_eq!(UnresponsivenessOffence::<()>::slash_fraction(1, 50), Perbill::zero());
assert_eq!(
UnresponsivenessOffence::<()>::slash_fraction(1, 50),
Perbill::from_parts(3000000), // 0.3%
);

assert_eq!(
UnresponsivenessOffence::<()>::slash_fraction(3, 50),
Expand Down

0 comments on commit 327553c

Please sign in to comment.