Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions core/ethash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,31 +330,31 @@ mod tests {
);
}

#[test]
fn hashimoto_should_work_on_ropsten() {
type DAG = LightDAG<EthereumPatch>;
let light_dag = DAG::new(0x672884.into());
let partial_header_hash = H256::from(hex!("9cb3d16b788bfc7f2569db2d1fedb5b1e9633acfe84a4eca44a9fa50979a9887"));
let mixh = light_dag
.hashimoto(partial_header_hash, H64::from(hex!("9348d06003756cff")))
.0;
assert_eq!(
mixh,
H256::from(hex!("e06f0c107dcc91e9e82de0b42d0e22d5c2cfae5209422fda88cff4f810f4bffb"))
);
}

#[test]
fn hashimoto_should_work_on_ropsten_earlier() {
type DAG = LightDAG<EthereumPatch>;
let light_dag = DAG::new(0x11170.into());
let partial_header_hash = H256::from(hex!("bb698ea6e304a7a88a6cd8238f0e766b4f7bf70dc0869bd2e4a76a8e93fffc80"));
let mixh = light_dag
.hashimoto(partial_header_hash, H64::from(hex!("475ddd90b151f305")))
.0;
assert_eq!(
mixh,
H256::from(hex!("341e3bcf01c921963933253e0cf937020db69206f633e31e0d1c959cdd1188f5"))
);
}
// #[test]
// fn hashimoto_should_work_on_ropsten() {
// type DAG = LightDAG<EthereumPatch>;
// let light_dag = DAG::new(0x672884.into());
// let partial_header_hash = H256::from(hex!("9cb3d16b788bfc7f2569db2d1fedb5b1e9633acfe84a4eca44a9fa50979a9887"));
// let mixh = light_dag
// .hashimoto(partial_header_hash, H64::from(hex!("9348d06003756cff")))
// .0;
// assert_eq!(
// mixh,
// H256::from(hex!("e06f0c107dcc91e9e82de0b42d0e22d5c2cfae5209422fda88cff4f810f4bffb"))
// );
// }
//
// #[test]
// fn hashimoto_should_work_on_ropsten_earlier() {
// type DAG = LightDAG<EthereumPatch>;
// let light_dag = DAG::new(0x11170.into());
// let partial_header_hash = H256::from(hex!("bb698ea6e304a7a88a6cd8238f0e766b4f7bf70dc0869bd2e4a76a8e93fffc80"));
// let mixh = light_dag
// .hashimoto(partial_header_hash, H64::from(hex!("475ddd90b151f305")))
// .0;
// assert_eq!(
// mixh,
// H256::from(hex!("341e3bcf01c921963933253e0cf937020db69206f633e31e0d1c959cdd1188f5"))
// );
// }
}
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,);
Comment thread
aurexav marked this conversation as resolved.
type ValidatorId = u64;
type ValidatorIdOf = ConvertInto;
type Keys = UintAuthorityId;
Expand Down
11 changes: 9 additions & 2 deletions srml/im-online/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ 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());
// 1 ~ 2 offline should be punished 0.3%.
assert_eq!(
UnresponsivenessOffence::<()>::slash_fraction(1, 50),
Perbill::from_parts(3000000), // 0.3%
);
assert_eq!(
UnresponsivenessOffence::<()>::slash_fraction(2, 50),
Perbill::from_parts(3000000), // 0.3%
);

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