From 80a4367399cdc700f2ecfedd77b70013300a5374 Mon Sep 17 00:00:00 2001 From: Raid5594 <52794079+Raid5594@users.noreply.github.com> Date: Mon, 27 Nov 2023 09:48:54 +0100 Subject: [PATCH] provide benchmarking and weights for ddc-staking after changes (#163) - update benchmarking - update weights --------- Co-authored-by: rakanalh --- pallets/ddc-clusters/src/tests.rs | 3 +- pallets/ddc-nodes/src/cdn_node.rs | 12 +- pallets/ddc-nodes/src/lib.rs | 21 +++- pallets/ddc-nodes/src/node.rs | 13 +-- pallets/ddc-nodes/src/storage_node.rs | 13 +-- pallets/ddc-nodes/src/testing_utils.rs | 4 +- pallets/ddc-nodes/src/tests.rs | 3 +- pallets/ddc-staking/src/benchmarking.rs | 21 +++- pallets/ddc-staking/src/lib.rs | 8 +- pallets/ddc-staking/src/mock.rs | 32 ++++- pallets/ddc-staking/src/testing_utils.rs | 90 ++++++++++++-- pallets/ddc-staking/src/weights.rs | 142 +++++++++++++++-------- primitives/src/lib.rs | 25 +++- runtime/cere-dev/src/lib.rs | 2 + traits/src/node.rs | 11 +- 15 files changed, 292 insertions(+), 108 deletions(-) diff --git a/pallets/ddc-clusters/src/tests.rs b/pallets/ddc-clusters/src/tests.rs index ae0b96ae2..97f2a3daf 100644 --- a/pallets/ddc-clusters/src/tests.rs +++ b/pallets/ddc-clusters/src/tests.rs @@ -1,11 +1,10 @@ //! Tests for the module. use super::{mock::*, *}; -use ddc_primitives::{ClusterId, ClusterParams, NodePubKey}; +use ddc_primitives::{CDNNodeParams, ClusterId, ClusterParams, NodeParams, NodePubKey}; use frame_support::{assert_noop, assert_ok, error::BadOrigin}; use frame_system::Config; use hex_literal::hex; -use pallet_ddc_nodes::{CDNNodeParams, NodeParams}; use sp_runtime::{traits::Hash, AccountId32, Perbill}; #[test] diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index eafe6cd27..43c3721f4 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,6 +1,6 @@ -use crate::node::{NodeError, NodeParams, NodeProps, NodeTrait}; +use crate::node::{NodeError, NodeProps, NodeTrait}; use codec::{Decode, Encode}; -use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey, NodeType}; +use ddc_primitives::{CDNNodePubKey, ClusterId, NodeParams, NodePubKey, NodeType}; use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; @@ -28,14 +28,6 @@ pub struct CDNNodeProps { pub p2p_port: u16, } -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct CDNNodeParams { - pub host: Vec, - pub http_port: u16, - pub grpc_port: u16, - pub p2p_port: u16, -} - impl CDNNode { pub fn new( node_pub_key: NodePubKey, diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 59b40e8ed..5bd307596 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -27,9 +27,9 @@ pub mod benchmarking; #[cfg(any(feature = "runtime-benchmarks", test))] pub mod testing_utils; -use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey, StorageNodePubKey}; +use ddc_primitives::{CDNNodePubKey, ClusterId, NodeParams, NodePubKey, StorageNodePubKey}; use ddc_traits::{ - node::{NodeVisitor, NodeVisitorError}, + node::{NodeCreator, NodeVisitor, NodeVisitorError}, staking::StakingVisitor, }; @@ -43,8 +43,8 @@ mod node; mod storage_node; pub use crate::{ - cdn_node::{CDNNode, CDNNodeParams}, - node::{Node, NodeError, NodeParams, NodeTrait}, + cdn_node::CDNNode, + node::{Node, NodeError, NodeTrait}, storage_node::StorageNode, }; @@ -242,4 +242,17 @@ pub mod pallet { Self::get(node_pub_key.clone()).is_ok() } } + + impl NodeCreator for Pallet { + fn create_node( + node_pub_key: NodePubKey, + provider_id: T::AccountId, + node_params: NodeParams, + ) -> DispatchResult { + let node = Node::::new(node_pub_key, provider_id, node_params) + .map_err(Into::>::into)?; + Self::create(node).map_err(Into::>::into)?; + Ok(()) + } + } } diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 042d13be3..ecccdd200 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -1,13 +1,13 @@ #![allow(clippy::needless_lifetimes)] // ToDo use crate::{ - cdn_node::{CDNNode, CDNNodeParams, CDNNodeProps}, + cdn_node::{CDNNode, CDNNodeProps}, pallet::Error, - storage_node::{StorageNode, StorageNodeParams, StorageNodeProps}, + storage_node::{StorageNode, StorageNodeProps}, ClusterId, }; use codec::{Decode, Encode}; -use ddc_primitives::{NodePubKey, NodeType}; +use ddc_primitives::{NodeParams, NodePubKey, NodeType}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; @@ -17,13 +17,6 @@ pub enum Node { CDN(CDNNode), } -// Params fields are always coming from extrinsic input -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub enum NodeParams { - StorageParams(StorageNodeParams), - CDNParams(CDNNodeParams), -} - // Props fields may include internal protocol properties #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeProps { diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 902739771..0749c044e 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,10 +1,9 @@ -use crate::node::{NodeError, NodeParams, NodeProps, NodeTrait}; +use crate::node::{NodeError, NodeProps, NodeTrait}; use codec::{Decode, Encode}; -use ddc_primitives::{ClusterId, NodePubKey, NodeType, StorageNodePubKey}; +use ddc_primitives::{ClusterId, NodeParams, NodePubKey, NodeType, StorageNodePubKey}; use frame_support::{parameter_types, BoundedVec}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; -use sp_std::prelude::Vec; parameter_types! { pub MaxStorageNodeParamsLen: u16 = 2048; @@ -28,14 +27,6 @@ pub struct StorageNodeProps { pub p2p_port: u16, } -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct StorageNodeParams { - pub host: Vec, - pub http_port: u16, - pub grpc_port: u16, - pub p2p_port: u16, -} - impl StorageNode { pub fn new( node_pub_key: NodePubKey, diff --git a/pallets/ddc-nodes/src/testing_utils.rs b/pallets/ddc-nodes/src/testing_utils.rs index 432107e61..8db4dfd35 100644 --- a/pallets/ddc-nodes/src/testing_utils.rs +++ b/pallets/ddc-nodes/src/testing_utils.rs @@ -1,7 +1,7 @@ //! Testing utils for ddc-staking. -use crate::{cdn_node::CDNNodeParams, node::NodeParams, Config, NodePubKey}; -use ddc_primitives::CDNNodePubKey; +use crate::{Config, NodePubKey}; +use ddc_primitives::{CDNNodeParams, CDNNodePubKey, NodeParams}; use frame_benchmarking::account; use sp_std::vec; diff --git a/pallets/ddc-nodes/src/tests.rs b/pallets/ddc-nodes/src/tests.rs index 1c5a80137..ede8e4c64 100644 --- a/pallets/ddc-nodes/src/tests.rs +++ b/pallets/ddc-nodes/src/tests.rs @@ -1,8 +1,7 @@ //! Tests for the module. use super::{mock::*, *}; -use crate::{cdn_node::CDNNodeParams, storage_node::StorageNodeParams}; -use ddc_primitives::NodePubKey; +use ddc_primitives::{CDNNodeParams, NodePubKey, StorageNodeParams}; use frame_support::{assert_noop, assert_ok}; use sp_runtime::AccountId32; diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index 6353e4a5d..a533a6828 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -2,7 +2,7 @@ use super::*; use crate::Pallet as DdcStaking; -use ddc_primitives::{CDNNodePubKey, NodeType}; +use ddc_primitives::{CDNNodeParams, CDNNodePubKey, NodeParams, NodeType, StorageNodePubKey}; use testing_utils::*; use frame_support::traits::Currency; @@ -23,6 +23,16 @@ benchmarks! { let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + let _ = T::NodeCreator::create_node( + node.clone(), + stash.clone(), + NodeParams::CDNParams(CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }) + )?; let amount = T::Currency::minimum_balance() * 10u32.into(); whitelist_account!(stash); }: _(RawOrigin::Signed(stash.clone()), controller_lookup, node.clone(), amount) @@ -65,7 +75,8 @@ benchmarks! { } store { - let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128).saturated_into::>())?; + let node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); + let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(100u128), node_pub_key)?; whitelist_account!(controller); }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) @@ -74,7 +85,8 @@ benchmarks! { } serve { - let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128).saturated_into::>())?; + let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128), node_pub_key)?; whitelist_account!(controller); }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) @@ -86,7 +98,8 @@ benchmarks! { // clean up any existing state. clear_storages_and_cdns::(); - let (cdn_stash, cdn_controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128).saturated_into::>())?; + let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + let (cdn_stash, cdn_controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(10u128), node_pub_key)?; DdcStaking::::serve(RawOrigin::Signed(cdn_controller.clone()).into(), ClusterId::from([1; 20]))?; assert!(CDNs::::contains_key(&cdn_stash)); frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32)); diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index d32059d0f..cdb3c42de 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -32,8 +32,8 @@ use codec::{Decode, Encode, HasCompact}; use core::fmt::Debug; pub use ddc_primitives::{ClusterId, NodePubKey, NodeType}; use ddc_traits::{ - cluster::{ClusterVisitor, ClusterVisitorError}, - node::NodeVisitor, + cluster::{ClusterCreator, ClusterVisitor, ClusterVisitorError}, + node::{NodeCreator, NodeVisitor}, staking::{StakingVisitor, StakingVisitorError}, }; @@ -171,9 +171,13 @@ pub mod pallet { type ClusterVisitor: ClusterVisitor; + type ClusterCreator: ClusterCreator>; + type ClusterManager: ClusterManager; type NodeVisitor: NodeVisitor; + + type NodeCreator: NodeCreator; } /// Map from all locked "stash" accounts to the controller account. diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index 868271f04..37e26b00f 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -4,7 +4,8 @@ use crate::{self as pallet_ddc_staking, *}; use ddc_primitives::{ - CDNNodePubKey, ClusterBondingParams, ClusterFeesParams, ClusterPricingParams, StorageNodePubKey, + CDNNodePubKey, ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterParams, + ClusterPricingParams, NodeParams, NodePubKey, StorageNodePubKey, }; use ddc_traits::{ cluster::{ClusterManager, ClusterManagerError, ClusterVisitor, ClusterVisitorError}, @@ -13,9 +14,11 @@ use ddc_traits::{ use frame_support::{ construct_runtime, + dispatch::DispatchResult, traits::{ConstU32, ConstU64, Everything, GenesisBuild}, weights::constants::RocksDbWeight, }; + use frame_system::mocking::{MockBlock, MockUncheckedExtrinsic}; use lazy_static::lazy_static; use parking_lot::{ReentrantMutex, ReentrantMutexGuard}; @@ -108,11 +111,38 @@ impl crate::pallet::Config for Test { type ClusterVisitor = TestClusterVisitor; type ClusterManager = TestClusterManager; type NodeVisitor = MockNodeVisitor; + type NodeCreator = TestNodeCreator; + type ClusterCreator = TestClusterCreator; } pub(crate) type DdcStakingCall = crate::Call; pub(crate) type TestRuntimeCall = ::RuntimeCall; +pub struct TestNodeCreator; +pub struct TestClusterCreator; pub struct TestClusterVisitor; + +impl NodeCreator for TestNodeCreator { + fn create_node( + _node_pub_key: NodePubKey, + _provider_id: T::AccountId, + _node_params: NodeParams, + ) -> DispatchResult { + Ok(()) + } +} + +impl ClusterCreator for TestClusterCreator { + fn create_new_cluster( + _cluster_id: ClusterId, + _cluster_manager_id: T::AccountId, + _cluster_reserve_id: T::AccountId, + _cluster_params: ClusterParams, + _cluster_gov_params: ClusterGovParams, + ) -> DispatchResult { + Ok(()) + } +} + impl ClusterVisitor for TestClusterVisitor { fn ensure_cluster(_cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { Ok(()) diff --git a/pallets/ddc-staking/src/testing_utils.rs b/pallets/ddc-staking/src/testing_utils.rs index 58e6b656b..277c59334 100644 --- a/pallets/ddc-staking/src/testing_utils.rs +++ b/pallets/ddc-staking/src/testing_utils.rs @@ -1,12 +1,16 @@ //! Testing utils for ddc-staking. use crate::{Pallet as DdcStaking, *}; -use ddc_primitives::CDNNodePubKey; +use ddc_primitives::{ + CDNNodeParams, CDNNodePubKey, ClusterGovParams, ClusterId, ClusterParams, NodeParams, + StorageNodeParams, +}; + use frame_benchmarking::account; use frame_system::RawOrigin; use frame_support::traits::Currency; -use sp_runtime::traits::StaticLookup; +use sp_runtime::{traits::StaticLookup, Perbill}; use sp_std::prelude::*; const SEED: u32 = 0; @@ -36,9 +40,10 @@ pub fn create_funded_user( pub fn create_funded_user_with_balance( string: &'static str, n: u32, - balance: BalanceOf, + balance_factor: u128, ) -> T::AccountId { let user = account(string, n, SEED); + let balance = T::Currency::minimum_balance() * balance_factor.saturated_into::>(); let _ = T::Currency::make_free_balance_be(&user, balance); user } @@ -53,6 +58,17 @@ pub fn create_stash_controller_node( let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + + T::NodeCreator::create_node( + node.clone(), + stash.clone(), + NodeParams::CDNParams(CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }), + )?; let amount = T::Currency::minimum_balance() * (balance_factor / 10).max(1).into(); DdcStaking::::bond( RawOrigin::Signed(stash.clone()).into(), @@ -66,19 +82,73 @@ pub fn create_stash_controller_node( /// Create a stash and controller pair with fixed balance. pub fn create_stash_controller_node_with_balance( n: u32, - balance: crate::BalanceOf, + balance_factor: u128, + node_pub_key: NodePubKey, ) -> Result<(T::AccountId, T::AccountId, NodePubKey), &'static str> { - let stash = create_funded_user_with_balance::("stash", n, balance); - let controller = create_funded_user_with_balance::("controller", n, balance); + let stash = create_funded_user_with_balance::("stash", n, balance_factor); + let controller = create_funded_user_with_balance::("controller", n, balance_factor); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); - let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + + let node_pub = node_pub_key.clone(); + match node_pub_key { + NodePubKey::CDNPubKey(node_pub_key) => { + T::NodeCreator::create_node( + ddc_primitives::NodePubKey::CDNPubKey(node_pub_key), + stash.clone(), + NodeParams::CDNParams(CDNNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }), + )?; + }, + NodePubKey::StoragePubKey(node_pub_key) => { + T::NodeCreator::create_node( + NodePubKey::StoragePubKey(node_pub_key), + stash.clone(), + NodeParams::StorageParams(StorageNodeParams { + host: vec![1u8, 255], + http_port: 35000u16, + grpc_port: 25000u16, + p2p_port: 15000u16, + }), + )?; + }, + } + + let cluster_id = ClusterId::from([1; 20]); + let cluster_params = ClusterParams { node_provider_auth_contract: stash.clone() }; + let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perbill::default(), + validators_share: Perbill::default(), + cluster_reserve_share: Perbill::default(), + cdn_bond_size: 10u32.into(), + cdn_chill_delay: 50u32.into(), + cdn_unbonding_delay: 50u32.into(), + storage_bond_size: 10u32.into(), + storage_chill_delay: 50u32.into(), + storage_unbonding_delay: 50u32.into(), + unit_per_mb_stored: 10, + unit_per_mb_streamed: 10, + unit_per_put_request: 10, + unit_per_get_request: 10, + }; + T::ClusterCreator::create_new_cluster( + cluster_id, + stash.clone(), + stash.clone(), + cluster_params, + cluster_gov_params, + )?; DdcStaking::::bond( RawOrigin::Signed(stash.clone()).into(), controller_lookup, - node.clone(), - balance, + node_pub.clone(), + T::Currency::minimum_balance() * balance_factor.saturated_into::>(), )?; - Ok((stash, controller, node)) + + Ok((stash, controller, node_pub)) } diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index efca88632..5437d12a2 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -44,72 +44,95 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:1) + // Storage: DdcStaking Providers (r:1 w:1) + // Storage: DdcNodes CDNNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(55_007_000_u64) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(37_000_000_u64) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) - // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) + // Storage: DdcNodes CDNNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(47_727_000_u64) - .saturating_add(T::DbWeight::get().reads(6_u64)) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(38_000_000_u64) + .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(69_750_000_u64) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Minimum execution time: 33_000 nanoseconds. + Weight::from_ref_time(34_000_000_u64) + .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } + // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn store() -> Weight { - Weight::from_ref_time(26_112_000_u64) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Minimum execution time: 28_000 nanoseconds. + Weight::from_ref_time(29_000_000_u64) + .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) fn serve() -> Weight { - Weight::from_ref_time(19_892_000_u64) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(28_000_000_u64) + .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(77_450_000_u64) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(28_000_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(38_521_000_u64) + // Minimum execution time: 12_000 nanoseconds. + Weight::from_ref_time(13_000_000_u64) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } - // Storage: DdcStaking Nodes (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:2) + // Storage: DdcStaking Providers (r:1 w:1) + // Storage: DdcStaking CDNs (r:1 w:0) + // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn set_node() -> Weight { - Weight::from_ref_time(21_779_000_u64) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 13_000 nanoseconds. + Weight::from_ref_time(14_000_000_u64) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } } @@ -118,71 +141,94 @@ impl WeightInfo for () { // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:1) + // Storage: DdcStaking Providers (r:1 w:1) + // Storage: DdcNodes CDNNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(55_007_000_u64) - .saturating_add(RocksDbWeight::get().reads(4_u64)) - .saturating_add(RocksDbWeight::get().writes(4_u64)) + // Minimum execution time: 35_000 nanoseconds. + Weight::from_ref_time(37_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) - // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) + // Storage: DdcNodes CDNNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(47_727_000_u64) - .saturating_add(RocksDbWeight::get().reads(6_u64)) + // Minimum execution time: 37_000 nanoseconds. + Weight::from_ref_time(38_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CurrentEra (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(69_750_000_u64) - .saturating_add(RocksDbWeight::get().reads(4_u64)) + // Minimum execution time: 33_000 nanoseconds. + Weight::from_ref_time(34_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } + // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn store() -> Weight { - Weight::from_ref_time(26_112_000_u64) - .saturating_add(RocksDbWeight::get().reads(4_u64)) + // Minimum execution time: 28_000 nanoseconds. + Weight::from_ref_time(29_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking Providers (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) fn serve() -> Weight { - Weight::from_ref_time(19_892_000_u64) - .saturating_add(RocksDbWeight::get().reads(4_u64)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(28_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) - // Storage: DdcStaking Settings (r:1 w:0) + // Storage: DdcClusters ClustersGovParams (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(77_450_000_u64) - .saturating_add(RocksDbWeight::get().reads(5_u64)) + // Minimum execution time: 27_000 nanoseconds. + Weight::from_ref_time(28_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(38_521_000_u64) + // Minimum execution time: 12_000 nanoseconds. + Weight::from_ref_time(13_000_000_u64) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } - // Storage: DdcStaking Nodes (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:2) + // Storage: DdcStaking Providers (r:1 w:1) + // Storage: DdcStaking CDNs (r:1 w:0) + // Storage: DdcStaking Storages (r:1 w:0) + // Storage: DdcStaking LeavingCDNs (r:1 w:0) + // Storage: DdcStaking LeavingStorages (r:1 w:0) fn set_node() -> Weight { - Weight::from_ref_time(21_779_000_u64) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Minimum execution time: 13_000 nanoseconds. + Weight::from_ref_time(14_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } } diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 3cdb76416..b17d85d4f 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use codec::{Decode, Encode}; -use scale_info::TypeInfo; +use scale_info::{prelude::vec::Vec, TypeInfo}; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; use sp_core::hash::H160; @@ -94,3 +94,26 @@ impl TryFrom for NodeType { } } } + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct CDNNodeParams { + pub host: Vec, + pub http_port: u16, + pub grpc_port: u16, + pub p2p_port: u16, +} + +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct StorageNodeParams { + pub host: Vec, + pub http_port: u16, + pub grpc_port: u16, + pub p2p_port: u16, +} + +// Params fields are always coming from extrinsic input +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub enum NodeParams { + StorageParams(StorageNodeParams), + CDNParams(CDNNodeParams), +} diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index b9359a935..5afafa72c 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1329,8 +1329,10 @@ impl pallet_ddc_staking::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_ddc_staking::weights::SubstrateWeight; type ClusterVisitor = pallet_ddc_clusters::Pallet; + type ClusterCreator = pallet_ddc_clusters::Pallet; type ClusterManager = pallet_ddc_clusters::Pallet; type NodeVisitor = pallet_ddc_nodes::Pallet; + type NodeCreator = pallet_ddc_nodes::Pallet; } parameter_types! { diff --git a/traits/src/node.rs b/traits/src/node.rs index 0ab55c1d1..ed60e0f1a 100644 --- a/traits/src/node.rs +++ b/traits/src/node.rs @@ -1,4 +1,5 @@ -use ddc_primitives::{ClusterId, NodePubKey}; +use ddc_primitives::{ClusterId, NodeParams, NodePubKey}; +use frame_support::dispatch::DispatchResult; use frame_system::Config; pub trait NodeVisitor { @@ -6,6 +7,14 @@ pub trait NodeVisitor { fn exists(node_pub_key: &NodePubKey) -> bool; } +pub trait NodeCreator { + fn create_node( + node_pub_key: NodePubKey, + provider_id: T::AccountId, + node_params: NodeParams, + ) -> DispatchResult; +} + pub enum NodeVisitorError { NodeDoesNotExist, }