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

Commit

Permalink
babe: add weights based on benchmark results
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilva committed Jul 1, 2020
1 parent 15b1000 commit eb047f0
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ decl_module! {
/// the equivocation proof and validate the given key ownership proof
/// against the extracted offender. If both are valid, the offence will
/// be reported.
#[weight = 0]
#[weight = weight::weight_for_report_equivocation::<T>()]
fn report_equivocation(
origin,
equivocation_proof: EquivocationProof<T::Header>,
Expand All @@ -278,7 +278,7 @@ decl_module! {
/// block authors will call it (validated in `ValidateUnsigned`), as such
/// if the block author is defined it will be defined as the equivocation
/// reporter.
#[weight = 0]
#[weight = weight::weight_for_report_equivocation::<T>()]
fn report_equivocation_unsigned(
origin,
equivocation_proof: EquivocationProof<T::Header>,
Expand All @@ -295,6 +295,27 @@ decl_module! {
}
}

mod weight {
use frame_support::{
traits::Get,
weights::{constants::WEIGHT_PER_MICROS, Weight},
};

pub fn weight_for_report_equivocation<T: super::Trait>() -> Weight {
// checking membership proof
(30 * WEIGHT_PER_MICROS)
.saturating_add(T::DbWeight::get().reads(5))
// check equivocation proof
.saturating_add(130 * WEIGHT_PER_MICROS)
// report offence
.saturating_add(135 * WEIGHT_PER_MICROS)
// worst case we are considering is that the given offender
// is backed by 100 nominators
.saturating_add(T::DbWeight::get().reads(14 + 3 * 100))
.saturating_add(T::DbWeight::get().writes(10 + 3 * 100))
}
}

impl<T: Trait> RandomnessT<<T as frame_system::Trait>::Hash> for Module<T> {
/// Some BABE blocks have VRF outputs where the block producer has exactly one bit of influence,
/// either they make the block or they do not make the block and thus someone else makes the
Expand Down

0 comments on commit eb047f0

Please sign in to comment.