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

Benchmarks for offences pallet. #5851

Merged
merged 23 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from 10 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
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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this intentional (or a result of debugging)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional. Using forbid may cause issues with:

  • Quick development cycle
  • Build randomly breaking on rustc upgrades

We did try that in the past, but it was doing more harm than good.


use pallet_timestamp;

Expand Down Expand Up @@ -267,19 +267,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
2 changes: 1 addition & 1 deletion frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ decl_module! {
/// - Contains a limited number of reads and writes.
/// # </weight>
#[weight = T::DbWeight::get().reads_writes(1, 1) + 100_000_000]
fn set_balance(
pub fn set_balance(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just started reviewing, but you shouldn't need to make this pub. You can instead call make_free_balance_be which is part of the currency trait.

origin,
who: <T::Lookup as StaticLookup>::Source,
#[compact] new_free: T::Balance,
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
33 changes: 22 additions & 11 deletions frame/offences/benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,42 @@ 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", 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-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",
]
Loading