Skip to content

Commit

Permalink
updated pallet-avn-offence-handler (#351)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Cholakov <icholakov1@gmail.com>
Co-authored-by: Nahu <39748285+nahuseyoum@users.noreply.github.com>
  • Loading branch information
ivan-cholakov and nahuseyoum committed Feb 19, 2024
1 parent 7832ec5 commit 8547462
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 58 deletions.
28 changes: 16 additions & 12 deletions pallets/avn-offence-handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,43 @@ repository = { workspace = true }
rust-version = { workspace = true }

[dependencies]
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
sp-staking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
pallet-session = { default-features = false, features = ["historical"], git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }

sp-avn-common = { default-features = false, path = "../../primitives/avn-common" }
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-staking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
pallet-avn = { default-features = false, path = "../avn" }
pallet-session = { default-features = false, features = ["historical"], git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }

# Optional imports for benchmarking
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36", optional = true }
frame-benchmarking = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", optional = true }

[dev-dependencies]
serde = { version = "1.0.101"}
serde = { version = "1.0.163", default-features = false}
parking_lot = { version = "0.12.0" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-io = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }

[features]
default = ["std"]
std = [
"frame-benchmarking?/std",
"codec/std",
"scale-info/std",
"frame-support/std",
"frame-system/std",
"sp-core/std",
"sp-std/std",
"sp-io/std",
"sp-runtime/std",
"sp-staking/std",
"pallet-session/std",
"pallet-avn/std",
"sp-avn-common/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand Down
57 changes: 26 additions & 31 deletions pallets/avn-offence-handler/src/default_weights.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,39 @@
// This file is part of Substrate.

// Copyright (C) 2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Autogenerated weights for pallet_avn_offence_handler
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-12-08, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `ip-172-31-4-12`, CPU: `AMD EPYC 7R32`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
//! DATE: 2024-02-15, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `ip-172-31-16-102`, CPU: `Intel(R) Xeon(R) Platinum 8275CL CPU @ 3.00GHz`
//! EXECUTION: ``, WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`

// Executed Command:
// ./avn-parachain-collator
// benchmark
// pallet
// --chain
// dev
// --execution=wasm
// --wasm-execution=compiled
// --template
// .maintain/frame-weight-template.hbs
// frame-weight-template.hbs
// --pallet
// pallet_avn-offence-handler
// pallet_avn_offence_handler
// --extrinsic
// *
// --steps
// 50
// --repeat
// 20
// --output
// avn_offence_handler_weights.rs
// avt_offence_handlerweights.rs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;
use core::marker::PhantomData;

/// Weight functions needed for pallet_avn_offence_handler.
pub trait WeightInfo {
Expand All @@ -58,18 +43,28 @@ pub trait WeightInfo {
/// Weights for pallet_avn_offence_handler using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: AvnOffenceHandler SlashingEnabled (r:0 w:1)
/// Storage: `AvnOffenceHandler::SlashingEnabled` (r:0 w:1)
/// Proof: `AvnOffenceHandler::SlashingEnabled` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
fn configure_slashing() -> Weight {
(Weight::from_ref_time(15_281_000))
.saturating_add(T::DbWeight::get().writes(1))
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 8_167_000 picoseconds.
Weight::from_parts(8_564_000, 0)
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

// For backwards compatibility and tests
// For backwards compatibility and tests.
impl WeightInfo for () {
// Storage: AvnOffenceHandler SlashingEnabled (r:0 w:1)
/// Storage: `AvnOffenceHandler::SlashingEnabled` (r:0 w:1)
/// Proof: `AvnOffenceHandler::SlashingEnabled` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`)
fn configure_slashing() -> Weight {
(Weight::from_ref_time(15_281_000))
.saturating_add(RocksDbWeight::get().writes(1))
// Proof Size summary in bytes:
// Measured: `0`
// Estimated: `0`
// Minimum execution time: 8_167_000 picoseconds.
Weight::from_parts(8_564_000, 0)
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}
2 changes: 1 addition & 1 deletion pallets/avn-offence-handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<T: Config> OnOffenceHandler<T::AccountId, IdentificationTuple<T>, Weight> f
_session: SessionIndex,
_disable_strategy: DisableStrategy,
) -> Weight {
let mut consumed_weight: Weight = Weight::from_ref_time(0);
let mut consumed_weight: Weight = Weight::from_parts(0 as u64, 0);
let mut add_db_reads_writes = |reads, writes| {
consumed_weight += T::DbWeight::get().reads_writes(reads, writes);
};
Expand Down
22 changes: 8 additions & 14 deletions pallets/avn-offence-handler/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use crate::{self as avn_offence_handler, *};
use frame_support::{
dispatch::{DispatchError, DispatchResult},
parameter_types,
traits::GenesisBuild,
BasicExternalities,
};
use frame_system as system;
use pallet_session as session;
use sp_core::H256;
use sp_runtime::{
testing::{Header, UintAuthorityId},
testing::UintAuthorityId,
traits::{BlakeTwo256, ConvertInto, IdentityLookup},
BuildStorage
};

use std::cell::RefCell;
Expand All @@ -21,16 +21,11 @@ pub const VALIDATOR_ID_1: u64 = 1;
pub const VALIDATOR_ID_2: u64 = 2;
pub const VALIDATOR_ID_CAN_CAUSE_SLASH_ERROR: u64 = 3;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>;
type Block = frame_system::mocking::MockBlock<TestRuntime>;

frame_support::construct_runtime!(
pub enum TestRuntime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
pub enum TestRuntime {
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
AVN: pallet_avn::{Pallet, Storage, Event},
AvnOffenceHandler: avn_offence_handler::{Pallet, Call, Storage, Event<T>},
Expand Down Expand Up @@ -97,13 +92,12 @@ impl system::Config for TestRuntime {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
Expand Down Expand Up @@ -141,7 +135,7 @@ pub struct ExtBuilder {
impl ExtBuilder {
pub fn build_default() -> Self {
let storage =
frame_system::GenesisConfig::default().build_storage::<TestRuntime>().unwrap();
frame_system::GenesisConfig::<TestRuntime>::default().build_storage().unwrap();
Self { storage }
}

Expand Down Expand Up @@ -191,7 +185,7 @@ impl TestExternalitiesBuilder {
// Build a genesis storage key/value store
pub fn build<R>(self, execute: impl FnOnce() -> R) -> sp_io::TestExternalities {
let storage =
frame_system::GenesisConfig::default().build_storage::<TestRuntime>().unwrap();
frame_system::GenesisConfig::<TestRuntime>::default().build_storage().unwrap();

let mut ext = sp_io::TestExternalities::new(storage);
ext.execute_with(|| {
Expand Down

0 comments on commit 8547462

Please sign in to comment.