Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Benchmarks for offences pallet. (#5851)
Browse files Browse the repository at this point in the history
* really rough mock runtime

* start to work on offences

* Make sure to start the session.

* Update to latest master.

* Add verify.

* Fix on_initialize benchmark.

* Add grandpa offence.

* Add Babe offence benchmarking.

* Enable babe test.

* Address review grumbles.

* Address review grumbles.

* Address review grumbles part 1/2

* use currency trait

* features

* Check events explicitly.

* Auto-impl tuple converter.

* Removed dead code.

* add test feature flag

* dont use std

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
  • Loading branch information
tomusdrw and shawntabrizi authored May 6, 2020
1 parent 31899a4 commit 80e4417
Show file tree
Hide file tree
Showing 8 changed files with 556 additions and 74 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! from VRF outputs and manages epoch transitions.
#![cfg_attr(not(feature = "std"), no_std)]
#![forbid(unused_must_use, unsafe_code, unused_variables, unused_must_use)]
#![warn(unused_must_use, unsafe_code, unused_variables, unused_must_use)]

use pallet_timestamp;

Expand Down Expand Up @@ -268,19 +268,18 @@ impl<T: Trait> pallet_session::ShouldEndSession<T::BlockNumber> for Module<T> {
}
}

// TODO [slashing]: @marcio use this, remove the dead_code annotation.
/// A BABE equivocation offence report.
///
/// When a validator released two or more blocks at the same slot.
struct BabeEquivocationOffence<FullIdentification> {
pub struct BabeEquivocationOffence<FullIdentification> {
/// A babe slot number in which this incident happened.
slot: u64,
pub slot: u64,
/// The session index in which the incident happened.
session_index: SessionIndex,
pub session_index: SessionIndex,
/// The size of the validator set at the time of the offence.
validator_set_count: u32,
pub validator_set_count: u32,
/// The authority that produced the equivocation.
offender: FullIdentification,
pub offender: FullIdentification,
}

impl<FullIdentification: Clone> Offence<FullIdentification> for BabeEquivocationOffence<FullIdentification> {
Expand Down
19 changes: 10 additions & 9 deletions frame/grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,23 +456,24 @@ impl<T: Trait> pallet_finality_tracker::OnFinalizationStalled<T::BlockNumber> fo

/// A round number and set id which point on the time of an offence.
#[derive(Copy, Clone, PartialOrd, Ord, Eq, PartialEq, Encode, Decode)]
struct GrandpaTimeSlot {
pub struct GrandpaTimeSlot {
// The order of these matters for `derive(Ord)`.
set_id: SetId,
round: RoundNumber,
/// Grandpa Set ID.
pub set_id: SetId,
/// Round number.
pub round: RoundNumber,
}

// TODO [slashing]: Integrate this.
/// A grandpa equivocation offence report.
struct GrandpaEquivocationOffence<FullIdentification> {
pub struct GrandpaEquivocationOffence<FullIdentification> {
/// Time slot at which this incident happened.
time_slot: GrandpaTimeSlot,
pub time_slot: GrandpaTimeSlot,
/// The session index in which the incident happened.
session_index: SessionIndex,
pub session_index: SessionIndex,
/// The size of the validator set at the time of the offence.
validator_set_count: u32,
pub validator_set_count: u32,
/// The authority which produced this equivocation.
offender: FullIdentification,
pub offender: FullIdentification,
}

impl<FullIdentification: Clone> Offence<FullIdentification> for GrandpaEquivocationOffence<FullIdentification> {
Expand Down
35 changes: 24 additions & 11 deletions frame/offences/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,44 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false }

sp-std = { version = "2.0.0-dev", default-features = false, path = "../../../primitives/std" }
sp-staking = { version = "2.0.0-dev", default-features = false, path = "../../../primitives/staking" }
sp-runtime = { version = "2.0.0-dev", default-features = false, path = "../../../primitives/runtime" }
frame-benchmarking = { version = "2.0.0-dev", default-features = false, path = "../../benchmarking" }
frame-system = { version = "2.0.0-dev", default-features = false, path = "../../system" }
frame-support = { version = "2.0.0-dev", default-features = false, path = "../../support" }
frame-system = { version = "2.0.0-dev", default-features = false, path = "../../system" }
pallet-babe = { version = "2.0.0-dev", default-features = false, path = "../../babe" }
pallet-balances = { version = "2.0.0-dev", default-features = false, path = "../../balances" }
pallet-grandpa = { version = "2.0.0-dev", default-features = false, path = "../../grandpa" }
pallet-im-online = { version = "2.0.0-dev", default-features = false, path = "../../im-online" }
pallet-offences = { version = "2.0.0-dev", default-features = false, features = ["runtime-benchmarks"], path = "../../offences" }
pallet-staking = { version = "2.0.0-dev", default-features = false, features = ["runtime-benchmarks"], path = "../../staking" }
pallet-session = { version = "2.0.0-dev", default-features = false, path = "../../session" }
pallet-staking = { version = "2.0.0-dev", default-features = false, features = ["runtime-benchmarks"], path = "../../staking" }
sp-io = { path = "../../../primitives/io", default-features = false, version = "2.0.0-dev"}
sp-runtime = { version = "2.0.0-dev", default-features = false, path = "../../../primitives/runtime" }
sp-staking = { version = "2.0.0-dev", default-features = false, path = "../../../primitives/staking" }
sp-std = { version = "2.0.0-dev", default-features = false, path = "../../../primitives/std" }

[dev-dependencies]
codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] }
pallet-staking-reward-curve = { version = "2.0.0-dev", path = "../../staking/reward-curve" }
pallet-timestamp = { version = "2.0.0-dev", path = "../../timestamp" }
serde = { version = "1.0.101" }
sp-core = { version = "2.0.0-dev", path = "../../../primitives/core" }
sp-io ={ path = "../../../primitives/io", version = "2.0.0-dev"}

[features]
default = ["std"]
std = [
"sp-runtime/std",
"sp-std/std",
"sp-staking/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"pallet-offences/std",
"pallet-babe/std",
"pallet-balances/std",
"pallet-grandpa/std",
"pallet-im-online/std",
"pallet-staking/std",
"pallet-offences/std",
"pallet-session/std",
"pallet-staking/std",
"sp-runtime/std",
"sp-staking/std",
"sp-std/std",
"sp-io/std",
]
Loading

0 comments on commit 80e4417

Please sign in to comment.