diff --git a/frame/babe/src/lib.rs b/frame/babe/src/lib.rs index 5db863f7be5dd..e7693c35f75ff 100644 --- a/frame/babe/src/lib.rs +++ b/frame/babe/src/lib.rs @@ -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::()] fn report_equivocation( origin, equivocation_proof: EquivocationProof, @@ -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::()] fn report_equivocation_unsigned( origin, equivocation_proof: EquivocationProof, @@ -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() -> 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 200 nominators + .saturating_add(T::DbWeight::get().reads(14 + 3 * 200)) + .saturating_add(T::DbWeight::get().writes(10 + 3 * 200)) + } +} + impl RandomnessT<::Hash> for Module { /// 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