-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmarking & weights for ddc-nodes (#143)
1. add benchmarking 2. add weights
- Loading branch information
Showing
10 changed files
with
197 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//! DdcStaking pallet benchmarking. | ||
|
||
use super::*; | ||
use crate::{cdn_node::CDNNodeProps, Pallet as DdcNodes}; | ||
use ddc_primitives::CDNNodePubKey; | ||
use testing_utils::*; | ||
|
||
use sp_std::prelude::*; | ||
|
||
pub use frame_benchmarking::{ | ||
account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller, | ||
}; | ||
use frame_system::RawOrigin; | ||
|
||
const USER_SEED: u32 = 999666; | ||
|
||
benchmarks! { | ||
create_node { | ||
let (user, node, cdn_node_params, _) = create_user_and_config::<T>("user", USER_SEED); | ||
|
||
whitelist_account!(user); | ||
}: _(RawOrigin::Signed(user.clone()), node, cdn_node_params) | ||
verify { | ||
assert!(CDNNodes::<T>::contains_key(CDNNodePubKey::new([0; 32]))); | ||
} | ||
|
||
delete_node { | ||
let (user, node, cdn_node_params, _) = create_user_and_config::<T>("user", USER_SEED); | ||
|
||
DdcNodes::<T>::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), cdn_node_params)?; | ||
|
||
whitelist_account!(user); | ||
}: _(RawOrigin::Signed(user.clone()), node) | ||
verify { | ||
assert!(!CDNNodes::<T>::contains_key(CDNNodePubKey::new([0; 32]))); | ||
} | ||
|
||
set_node_params { | ||
let (user, node, cdn_node_params, cdn_node_params_new) = create_user_and_config::<T>("user", USER_SEED); | ||
|
||
DdcNodes::<T>::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), cdn_node_params)?; | ||
|
||
whitelist_account!(user); | ||
}: _(RawOrigin::Signed(user.clone()), node, cdn_node_params_new) | ||
verify { | ||
assert_eq!(CDNNodes::<T>::try_get( | ||
CDNNodePubKey::new([0; 32])).unwrap().props, | ||
CDNNodeProps { | ||
host: vec![2u8, 255].try_into().unwrap(), | ||
http_port: 45000u16, | ||
grpc_port: 55000u16, | ||
p2p_port: 65000u16, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//! Testing utils for ddc-staking. | ||
|
||
use crate::{cdn_node::CDNNodeParams, node::NodeParams, Config, NodePubKey}; | ||
use ddc_primitives::CDNNodePubKey; | ||
use frame_benchmarking::account; | ||
use sp_std::vec; | ||
|
||
const SEED: u32 = 0; | ||
|
||
/// Grab a funded user. | ||
pub fn create_user_and_config<T: Config>( | ||
string: &'static str, | ||
n: u32, | ||
) -> (T::AccountId, NodePubKey, NodeParams, NodeParams) { | ||
let user = account(string, n, SEED); | ||
let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); | ||
let cdn_node_params = NodeParams::CDNParams(CDNNodeParams { | ||
host: vec![1u8, 255], | ||
http_port: 35000u16, | ||
grpc_port: 25000u16, | ||
p2p_port: 15000u16, | ||
}); | ||
|
||
let cdn_node_params_new = NodeParams::CDNParams(CDNNodeParams { | ||
host: vec![2u8, 255], | ||
http_port: 45000u16, | ||
grpc_port: 55000u16, | ||
p2p_port: 65000u16, | ||
}); | ||
(user, node, cdn_node_params, cdn_node_params_new) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
//! Autogenerated weights for `pallet_ddc_nodes` | ||
//! | ||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev | ||
//! DATE: 2023-11-16, STEPS: `200`, REPEAT: 1000, LOW RANGE: `[]`, HIGH RANGE: `[]` | ||
//! HOSTNAME: `Raids-MBP-2`, CPU: `<UNKNOWN>` | ||
//! EXECUTION: None, WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 | ||
|
||
// Executed Command: | ||
// ./target/release/cere | ||
// benchmark | ||
// pallet | ||
// --chain | ||
// dev | ||
// --pallet | ||
// pallet_ddc_nodes | ||
// --extrinsic | ||
// * | ||
// --steps | ||
// 200 | ||
// --repeat | ||
// 1000 | ||
// --output | ||
// pallets/ddc-nodes/src/weights.rs | ||
|
||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
#![allow(unused_parens)] | ||
#![allow(unused_imports)] | ||
|
||
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; | ||
use sp_std::marker::PhantomData; | ||
|
||
/// Weight functions needed for pallet_ddc_nodes. | ||
pub trait WeightInfo { | ||
fn create_node() -> Weight; | ||
fn delete_node() -> Weight; | ||
fn set_node_params() -> Weight; | ||
} | ||
|
||
/// Weights for pallet_ddc_nodes. | ||
pub struct SubstrateWeight<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { | ||
// Storage: DdcNodes CDNNodes (r:1 w:1) | ||
fn create_node() -> Weight { | ||
Weight::from_ref_time(12_000_000u64) | ||
.saturating_add(T::DbWeight::get().reads(1u64)) | ||
.saturating_add(T::DbWeight::get().writes(1u64)) | ||
} | ||
// Storage: DdcNodes CDNNodes (r:1 w:1) | ||
fn delete_node() -> Weight { | ||
Weight::from_ref_time(14_000_000u64) | ||
.saturating_add(T::DbWeight::get().reads(1u64)) | ||
.saturating_add(T::DbWeight::get().writes(1u64)) | ||
} | ||
// Storage: DdcNodes CDNNodes (r:1 w:1) | ||
fn set_node_params() -> Weight { | ||
Weight::from_ref_time(15_000_000u64) | ||
.saturating_add(T::DbWeight::get().reads(1u64)) | ||
.saturating_add(T::DbWeight::get().writes(1u64)) | ||
} | ||
} | ||
|
||
// For backwards compatibility and tests | ||
impl WeightInfo for () { | ||
// Storage: DdcNodes CDNNodes (r:1 w:1) | ||
fn create_node() -> Weight { | ||
Weight::from_ref_time(12_000_000u64) | ||
.saturating_add(RocksDbWeight::get().reads(1u64)) | ||
.saturating_add(RocksDbWeight::get().writes(1u64)) | ||
} | ||
// Storage: DdcNodes CDNNodes (r:1 w:1) | ||
fn delete_node() -> Weight { | ||
Weight::from_ref_time(14_000_000u64) | ||
.saturating_add(RocksDbWeight::get().reads(1u64)) | ||
.saturating_add(RocksDbWeight::get().writes(1u64)) | ||
} | ||
// Storage: DdcNodes CDNNodes (r:1 w:1) | ||
fn set_node_params() -> Weight { | ||
Weight::from_ref_time(15_000_000u64) | ||
.saturating_add(RocksDbWeight::get().reads(1u64)) | ||
.saturating_add(RocksDbWeight::get().writes(1u64)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters