diff --git a/node/service/chain-specs/example.json b/node/service/chain-specs/example.json index 7e3b5c97c..a9394d98b 100644 --- a/node/service/chain-specs/example.json +++ b/node/service/chain-specs/example.json @@ -157,7 +157,6 @@ "maxMembers": 512 }, "ddcStaking": { - "cdns": [], "storages": [] }, "ddcCustomers": { @@ -183,7 +182,6 @@ } } ], - "cdnNodes": [] }, "ddcClusters": { "clusters": [ @@ -203,9 +201,6 @@ "treasury_share": 0, "validators_share": 0, "cluster_reserve_share": 0, - "cdn_bond_size": 0, - "cdn_chill_delay": 0, - "cdn_unbonding_delay": 0, "storage_bond_size": 0, "storage_chill_delay": 0, "storage_unbonding_delay": 0, diff --git a/pallets/ddc-clusters/src/benchmarking.rs b/pallets/ddc-clusters/src/benchmarking.rs index 9ce6b28d9..2405330d7 100644 --- a/pallets/ddc-clusters/src/benchmarking.rs +++ b/pallets/ddc-clusters/src/benchmarking.rs @@ -22,93 +22,87 @@ benchmarks! { T::AccountId: UncheckedFrom + AsRef<[u8]> } create_cluster { - let cluster_id = ClusterId::from([1; 20]); + let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); - let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) }; - let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { - treasury_share: Perquintill::default(), - validators_share: Perquintill::default(), - cluster_reserve_share: Perquintill::default(), - cdn_bond_size: 100u32.into(), - cdn_chill_delay: 50u32.into(), - cdn_unbonding_delay: 50u32.into(), - storage_bond_size: 100u32.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, - }; + let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) }; + let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perquintill::default(), + validators_share: Perquintill::default(), + cluster_reserve_share: Perquintill::default(), + storage_bond_size: 100u32.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, + }; }: _(RawOrigin::Root, cluster_id, user.clone(), user, cluster_params, cluster_gov_params) verify { assert!(Clusters::::contains_key(cluster_id)); } - add_node { - let bytes = [0u8; 32]; - let node_pub_key = NodePubKey::CDNPubKey(AccountId32::from(bytes)); - let cluster_id = ClusterId::from([1; 20]); + add_node { + let bytes = [0u8; 32]; + let node_pub_key = NodePubKey::StoragePubKey(AccountId32::from(bytes)); + let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); - let balance = ::Currency::minimum_balance() * 1_000_000u32.into(); - let _ = ::Currency::make_free_balance_be(&user, balance); - let _ = config_cluster_and_node::(user.clone(), node_pub_key.clone(), cluster_id); - }: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone()) - verify { - assert!(ClustersNodes::::contains_key(cluster_id, node_pub_key)); - } + let balance = ::Currency::minimum_balance() * 1_000_000u32.into(); + let _ = ::Currency::make_free_balance_be(&user, balance); + let _ = config_cluster_and_node::(user.clone(), node_pub_key.clone(), cluster_id); + }: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone()) + verify { + assert!(ClustersNodes::::contains_key(cluster_id, node_pub_key)); + } - remove_node { - let bytes = [0u8; 32]; - let node_pub_key = NodePubKey::CDNPubKey(AccountId32::from(bytes)); - let cluster_id = ClusterId::from([1; 20]); + remove_node { + let bytes = [0u8; 32]; + let node_pub_key = NodePubKey::StoragePubKey(AccountId32::from(bytes)); + let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); - let balance = ::Currency::minimum_balance() * 1_000_000u32.into(); - let _ = ::Currency::make_free_balance_be(&user, balance); - let _ = config_cluster_and_node::(user.clone(), node_pub_key.clone(), cluster_id); - let _ = DdcClusters::::add_node( - RawOrigin::Signed(user.clone()).into(), - cluster_id, - node_pub_key.clone() - ); - }: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone()) - verify { - assert!(!ClustersNodes::::contains_key(cluster_id, node_pub_key)); - } + let balance = ::Currency::minimum_balance() * 1_000_000u32.into(); + let _ = ::Currency::make_free_balance_be(&user, balance); + let _ = config_cluster_and_node::(user.clone(), node_pub_key.clone(), cluster_id); + let _ = DdcClusters::::add_node( + RawOrigin::Signed(user.clone()).into(), + cluster_id, + node_pub_key.clone() + ); + }: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone()) + verify { + assert!(!ClustersNodes::::contains_key(cluster_id, node_pub_key)); + } set_cluster_params { - let cluster_id = ClusterId::from([1; 20]); + let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); let user_2 = account::("user", USER_SEED_2, 0u32); - let _ = config_cluster::(user.clone(), cluster_id); - let new_cluster_params = ClusterParams { node_provider_auth_contract: Some(user_2.clone()) }; + let _ = config_cluster::(user.clone(), cluster_id); + let new_cluster_params = ClusterParams { node_provider_auth_contract: Some(user_2.clone()) }; }: _(RawOrigin::Signed(user.clone()), cluster_id, new_cluster_params) verify { - assert_eq!(Clusters::::try_get(cluster_id).unwrap().props, ClusterProps { node_provider_auth_contract: Some(user_2) }); + assert_eq!(Clusters::::try_get(cluster_id).unwrap().props, ClusterProps { node_provider_auth_contract: Some(user_2) }); } set_cluster_gov_params { - let cluster_id = ClusterId::from([1; 20]); + let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); - let _ = config_cluster::(user, cluster_id); - let new_cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { - treasury_share: Perquintill::default(), - validators_share: Perquintill::default(), - cluster_reserve_share: Perquintill::default(), - cdn_bond_size: 10u32.into(), - cdn_chill_delay: 5u32.into(), - cdn_unbonding_delay: 5u32.into(), - storage_bond_size: 10u32.into(), - storage_chill_delay: 5u32.into(), - storage_unbonding_delay: 5u32.into(), - unit_per_mb_stored: 1, - unit_per_mb_streamed: 1, - unit_per_put_request: 1, - unit_per_get_request: 1, - }; + let _ = config_cluster::(user, cluster_id); + let new_cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + treasury_share: Perquintill::default(), + validators_share: Perquintill::default(), + cluster_reserve_share: Perquintill::default(), + storage_bond_size: 10u32.into(), + storage_chill_delay: 5u32.into(), + storage_unbonding_delay: 5u32.into(), + unit_per_mb_stored: 1, + unit_per_mb_streamed: 1, + unit_per_put_request: 1, + unit_per_get_request: 1, + }; }: _(RawOrigin::Root, cluster_id, new_cluster_gov_params.clone()) verify { - assert_eq!(ClustersGovParams::::try_get(cluster_id).unwrap(), new_cluster_gov_params); + assert_eq!(ClustersGovParams::::try_get(cluster_id).unwrap(), new_cluster_gov_params); } impl_benchmark_test_suite!( diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index a9c501854..49bbe1f87 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -350,7 +350,6 @@ pub mod pallet { match node_type { NodeType::Storage => Ok(cluster_gov_params.storage_bond_size.saturated_into::()), - NodeType::CDN => Ok(cluster_gov_params.cdn_bond_size.saturated_into::()), } } @@ -396,7 +395,6 @@ pub mod pallet { .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; match node_type { NodeType::Storage => Ok(cluster_gov_params.storage_chill_delay), - NodeType::CDN => Ok(cluster_gov_params.cdn_chill_delay), } } @@ -408,7 +406,6 @@ pub mod pallet { .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; match node_type { NodeType::Storage => Ok(cluster_gov_params.storage_unbonding_delay), - NodeType::CDN => Ok(cluster_gov_params.cdn_unbonding_delay), } } @@ -418,9 +415,6 @@ pub mod pallet { let cluster_gov_params = ClustersGovParams::::try_get(cluster_id) .map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?; Ok(ClusterBondingParams { - cdn_bond_size: cluster_gov_params.cdn_bond_size.saturated_into::(), - cdn_chill_delay: cluster_gov_params.cdn_chill_delay, - cdn_unbonding_delay: cluster_gov_params.cdn_unbonding_delay, storage_bond_size: cluster_gov_params.storage_bond_size.saturated_into::(), storage_chill_delay: cluster_gov_params.storage_chill_delay, storage_unbonding_delay: cluster_gov_params.storage_unbonding_delay, diff --git a/pallets/ddc-clusters/src/mock.rs b/pallets/ddc-clusters/src/mock.rs index d9beb473d..ab7e449bb 100644 --- a/pallets/ddc-clusters/src/mock.rs +++ b/pallets/ddc-clusters/src/mock.rs @@ -247,9 +247,6 @@ impl ExtBuilder { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -259,7 +256,7 @@ impl ExtBuilder { unit_per_get_request: 10, }; - let node_pub_key = NodePubKey::CDNPubKey(AccountId::from([0; 32])); + let node_pub_key = NodePubKey::StoragePubKey(AccountId::from([0; 32])); // For testing purposes only pallet_ddc_clusters::GenesisConfig::::default().build(); diff --git a/pallets/ddc-clusters/src/testing_utils.rs b/pallets/ddc-clusters/src/testing_utils.rs index b32e9ecca..3e7a65974 100644 --- a/pallets/ddc-clusters/src/testing_utils.rs +++ b/pallets/ddc-clusters/src/testing_utils.rs @@ -1,7 +1,7 @@ //! DdcStaking pallet benchmarking. use ddc_primitives::{ - CDNNodeParams, ClusterGovParams, ClusterId, ClusterParams, NodeParams, NodePubKey, + ClusterGovParams, ClusterId, ClusterParams, NodeParams, NodePubKey, StorageNodeParams, }; pub use frame_benchmarking::{ account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller, @@ -24,9 +24,6 @@ where treasury_share: Perquintill::default(), validators_share: Perquintill::default(), cluster_reserve_share: Perquintill::default(), - cdn_bond_size: 100u32.into(), - cdn_chill_delay: 50u32.into(), - cdn_unbonding_delay: 50u32.into(), storage_bond_size: 100u32.into(), storage_chill_delay: 50u32.into(), storage_unbonding_delay: 50u32.into(), @@ -55,7 +52,7 @@ where T::AccountId: UncheckedFrom + AsRef<[u8]>, { let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) }; - let cdn_node_params = CDNNodeParams { + let storage_node_params = StorageNodeParams { host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, @@ -66,9 +63,6 @@ where treasury_share: Perquintill::default(), validators_share: Perquintill::default(), cluster_reserve_share: Perquintill::default(), - cdn_bond_size: 100u32.into(), - cdn_chill_delay: 50u32.into(), - cdn_unbonding_delay: 50u32.into(), storage_bond_size: 100u32.into(), storage_chill_delay: 50u32.into(), storage_unbonding_delay: 50u32.into(), @@ -87,9 +81,11 @@ where cluster_gov_params, ); - if let Ok(new_node) = - Node::::new(node_pub_key.clone(), user.clone(), NodeParams::CDNParams(cdn_node_params)) - { + if let Ok(new_node) = Node::::new( + node_pub_key.clone(), + user.clone(), + NodeParams::StorageParams(storage_node_params), + ) { let _ = T::NodeRepository::create(new_node); } diff --git a/pallets/ddc-clusters/src/tests.rs b/pallets/ddc-clusters/src/tests.rs index b94627f47..d2903d891 100644 --- a/pallets/ddc-clusters/src/tests.rs +++ b/pallets/ddc-clusters/src/tests.rs @@ -2,8 +2,8 @@ use super::{mock::*, *}; use ddc_primitives::{ - CDNNodeParams, ClusterBondingParams, ClusterFeesParams, ClusterId, ClusterParams, - ClusterPricingParams, NodeParams, NodePubKey, + ClusterBondingParams, ClusterFeesParams, ClusterId, ClusterParams, ClusterPricingParams, + NodeParams, NodePubKey, StorageNodeParams, }; use ddc_traits::cluster::ClusterManager; use frame_support::{assert_noop, assert_ok, error::BadOrigin}; @@ -25,9 +25,6 @@ fn create_cluster_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -98,7 +95,7 @@ fn add_and_delete_node_works() { DdcClusters::add_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), ), Error::::ClusterDoesNotExist ); @@ -114,9 +111,6 @@ fn add_and_delete_node_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -132,7 +126,7 @@ fn add_and_delete_node_works() { DdcClusters::add_node( RuntimeOrigin::signed(cluster_reserve_id), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), ), Error::::OnlyClusterManager ); @@ -142,12 +136,12 @@ fn add_and_delete_node_works() { DdcClusters::add_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), ), Error::::AttemptToAddNonExistentNode ); - let cdn_node_params = CDNNodeParams { + let storage_node_params = StorageNodeParams { host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, @@ -157,8 +151,8 @@ fn add_and_delete_node_works() { // Node created assert_ok!(DdcNodes::create_node( RuntimeOrigin::signed(cluster_manager_id.clone()), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params) + NodePubKey::StoragePubKey(node_pub_key.clone()), + NodeParams::StorageParams(storage_node_params) )); // Node doesn't exist @@ -166,7 +160,7 @@ fn add_and_delete_node_works() { DdcClusters::add_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), ), Error::::NodeAuthContractCallFailed ); @@ -182,12 +176,12 @@ fn add_and_delete_node_works() { assert_ok!(DdcClusters::add_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), )); assert!(>::contains_node( &cluster_id, - &NodePubKey::CDNPubKey(node_pub_key.clone()) + &NodePubKey::StoragePubKey(node_pub_key.clone()) )); // Node already assigned @@ -195,7 +189,7 @@ fn add_and_delete_node_works() { DdcClusters::add_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), ), Error::::AttemptToAddAlreadyAssignedNode ); @@ -204,7 +198,7 @@ fn add_and_delete_node_works() { System::assert_last_event( Event::ClusterNodeAdded { cluster_id, - node_pub_key: NodePubKey::CDNPubKey(node_pub_key.clone()), + node_pub_key: NodePubKey::StoragePubKey(node_pub_key.clone()), } .into(), ); @@ -213,14 +207,14 @@ fn add_and_delete_node_works() { assert_ok!(DdcClusters::remove_node( RuntimeOrigin::signed(cluster_manager_id.clone()), cluster_id, - NodePubKey::CDNPubKey(node_pub_key.clone()), + NodePubKey::StoragePubKey(node_pub_key.clone()), )); // Checking that event was emitted System::assert_last_event( Event::ClusterNodeRemoved { cluster_id, - node_pub_key: NodePubKey::CDNPubKey(node_pub_key.clone()), + node_pub_key: NodePubKey::StoragePubKey(node_pub_key.clone()), } .into(), ); @@ -230,7 +224,7 @@ fn add_and_delete_node_works() { DdcClusters::remove_node( RuntimeOrigin::signed(cluster_manager_id), cluster_id, - NodePubKey::CDNPubKey(node_pub_key), + NodePubKey::StoragePubKey(node_pub_key), ), Error::::AttemptToRemoveNotAssignedNode ); @@ -277,7 +271,7 @@ fn add_and_delete_node_works() { let contract_id = Contracts::contract_address(&alice, &wasm_hash, &[]); pub const ADD_DDC_NODE_SELECTOR: [u8; 4] = hex!("7a04093d"); - let node_pub_key = NodePubKey::CDNPubKey(node_pub_key); + let node_pub_key = NodePubKey::StoragePubKey(node_pub_key); let call_data = { // is_authorized(node_provider: AccountId, node: Vec, node_variant: u8) -> bool @@ -334,9 +328,6 @@ fn set_cluster_params_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -382,9 +373,6 @@ fn set_cluster_gov_params_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -448,9 +436,6 @@ fn cluster_visitor_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -473,7 +458,7 @@ fn cluster_visitor_works() { assert_ok!(>::ensure_cluster(&cluster_id)); assert_eq!( - >::get_bond_size(&cluster_id, NodeType::CDN) + >::get_bond_size(&cluster_id, NodeType::Storage) .unwrap(), 100u128 ); @@ -508,7 +493,7 @@ fn cluster_visitor_works() { ); assert_eq!( - >::get_chill_delay(&cluster_id, NodeType::CDN) + >::get_chill_delay(&cluster_id, NodeType::Storage) .unwrap(), 50 ); @@ -519,8 +504,11 @@ fn cluster_visitor_works() { ); assert_eq!( - >::get_unbonding_delay(&cluster_id, NodeType::CDN) - .unwrap(), + >::get_unbonding_delay( + &cluster_id, + NodeType::Storage + ) + .unwrap(), 50 ); assert_eq!( @@ -535,9 +523,6 @@ fn cluster_visitor_works() { assert_eq!( >::get_bonding_params(&cluster_id).unwrap(), ClusterBondingParams::<::BlockNumber> { - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, @@ -560,9 +545,6 @@ fn cluster_creator_works() { treasury_share: Perquintill::from_float(0.05), validators_share: Perquintill::from_float(0.01), cluster_reserve_share: Perquintill::from_float(0.02), - cdn_bond_size: 100, - cdn_chill_delay: 50, - cdn_unbonding_delay: 50, storage_bond_size: 100, storage_chill_delay: 50, storage_unbonding_delay: 50, diff --git a/pallets/ddc-clusters/src/weights.rs b/pallets/ddc-clusters/src/weights.rs index 96e4b735f..af2bb5559 100644 --- a/pallets/ddc-clusters/src/weights.rs +++ b/pallets/ddc-clusters/src/weights.rs @@ -1,27 +1,22 @@ - -//! Autogenerated weights for `pallet_ddc_clusters` +//! Autogenerated weights for pallet_ddc_clusters //! //! 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-MacBook-Pro-2.local`, CPU: `` -//! EXECUTION: None, WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/cere // benchmark // pallet -// --chain -// dev -// --pallet -// pallet_ddc_clusters -// --extrinsic -// * -// --steps -// 20 -// --repeat -// 50 -// --output -// pallets/ddc-clusters/src/weights.rs +// --chain=dev +// --execution=wasm +// --pallet=pallet-ddc-clusters +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --template=./.maintain/frame-weight-template.hbs +// --output=pallets/ddc-clusters/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -39,24 +34,22 @@ pub trait WeightInfo { fn set_cluster_gov_params() -> Weight; } -/// Weight functions for `pallet_ddc_clusters`. +/// Weights for pallet_ddc_clusters using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: DdcClusters Clusters (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn create_cluster() -> Weight { - // Minimum execution time: 14_000 nanoseconds. - Weight::from_ref_time(15_000_000u64) - .saturating_add(T::DbWeight::get().reads(1u64)) - .saturating_add(T::DbWeight::get().writes(2u64)) + Weight::from_ref_time(15_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:0) - // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking Bonded (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) + // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: System Account (r:1 w:0) // Storage: Contracts ContractInfoOf (r:1 w:1) // Storage: Contracts CodeStorage (r:1 w:0) @@ -66,54 +59,48 @@ impl WeightInfo for SubstrateWeight { // Storage: unknown [0x89eb0d6a8a691dae2cd15ed0369931ce0a949ecafa5c3f93f8121833646e15c3] (r:1 w:0) // Storage: unknown [0xc3ad1d87683b6ac25f2e809346840d7a7ed0c05653ee606dba68aba3bdb5d957] (r:1 w:0) fn add_node() -> Weight { - // Minimum execution time: 307_000 nanoseconds. - Weight::from_ref_time(354_000_000u64) - .saturating_add(T::DbWeight::get().reads(15u64)) - .saturating_add(T::DbWeight::get().writes(5u64)) + Weight::from_ref_time(599_000_000_u64) + .saturating_add(T::DbWeight::get().reads(14_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: DdcClusters ClustersNodes (r:0 w:1) fn remove_node() -> Weight { - // Minimum execution time: 23_000 nanoseconds. - Weight::from_ref_time(24_000_000u64) - .saturating_add(T::DbWeight::get().reads(2u64)) - .saturating_add(T::DbWeight::get().writes(2u64)) + Weight::from_ref_time(24_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcClusters Clusters (r:1 w:1) fn set_cluster_params() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000u64) - .saturating_add(T::DbWeight::get().reads(1u64)) - .saturating_add(T::DbWeight::get().writes(1u64)) + Weight::from_ref_time(16_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn set_cluster_gov_params() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000u64) - .saturating_add(T::DbWeight::get().reads(1u64)) - .saturating_add(T::DbWeight::get().writes(1u64)) + Weight::from_ref_time(17_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: DdcClusters Clusters (r:1 w:1) + // Storage: DdcClusters Clusters (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn create_cluster() -> Weight { - // Minimum execution time: 14_000 nanoseconds. - Weight::from_ref_time(15_000_000u64) - .saturating_add(RocksDbWeight::get().reads(1u64)) - .saturating_add(RocksDbWeight::get().writes(2u64)) + Weight::from_ref_time(15_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:1) // Storage: DdcStaking Nodes (r:1 w:0) - // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking Bonded (r:1 w:0) // Storage: DdcStaking Ledger (r:1 w:0) + // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: System Account (r:1 w:0) // Storage: Contracts ContractInfoOf (r:1 w:1) // Storage: Contracts CodeStorage (r:1 w:0) @@ -123,33 +110,29 @@ impl WeightInfo for () { // Storage: unknown [0x89eb0d6a8a691dae2cd15ed0369931ce0a949ecafa5c3f93f8121833646e15c3] (r:1 w:0) // Storage: unknown [0xc3ad1d87683b6ac25f2e809346840d7a7ed0c05653ee606dba68aba3bdb5d957] (r:1 w:0) fn add_node() -> Weight { - // Minimum execution time: 307_000 nanoseconds. - Weight::from_ref_time(354_000_000u64) - .saturating_add(RocksDbWeight::get().reads(15u64)) - .saturating_add(RocksDbWeight::get().writes(5u64)) + Weight::from_ref_time(599_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(14_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (r:1 w:1) // Storage: DdcClusters ClustersNodes (r:0 w:1) fn remove_node() -> Weight { - // Minimum execution time: 23_000 nanoseconds. - Weight::from_ref_time(24_000_000u64) - .saturating_add(RocksDbWeight::get().reads(2u64)) - .saturating_add(RocksDbWeight::get().writes(2u64)) + Weight::from_ref_time(24_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcClusters Clusters (r:1 w:1) fn set_cluster_params() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000u64) - .saturating_add(RocksDbWeight::get().reads(1u64)) - .saturating_add(RocksDbWeight::get().writes(1u64)) + Weight::from_ref_time(16_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcClusters ClustersGovParams (r:0 w:1) fn set_cluster_gov_params() -> Weight { - // Minimum execution time: 15_000 nanoseconds. - Weight::from_ref_time(16_000_000u64) - .saturating_add(RocksDbWeight::get().reads(1u64)) - .saturating_add(RocksDbWeight::get().writes(1u64)) + Weight::from_ref_time(17_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } \ No newline at end of file diff --git a/pallets/ddc-customers/src/benchmarking.rs b/pallets/ddc-customers/src/benchmarking.rs index 84d16daec..552f40727 100644 --- a/pallets/ddc-customers/src/benchmarking.rs +++ b/pallets/ddc-customers/src/benchmarking.rs @@ -20,14 +20,10 @@ benchmarks! { create_bucket { let cluster_id = ClusterId::from([1; 20]); let user = account::("user", USER_SEED, 0u32); - - let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { + let cluster_gov_params: ClusterGovParams, T::BlockNumber> = ClusterGovParams { treasury_share: Perquintill::default(), validators_share: Perquintill::default(), cluster_reserve_share: Perquintill::default(), - cdn_bond_size: 100u32.into(), - cdn_chill_delay: 50u32.into(), - cdn_unbonding_delay: 50u32.into(), storage_bond_size: 100u32.into(), storage_chill_delay: 50u32.into(), storage_unbonding_delay: 50u32.into(), @@ -37,13 +33,13 @@ benchmarks! { unit_per_get_request: 10, }; - let _ = ::ClusterCreator::create_new_cluster( - ClusterId::from([1; 20]), - user.clone(), - user.clone(), - ClusterParams { node_provider_auth_contract: Some(user.clone()) }, - cluster_gov_params - ); + let _ = ::ClusterCreator::create_new_cluster( + ClusterId::from([1; 20]), + user.clone(), + user.clone(), + ClusterParams { node_provider_auth_contract: Some(user.clone()) }, + cluster_gov_params + ); whitelist_account!(user); }: _(RawOrigin::Signed(user), cluster_id) @@ -69,7 +65,7 @@ benchmarks! { let _ = ::Currency::make_free_balance_be(&user, balance); let amount = ::Currency::minimum_balance() * 50u32.into(); - let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); whitelist_account!(user); }: _(RawOrigin::Signed(user.clone()), amount) @@ -83,71 +79,71 @@ benchmarks! { let _ = ::Currency::make_free_balance_be(&user, balance); let amount = ::Currency::minimum_balance() * 50u32.into(); - let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); - whitelist_account!(user); + whitelist_account!(user); }: unlock_deposit(RawOrigin::Signed(user.clone()), amount) verify { assert!(Ledger::::contains_key(user)); } - // Worst case scenario, 31/32 chunks unlocked after the unlocking duration + // Worst case scenario, 31/32 chunks unlocked after the unlocking duration withdraw_unlocked_deposit_update { - System::::set_block_number(1u32.into()); + System::::set_block_number(1u32.into()); let user = account::("user", USER_SEED, 0u32); let balance = ::Currency::minimum_balance() * 2000u32.into(); let _ = ::Currency::make_free_balance_be(&user, balance); let amount = ::Currency::minimum_balance() * 32u32.into(); - let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); - for _k in 1 .. 32 { - let _ = DdcCustomers::::unlock_deposit(RawOrigin::Signed(user.clone()).into(), ::Currency::minimum_balance() * 1u32.into()); - } + for _k in 1 .. 32 { + let _ = DdcCustomers::::unlock_deposit(RawOrigin::Signed(user.clone()).into(), ::Currency::minimum_balance() * 1u32.into()); + } - System::::set_block_number(5256001u32.into()); + System::::set_block_number(5256001u32.into()); - whitelist_account!(user); + whitelist_account!(user); }: withdraw_unlocked_deposit(RawOrigin::Signed(user.clone())) verify { - let ledger = Ledger::::try_get(user).unwrap(); + let ledger = Ledger::::try_get(user).unwrap(); assert_eq!(ledger.active, amount / 32u32.into()); } - // Worst case scenario, everything is removed after the unlocking duration + // Worst case scenario, everything is removed after the unlocking duration withdraw_unlocked_deposit_kill { - System::::set_block_number(1u32.into()); + System::::set_block_number(1u32.into()); let user = account::("user", USER_SEED, 0u32); - let user2 = account::("user", USER_SEED, 1u32); + let user2 = account::("user", USER_SEED, 1u32); let balance = ::Currency::minimum_balance() * 2000u32.into(); let _ = ::Currency::make_free_balance_be(&user, balance); - let _ = ::Currency::make_free_balance_be(&user2, balance); + let _ = ::Currency::make_free_balance_be(&user2, balance); let amount = ::Currency::minimum_balance() * 32u32.into(); - let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); - // To keep the balance of pallet positive - let _ = DdcCustomers::::deposit(RawOrigin::Signed(user2).into(), amount); + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user.clone()).into(), amount); + // To keep the balance of pallet positive + let _ = DdcCustomers::::deposit(RawOrigin::Signed(user2).into(), amount); - for _k in 1 .. 33 { - let _ = DdcCustomers::::unlock_deposit(RawOrigin::Signed(user.clone()).into(), ::Currency::minimum_balance() * 1u32.into()); - } + for _k in 1 .. 33 { + let _ = DdcCustomers::::unlock_deposit(RawOrigin::Signed(user.clone()).into(), ::Currency::minimum_balance() * 1u32.into()); + } - System::::set_block_number(5256001u32.into()); + System::::set_block_number(5256001u32.into()); - whitelist_account!(user); + whitelist_account!(user); }: withdraw_unlocked_deposit(RawOrigin::Signed(user.clone())) verify { - assert!(!Ledger::::contains_key(user)); + assert!(!Ledger::::contains_key(user)); } - impl_benchmark_test_suite!( - DdcCustomers, - crate::mock::ExtBuilder.build(), - crate::mock::Test, - ); + impl_benchmark_test_suite!( + DdcCustomers, + crate::mock::ExtBuilder.build(), + crate::mock::Test, + ); } diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 191af3ecc..725c617cc 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -70,14 +70,15 @@ pub struct BucketsDetails { #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] #[scale_info(skip_type_params(T))] pub struct AccountsLedger { - /// The owner account whose balance is actually locked and can be used for CDN usage. + /// The owner account whose balance is actually locked and can be used to pay for DDC network + /// usage. pub owner: T::AccountId, /// The total amount of the owner's balance that we are currently accounting for. /// It's just `active` plus all the `unlocking` balances. #[codec(compact)] pub total: BalanceOf, - /// The total amount of the owner's balance that will be accessible for CDN payments in any - /// forthcoming rounds. + /// The total amount of the owner's balance that will be accessible for DDC network payouts in + /// any forthcoming rounds. #[codec(compact)] pub active: BalanceOf, /// Any balance that is becoming free, which may eventually be transferred out of the owner @@ -319,7 +320,7 @@ pub mod pallet { } /// Add some extra amount that have appeared in the owner `free_balance` into the balance up - /// for CDN payments. + /// for DDC network payouts. /// /// The dispatch origin for this call must be _Signed_ by the owner. /// diff --git a/pallets/ddc-customers/src/mock.rs b/pallets/ddc-customers/src/mock.rs index d9e847eb0..56b644f37 100644 --- a/pallets/ddc-customers/src/mock.rs +++ b/pallets/ddc-customers/src/mock.rs @@ -163,21 +163,6 @@ impl ClusterVisitor for TestClusterVisitor { cluster_id: &ClusterId, ) -> Result, ClusterVisitorError> { Ok(ClusterBondingParams { - cdn_bond_size: >::get_bond_size( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), - cdn_chill_delay: >::get_chill_delay( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), - cdn_unbonding_delay: >::get_unbonding_delay( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), storage_bond_size: >::get_bond_size( cluster_id, NodeType::Storage, diff --git a/pallets/ddc-customers/src/weights.rs b/pallets/ddc-customers/src/weights.rs index 66ae43d01..b024b6808 100644 --- a/pallets/ddc-customers/src/weights.rs +++ b/pallets/ddc-customers/src/weights.rs @@ -1,27 +1,22 @@ - -//! Autogenerated weights for `pallet_ddc_customers` +//! Autogenerated weights for pallet_ddc_customers //! //! 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-MacBook-Pro-2.local`, CPU: `` -//! EXECUTION: None, WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/cere // benchmark // pallet -// --chain -// dev -// --pallet -// pallet_ddc_customers -// --extrinsic -// * -// --steps -// 200 -// --repeat -// 1000 -// --output -// pallets/ddc-customers/src/weights.rs +// --chain=dev +// --execution=wasm +// --pallet=pallet-ddc-customers +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --template=./.maintain/frame-weight-template.hbs +// --output=pallets/ddc-customers/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -30,7 +25,7 @@ use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use sp_std::marker::PhantomData; -/// Weight functions needed for pallet_ddc_nodes. +/// Weight functions needed for pallet_ddc_customers. pub trait WeightInfo { fn create_bucket() -> Weight; fn deposit() -> Weight; @@ -40,28 +35,28 @@ pub trait WeightInfo { fn withdraw_unlocked_deposit_kill() -> Weight; } -/// Weight functions for `pallet_ddc_customers`. +/// Weights for pallet_ddc_customers using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: DdcCustomers BucketsCount (r:1 w:1) // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcCustomers Buckets (r:0 w:1) fn create_bucket() -> Weight { - Weight::from_ref_time(18_000_000_u64) + Weight::from_ref_time(17_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit() -> Weight { - Weight::from_ref_time(26_000_000_u64) + Weight::from_ref_time(28_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit_extra() -> Weight { - Weight::from_ref_time(28_000_000_u64) + Weight::from_ref_time(29_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -72,15 +67,16 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_update() -> Weight { - Weight::from_ref_time(14_000_000_u64) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + Weight::from_ref_time(30_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_kill() -> Weight { - Weight::from_ref_time(31_000_000_u64) + Weight::from_ref_time(36_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -92,21 +88,21 @@ impl WeightInfo for () { // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcCustomers Buckets (r:0 w:1) fn create_bucket() -> Weight { - Weight::from_ref_time(18_000_000_u64) + Weight::from_ref_time(17_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit() -> Weight { - Weight::from_ref_time(26_000_000_u64) + Weight::from_ref_time(28_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn deposit_extra() -> Weight { - Weight::from_ref_time(28_000_000_u64) + Weight::from_ref_time(29_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -117,15 +113,16 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) + // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_update() -> Weight { - Weight::from_ref_time(14_000_000_u64) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + Weight::from_ref_time(30_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcCustomers Ledger (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unlocked_deposit_kill() -> Weight { - Weight::from_ref_time(31_000_000_u64) + Weight::from_ref_time(36_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } diff --git a/pallets/ddc-nodes/src/benchmarking.rs b/pallets/ddc-nodes/src/benchmarking.rs index 448cde563..1e65c7ea0 100644 --- a/pallets/ddc-nodes/src/benchmarking.rs +++ b/pallets/ddc-nodes/src/benchmarking.rs @@ -1,56 +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::*; - +use ddc_primitives::StorageNodePubKey; pub use frame_benchmarking::{ account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller, }; use frame_system::RawOrigin; +use sp_std::prelude::*; +use testing_utils::*; + +use super::*; +use crate::{storage_node::StorageNodeProps, Pallet as DdcNodes}; const USER_SEED: u32 = 999666; benchmarks! { create_node { - let (user, node, cdn_node_params, _) = create_user_and_config::("user", USER_SEED); + let (user, node, storage_node_params, _) = create_user_and_config::("user", USER_SEED); - whitelist_account!(user); - }: _(RawOrigin::Signed(user.clone()), node, cdn_node_params) + whitelist_account!(user); + }: _(RawOrigin::Signed(user.clone()), node, storage_node_params) verify { - assert!(CDNNodes::::contains_key(CDNNodePubKey::new([0; 32]))); + assert!(StorageNodes::::contains_key(StorageNodePubKey::new([0; 32]))); } delete_node { - let (user, node, cdn_node_params, _) = create_user_and_config::("user", USER_SEED); + let (user, node, storage_node_params, _) = create_user_and_config::("user", USER_SEED); - DdcNodes::::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), cdn_node_params)?; + DdcNodes::::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), storage_node_params)?; whitelist_account!(user); }: _(RawOrigin::Signed(user.clone()), node) verify { - assert!(!CDNNodes::::contains_key(CDNNodePubKey::new([0; 32]))); + assert!(!StorageNodes::::contains_key(StorageNodePubKey::new([0; 32]))); } set_node_params { - let (user, node, cdn_node_params, cdn_node_params_new) = create_user_and_config::("user", USER_SEED); + let (user, node, storage_node_params, new_storage_node_params) = create_user_and_config::("user", USER_SEED); - DdcNodes::::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), cdn_node_params)?; + DdcNodes::::create_node(RawOrigin::Signed(user.clone()).into(),node.clone(), storage_node_params)?; - whitelist_account!(user); - }: _(RawOrigin::Signed(user.clone()), node, cdn_node_params_new) + whitelist_account!(user); + }: _(RawOrigin::Signed(user.clone()), node, new_storage_node_params) verify { - assert_eq!(CDNNodes::::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, - }); + assert_eq!(StorageNodes::::try_get( + StorageNodePubKey::new([0; 32])).unwrap().props, + StorageNodeProps { + host: vec![2u8, 255].try_into().unwrap(), + http_port: 45000u16, + grpc_port: 55000u16, + p2p_port: 65000u16, + }); } impl_benchmark_test_suite!( diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs deleted file mode 100644 index b7f5cf146..000000000 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ /dev/null @@ -1,105 +0,0 @@ -use crate::node::{NodeError, NodeProps, NodeTrait}; -use codec::{Decode, Encode}; -use ddc_primitives::{CDNNodePubKey, ClusterId, NodeParams, NodePubKey, NodeType}; -use frame_support::{parameter_types, BoundedVec}; -use scale_info::TypeInfo; -#[cfg(feature = "std")] -use serde::{Deserialize, Serialize}; -use sp_runtime::RuntimeDebug; -use sp_std::prelude::*; - -parameter_types! { - pub MaxCDNNodeParamsLen: u16 = 2048; - pub MaxHostLen: u8 = 255; -} - -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -#[scale_info(skip_type_params(T))] -pub struct CDNNode { - pub pub_key: CDNNodePubKey, - pub provider_id: T::AccountId, - pub cluster_id: Option, - pub props: CDNNodeProps, -} - -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] -pub struct CDNNodeProps { - pub host: BoundedVec, - pub http_port: u16, - pub grpc_port: u16, - pub p2p_port: u16, -} - -impl CDNNode { - pub fn new( - node_pub_key: NodePubKey, - provider_id: T::AccountId, - node_params: NodeParams, - ) -> Result { - match node_pub_key { - NodePubKey::CDNPubKey(pub_key) => match node_params { - NodeParams::CDNParams(node_params) => Ok(CDNNode:: { - provider_id, - pub_key, - cluster_id: None, - props: CDNNodeProps { - host: match node_params.host.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), - }, - http_port: node_params.http_port, - grpc_port: node_params.grpc_port, - p2p_port: node_params.p2p_port, - }, - }), - _ => Err(NodeError::InvalidCDNNodeParams), - }, - _ => Err(NodeError::InvalidCDNNodePubKey), - } - } -} - -impl NodeTrait for CDNNode { - fn get_pub_key(&self) -> NodePubKey { - NodePubKey::CDNPubKey(self.pub_key.clone()) - } - fn get_provider_id(&self) -> &T::AccountId { - &self.provider_id - } - fn get_props(&self) -> NodeProps { - NodeProps::CDNProps(self.props.clone()) - } - fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { - self.props = match props { - NodeProps::CDNProps(props) => props, - _ => return Err(NodeError::InvalidCDNNodeProps), - }; - Ok(()) - } - fn set_params(&mut self, node_params: NodeParams) -> Result<(), NodeError> { - match node_params { - NodeParams::CDNParams(cdn_params) => { - self.props.host = match cdn_params.host.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), - }; - self.props.http_port = cdn_params.http_port; - self.props.grpc_port = cdn_params.grpc_port; - self.props.p2p_port = cdn_params.p2p_port; - }, - _ => return Err(NodeError::InvalidCDNNodeParams), - }; - Ok(()) - } - fn get_cluster_id(&self) -> &Option { - &self.cluster_id - } - fn set_cluster_id(&mut self, cluster_id: Option) { - self.cluster_id = cluster_id; - } - fn get_type(&self) -> NodeType { - NodeType::CDN - } -} diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 3d89e92b7..acf6b430b 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -27,7 +27,7 @@ pub mod benchmarking; #[cfg(any(feature = "runtime-benchmarks", test))] pub mod testing_utils; -use ddc_primitives::{CDNNodePubKey, ClusterId, NodeParams, NodePubKey, StorageNodePubKey}; +use ddc_primitives::{ClusterId, NodeParams, NodePubKey, StorageNodePubKey}; use ddc_traits::{ node::{NodeCreator, NodeVisitor, NodeVisitorError}, staking::StakingVisitor, @@ -35,15 +35,13 @@ use ddc_traits::{ use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; +pub use pallet::*; use sp_std::prelude::*; -pub use pallet::*; -mod cdn_node; mod node; mod storage_node; pub use crate::{ - cdn_node::CDNNode, node::{Node, NodeError, NodeTrait}, storage_node::StorageNode, }; @@ -76,9 +74,6 @@ pub mod pallet { pub enum Error { NodeAlreadyExists, NodeDoesNotExist, - InvalidNodePubKey, - InvalidNodeParams, - NodeParamsExceedsLimit, OnlyNodeProvider, NodeIsAssignedToCluster, HostLenExceedsLimit, @@ -90,20 +85,15 @@ pub mod pallet { pub type StorageNodes = StorageMap<_, Blake2_128Concat, StorageNodePubKey, StorageNode>; - #[pallet::storage] - #[pallet::getter(fn cdn_nodes)] - pub type CDNNodes = StorageMap<_, Blake2_128Concat, CDNNodePubKey, CDNNode>; - #[pallet::genesis_config] pub struct GenesisConfig { pub storage_nodes: Vec>, - pub cdn_nodes: Vec>, } #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { - GenesisConfig { storage_nodes: Default::default(), cdn_nodes: Default::default() } + GenesisConfig { storage_nodes: Default::default() } } } @@ -113,9 +103,6 @@ pub mod pallet { for storage_node in &self.storage_nodes { >::insert(storage_node.pub_key.clone(), storage_node); } - for cdn_node in &self.cdn_nodes { - >::insert(cdn_node.pub_key.clone(), cdn_node); - } } } @@ -174,18 +161,14 @@ pub mod pallet { #[derive(Debug, PartialEq)] pub enum NodeRepositoryError { StorageNodeAlreadyExists, - CDNNodeAlreadyExists, StorageNodeDoesNotExist, - CDNNodeDoesNotExist, } impl From for Error { fn from(error: NodeRepositoryError) -> Self { match error { NodeRepositoryError::StorageNodeAlreadyExists => Error::::NodeAlreadyExists, - NodeRepositoryError::CDNNodeAlreadyExists => Error::::NodeAlreadyExists, NodeRepositoryError::StorageNodeDoesNotExist => Error::::NodeDoesNotExist, - NodeRepositoryError::CDNNodeDoesNotExist => Error::::NodeDoesNotExist, } } } @@ -200,13 +183,6 @@ pub mod pallet { StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); Ok(()) }, - Node::CDN(cdn_node) => { - if CDNNodes::::contains_key(&cdn_node.pub_key) { - return Err(NodeRepositoryError::CDNNodeAlreadyExists) - } - CDNNodes::::insert(cdn_node.pub_key.clone(), cdn_node); - Ok(()) - }, } } @@ -216,10 +192,6 @@ pub mod pallet { Ok(storage_node) => Ok(Node::Storage(storage_node)), Err(_) => Err(NodeRepositoryError::StorageNodeDoesNotExist), }, - NodePubKey::CDNPubKey(pub_key) => match CDNNodes::::try_get(pub_key) { - Ok(cdn_node) => Ok(Node::CDN(cdn_node)), - Err(_) => Err(NodeRepositoryError::CDNNodeDoesNotExist), - }, } } @@ -231,12 +203,6 @@ pub mod pallet { } StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); }, - Node::CDN(cdn_node) => { - if !CDNNodes::::contains_key(&cdn_node.pub_key) { - return Err(NodeRepositoryError::CDNNodeDoesNotExist) - } - CDNNodes::::insert(cdn_node.pub_key.clone(), cdn_node); - }, } Ok(()) } @@ -247,10 +213,6 @@ pub mod pallet { StorageNodes::::remove(pub_key); Ok(()) }, - NodePubKey::CDNPubKey(pub_key) => { - CDNNodes::::remove(pub_key); - Ok(()) - }, } } } diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index f0a5be5d5..2688400f4 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -1,7 +1,6 @@ #![allow(clippy::needless_lifetimes)] // ToDo use crate::{ - cdn_node::{CDNNode, CDNNodeProps}, pallet::Error, storage_node::{StorageNode, StorageNodeProps}, ClusterId, @@ -14,14 +13,12 @@ use sp_runtime::RuntimeDebug; #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum Node { Storage(StorageNode), - CDN(CDNNode), } // Props fields may include internal protocol properties #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeProps { StorageProps(StorageNodeProps), - CDNProps(CDNNodeProps), } pub trait NodeTrait { @@ -44,8 +41,6 @@ impl Node { match node_pub_key { NodePubKey::StoragePubKey(_) => StorageNode::new(node_pub_key, provider_id, node_params).map(|n| Node::Storage(n)), - NodePubKey::CDNPubKey(_) => - CDNNode::new(node_pub_key, provider_id, node_params).map(|n| Node::CDN(n)), } } } @@ -54,76 +49,54 @@ impl NodeTrait for Node { fn get_pub_key(&self) -> NodePubKey { match &self { Node::Storage(node) => node.get_pub_key(), - Node::CDN(node) => node.get_pub_key(), } } fn get_provider_id(&self) -> &T::AccountId { match &self { Node::Storage(node) => node.get_provider_id(), - Node::CDN(node) => node.get_provider_id(), } } fn get_props(&self) -> NodeProps { match &self { Node::Storage(node) => node.get_props(), - Node::CDN(node) => node.get_props(), } } fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { match self { Node::Storage(node) => node.set_props(props), - Node::CDN(node) => node.set_props(props), } } fn set_params(&mut self, params: NodeParams) -> Result<(), NodeError> { match self { Node::Storage(node) => node.set_params(params), - Node::CDN(node) => node.set_params(params), } } fn get_cluster_id(&self) -> &Option { match &self { Node::Storage(node) => node.get_cluster_id(), - Node::CDN(node) => node.get_cluster_id(), } } fn set_cluster_id(&mut self, cluster_id: Option) { match self { Node::Storage(node) => node.set_cluster_id(cluster_id), - Node::CDN(node) => node.set_cluster_id(cluster_id), } } fn get_type(&self) -> NodeType { match &self { Node::Storage(node) => node.get_type(), - Node::CDN(node) => node.get_type(), } } } #[derive(Debug, PartialEq)] pub enum NodeError { - InvalidStorageNodePubKey, - InvalidCDNNodePubKey, - InvalidStorageNodeParams, - InvalidCDNNodeParams, StorageHostLenExceedsLimit, - CDNHostLenExceedsLimit, - InvalidCDNNodeProps, - InvalidStorageNodeProps, } impl From for Error { fn from(error: NodeError) -> Self { match error { - NodeError::InvalidStorageNodePubKey => Error::::InvalidNodePubKey, - NodeError::InvalidCDNNodePubKey => Error::::InvalidNodePubKey, - NodeError::InvalidStorageNodeParams => Error::::InvalidNodeParams, - NodeError::InvalidCDNNodeParams => Error::::InvalidNodeParams, NodeError::StorageHostLenExceedsLimit => Error::::HostLenExceedsLimit, - NodeError::CDNHostLenExceedsLimit => Error::::HostLenExceedsLimit, - NodeError::InvalidStorageNodeProps => Error::::InvalidNodeParams, - NodeError::InvalidCDNNodeProps => Error::::InvalidNodeParams, } } } diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 14f937c3b..1dcbaa467 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -53,9 +53,7 @@ impl StorageNode { p2p_port: node_params.p2p_port, }, }), - _ => Err(NodeError::InvalidStorageNodeParams), }, - _ => Err(NodeError::InvalidStorageNodePubKey), } } } @@ -73,7 +71,6 @@ impl NodeTrait for StorageNode { fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { self.props = match props { NodeProps::StorageProps(props) => props, - _ => return Err(NodeError::InvalidStorageNodeProps), }; Ok(()) } @@ -82,13 +79,12 @@ impl NodeTrait for StorageNode { NodeParams::StorageParams(storage_params) => { self.props.host = match storage_params.host.try_into() { Ok(vec) => vec, - Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), + Err(_) => return Err(NodeError::StorageHostLenExceedsLimit), }; self.props.http_port = storage_params.http_port; self.props.grpc_port = storage_params.grpc_port; self.props.p2p_port = storage_params.p2p_port; }, - _ => return Err(NodeError::InvalidStorageNodeParams), }; Ok(()) } diff --git a/pallets/ddc-nodes/src/testing_utils.rs b/pallets/ddc-nodes/src/testing_utils.rs index 8db4dfd35..26f12fc7c 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::{Config, NodePubKey}; -use ddc_primitives::{CDNNodeParams, CDNNodePubKey, NodeParams}; +use ddc_primitives::{NodeParams, StorageNodeParams, StorageNodePubKey}; use frame_benchmarking::account; use sp_std::vec; @@ -13,19 +13,19 @@ pub fn create_user_and_config( 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 { + let node = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); + let storage_node_params = NodeParams::StorageParams(StorageNodeParams { host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, p2p_port: 15000u16, }); - let cdn_node_params_new = NodeParams::CDNParams(CDNNodeParams { + let new_storage_node_params = NodeParams::StorageParams(StorageNodeParams { host: vec![2u8, 255], http_port: 45000u16, grpc_port: 55000u16, p2p_port: 65000u16, }); - (user, node, cdn_node_params, cdn_node_params_new) + (user, node, storage_node_params, new_storage_node_params) } diff --git a/pallets/ddc-nodes/src/tests.rs b/pallets/ddc-nodes/src/tests.rs index ea2c6d8af..3019e1e1e 100644 --- a/pallets/ddc-nodes/src/tests.rs +++ b/pallets/ddc-nodes/src/tests.rs @@ -1,132 +1,10 @@ //! Tests for the module. use super::{mock::*, *}; -use ddc_primitives::{CDNNodeParams, NodePubKey, StorageNodeParams}; +use ddc_primitives::{NodePubKey, StorageNodeParams}; use frame_support::{assert_noop, assert_ok}; use sp_runtime::AccountId32; -#[test] -fn create_cdn_node_works() { - ExtBuilder.build_and_execute(|| { - System::set_block_number(1); - let bytes = [0u8; 32]; - let node_pub_key = AccountId32::from(bytes); - let cdn_node_params = CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; - - // Node params are not valid - assert_noop!( - DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::StorageParams(StorageNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }) - ), - Error::::InvalidNodeParams - ); - - // Pub key invalid - assert_noop!( - CDNNode::::new( - NodePubKey::StoragePubKey(node_pub_key.clone()), - 1u64, - NodeParams::CDNParams(cdn_node_params.clone()) - ), - NodeError::InvalidCDNNodePubKey - ); - - // Host length exceeds limit - assert_noop!( - DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(CDNNodeParams { - host: vec![1u8; 256], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }) - ), - Error::::HostLenExceedsLimit - ); - - // Node created - assert_ok!(DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) - )); - - // Check storage - assert!(CDNNodes::::contains_key(node_pub_key.clone())); - assert!(DdcNodes::exists(&NodePubKey::CDNPubKey(node_pub_key.clone()))); - if let Ok(cluster_id) = - DdcNodes::get_cluster_id(&NodePubKey::CDNPubKey(node_pub_key.clone())) - { - assert_eq!(cluster_id, None); - } - let cdn_node = DdcNodes::cdn_nodes(&node_pub_key).unwrap(); - assert_eq!(cdn_node.pub_key, node_pub_key); - - // Node already exists - assert_noop!( - DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params) - ), - Error::::NodeAlreadyExists - ); - - // Checking that event was emitted - assert_eq!(System::events().len(), 1); - System::assert_last_event( - Event::NodeCreated { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), - ) - }) -} - -#[test] -fn create_cdn_node_with_node_creator() { - ExtBuilder.build_and_execute(|| { - System::set_block_number(1); - let bytes = [0u8; 32]; - let node_pub_key = AccountId32::from(bytes); - let cdn_node_params = CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; - - // Node created - assert_ok!(>::create_node( - NodePubKey::CDNPubKey(node_pub_key.clone()), - 1u64, - NodeParams::CDNParams(cdn_node_params) - )); - - // Check storage - assert!(CDNNodes::::contains_key(node_pub_key.clone())); - assert!(DdcNodes::exists(&NodePubKey::CDNPubKey(node_pub_key.clone()))); - if let Ok(cluster_id) = - DdcNodes::get_cluster_id(&NodePubKey::CDNPubKey(node_pub_key.clone())) - { - assert_eq!(cluster_id, None); - } - let cdn_node = DdcNodes::cdn_nodes(&node_pub_key).unwrap(); - assert_eq!(cdn_node.pub_key, node_pub_key); - }) -} - #[test] fn create_storage_node_works() { ExtBuilder.build_and_execute(|| { @@ -140,31 +18,6 @@ fn create_storage_node_works() { p2p_port: 15000u16, }; - // Node params are not valid - assert_noop!( - DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::StoragePubKey(node_pub_key.clone()), - NodeParams::CDNParams(CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }) - ), - Error::::InvalidNodeParams - ); - - // Pub key invalid - assert_noop!( - StorageNode::::new( - NodePubKey::CDNPubKey(node_pub_key.clone()), - 1u64, - NodeParams::StorageParams(storage_node_params.clone()) - ), - NodeError::InvalidStorageNodePubKey - ); - // Host length exceeds limit assert_noop!( DdcNodes::create_node( @@ -244,123 +97,8 @@ fn create_storage_node_with_node_creator() { { assert_eq!(cluster_id, None); } - let cdn_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); - assert_eq!(cdn_node.pub_key, node_pub_key); - }) -} - -#[test] -fn set_cdn_node_params_works() { - ExtBuilder.build_and_execute(|| { - System::set_block_number(1); - let bytes = [0u8; 32]; - let node_pub_key = AccountId32::from(bytes); - let storage_node_params = StorageNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; - let cdn_node_params = CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; - - // Node doesn't exist - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) - ), - Error::::NodeDoesNotExist - ); - - // Node created - assert_ok!(DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) - )); - - // Set node params - assert_ok!(DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) - )); - - // Node params are not valid - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::StorageParams(storage_node_params) - ), - Error::::InvalidNodeParams - ); - - // Only node provider can set params - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(2), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params.clone()) - ), - Error::::OnlyNodeProvider - ); - - // CDN host length exceeds limit - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(CDNNodeParams { - host: vec![1u8; 256], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }) - ), - Error::::HostLenExceedsLimit - ); - - let bytes_2 = [1u8; 32]; - let node_pub_key_2 = AccountId32::from(bytes_2); - let node = Node::::new( - NodePubKey::CDNPubKey(node_pub_key_2), - 2u64, - NodeParams::CDNParams(cdn_node_params), - ) - .unwrap(); - - // Update should fail if node doesn't exist - assert_noop!( - >::update(node), - NodeRepositoryError::CDNNodeDoesNotExist - ); - - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(CDNNodeParams { - host: vec![1u8; 256], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }) - ), - Error::::HostLenExceedsLimit - ); - - // Checking that event was emitted - assert_eq!(System::events().len(), 2); - System::assert_last_event( - Event::NodeParamsChanged { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), - ) + let storage_node = DdcNodes::storage_nodes(&node_pub_key).unwrap(); + assert_eq!(storage_node.pub_key, node_pub_key); }) } @@ -376,12 +114,6 @@ fn set_storage_node_params_works() { grpc_port: 25000u16, p2p_port: 15000u16, }; - let cdn_node_params = CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; // Node doesn't exist assert_noop!( @@ -407,16 +139,6 @@ fn set_storage_node_params_works() { NodeParams::StorageParams(storage_node_params.clone()) )); - // Node params are not valid - assert_noop!( - DdcNodes::set_node_params( - RuntimeOrigin::signed(1), - NodePubKey::StoragePubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params) - ), - Error::::InvalidNodeParams - ); - // Only node provider can set params assert_noop!( DdcNodes::set_node_params( @@ -466,58 +188,6 @@ fn set_storage_node_params_works() { }) } -#[test] -fn delete_cdn_node_works() { - ExtBuilder.build_and_execute(|| { - System::set_block_number(1); - let bytes = [0u8; 32]; - let node_pub_key = AccountId32::from(bytes); - let cdn_node_params = CDNNodeParams { - host: vec![1u8, 255], - http_port: 35000u16, - grpc_port: 25000u16, - p2p_port: 15000u16, - }; - - // Node doesn't exist - assert_noop!( - DdcNodes::delete_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()) - ), - Error::::NodeDoesNotExist - ); - - // Create node - assert_ok!(DdcNodes::create_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - NodeParams::CDNParams(cdn_node_params) - )); - - // Only node provider can delete - assert_noop!( - DdcNodes::delete_node( - RuntimeOrigin::signed(2), - NodePubKey::CDNPubKey(node_pub_key.clone()) - ), - Error::::OnlyNodeProvider - ); - - // Delete node - assert_ok!(DdcNodes::delete_node( - RuntimeOrigin::signed(1), - NodePubKey::CDNPubKey(node_pub_key.clone()), - )); - - // Checking that event was emitted - assert_eq!(System::events().len(), 2); - System::assert_last_event( - Event::NodeDeleted { node_pub_key: NodePubKey::CDNPubKey(node_pub_key) }.into(), - ) - }) -} - #[test] fn delete_storage_node_works() { ExtBuilder.build_and_execute(|| { diff --git a/pallets/ddc-nodes/src/weights.rs b/pallets/ddc-nodes/src/weights.rs index 868380f40..776e717a0 100644 --- a/pallets/ddc-nodes/src/weights.rs +++ b/pallets/ddc-nodes/src/weights.rs @@ -1,27 +1,22 @@ - -//! Autogenerated weights for `pallet_ddc_nodes` +//! 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: `` -//! EXECUTION: None, WASM-EXECUTION: Interpreted, CHAIN: Some("dev"), DB CACHE: 1024 +//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, 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 +// --chain=dev +// --execution=wasm +// --pallet=pallet-ddc-nodes +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --template=./.maintain/frame-weight-template.hbs +// --output=pallets/ddc-nodes/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -37,47 +32,49 @@ pub trait WeightInfo { fn set_node_params() -> Weight; } -/// Weights for pallet_ddc_nodes. +/// Weights for pallet_ddc_nodes using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - // Storage: DdcNodes CDNNodes (r:1 w:1) +impl WeightInfo for SubstrateWeight { + // Storage: DdcNodes StorageNodes (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)) + Weight::from_ref_time(13_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:0) 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)) + Weight::from_ref_time(17_000_000_u64) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (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)) + Weight::from_ref_time(16_000_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (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)) + Weight::from_ref_time(13_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (r:1 w:1) + // Storage: DdcStaking Nodes (r:1 w:0) fn delete_node() -> Weight { - Weight::from_ref_time(14_000_000u64) - .saturating_add(RocksDbWeight::get().reads(1u64)) - .saturating_add(RocksDbWeight::get().writes(1u64)) + Weight::from_ref_time(17_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } - // Storage: DdcNodes CDNNodes (r:1 w:1) + // Storage: DdcNodes StorageNodes (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)) + Weight::from_ref_time(16_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } \ No newline at end of file diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index 4a1a9047e..5b5b50d58 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -1231,7 +1231,7 @@ fn send_rewarding_providers_batch_works() { }; let node_usage1 = NodeUsage { - // CDN + // Storage 1 transferred_bytes: usage1.transferred_bytes * 2 / 3, stored_bytes: 0, number_of_puts: usage1.number_of_puts * 2 / 3, @@ -1239,7 +1239,7 @@ fn send_rewarding_providers_batch_works() { }; let node_usage2 = NodeUsage { - // Storage + // Storage 2 transferred_bytes: 0, stored_bytes: usage1.stored_bytes * 2, number_of_puts: 0, @@ -1247,7 +1247,7 @@ fn send_rewarding_providers_batch_works() { }; let node_usage3 = NodeUsage { - // CDN + Storage + // Storage 1 + Storage 2 transferred_bytes: usage1.transferred_bytes * 2, stored_bytes: usage1.stored_bytes * 3, number_of_puts: usage1.number_of_puts * 2, diff --git a/pallets/ddc-payouts/src/weights.rs b/pallets/ddc-payouts/src/weights.rs index e4764f492..5f0578c31 100644 --- a/pallets/ddc-payouts/src/weights.rs +++ b/pallets/ddc-payouts/src/weights.rs @@ -1,12 +1,12 @@ //! Autogenerated weights for pallet_ddc_payouts //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: -// ./target/debug/cere +// ./target/release/cere // benchmark // pallet // --chain=dev @@ -15,7 +15,7 @@ // --extrinsic=* // --steps=50 // --repeat=20 -// --template=./.maintain/frame-weight-template-clippy.hbs +// --template=./.maintain/frame-weight-template.hbs // --output=pallets/ddc-payouts/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -43,20 +43,20 @@ pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { // Storage: DdcPayouts AuthorisedCaller (r:0 w:1) fn set_authorised_caller() -> Weight { - Weight::from_ref_time(251_000_000_u64) + Weight::from_ref_time(11_000_000_u64) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_billing_report() -> Weight { - Weight::from_ref_time(466_000_000_u64) + Weight::from_ref_time(19_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_charging_customers() -> Weight { - Weight::from_ref_time(440_000_000_u64) + Weight::from_ref_time(19_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -68,9 +68,9 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcPayouts DebtorCustomers (r:1 w:1) /// The range of component `b` is `[1, 1000]`. fn send_charging_customers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(1_267_000_000_u64) - // Standard Error: 3_691_054 - .saturating_add(Weight::from_ref_time(557_422_673_u64).saturating_mul(b as u64)) + Weight::from_ref_time(12_333_820_u64) + // Standard Error: 298_759 + .saturating_add(Weight::from_ref_time(24_367_120_u64).saturating_mul(b as u64)) .saturating_add(T::DbWeight::get().reads(7_u64)) .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(b as u64))) .saturating_add(T::DbWeight::get().writes(5_u64)) @@ -84,14 +84,14 @@ impl WeightInfo for SubstrateWeight { // Storage: Staking CounterForValidators (r:1 w:0) // Storage: Staking Validators (r:2 w:0) fn end_charging_customers() -> Weight { - Weight::from_ref_time(1_978_000_000_u64) + Weight::from_ref_time(89_000_000_u64) .saturating_add(T::DbWeight::get().reads(10_u64)) .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_rewarding_providers() -> Weight { - Weight::from_ref_time(446_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -100,9 +100,9 @@ impl WeightInfo for SubstrateWeight { // Storage: System Account (r:2 w:2) /// The range of component `b` is `[1, 1000]`. fn send_rewarding_providers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(758_000_000_u64) - // Standard Error: 148_210 - .saturating_add(Weight::from_ref_time(336_218_526_u64).saturating_mul(b as u64)) + Weight::from_ref_time(32_000_000_u64) + // Standard Error: 5_087 + .saturating_add(Weight::from_ref_time(14_402_776_u64).saturating_mul(b as u64)) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(b as u64))) .saturating_add(T::DbWeight::get().writes(2_u64)) @@ -111,14 +111,14 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_rewarding_providers() -> Weight { - Weight::from_ref_time(458_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_billing_report() -> Weight { - Weight::from_ref_time(449_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -128,20 +128,20 @@ impl WeightInfo for SubstrateWeight { impl WeightInfo for () { // Storage: DdcPayouts AuthorisedCaller (r:0 w:1) fn set_authorised_caller() -> Weight { - Weight::from_ref_time(251_000_000_u64) + Weight::from_ref_time(11_000_000_u64) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_billing_report() -> Weight { - Weight::from_ref_time(466_000_000_u64) + Weight::from_ref_time(19_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_charging_customers() -> Weight { - Weight::from_ref_time(440_000_000_u64) + Weight::from_ref_time(19_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -153,9 +153,9 @@ impl WeightInfo for () { // Storage: DdcPayouts DebtorCustomers (r:1 w:1) /// The range of component `b` is `[1, 1000]`. fn send_charging_customers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(1_267_000_000_u64) - // Standard Error: 3_691_054 - .saturating_add(Weight::from_ref_time(557_422_673_u64).saturating_mul(b as u64)) + Weight::from_ref_time(12_333_820_u64) + // Standard Error: 298_759 + .saturating_add(Weight::from_ref_time(24_367_120_u64).saturating_mul(b as u64)) .saturating_add(RocksDbWeight::get().reads(7_u64)) .saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(b as u64))) .saturating_add(RocksDbWeight::get().writes(5_u64)) @@ -169,14 +169,14 @@ impl WeightInfo for () { // Storage: Staking CounterForValidators (r:1 w:0) // Storage: Staking Validators (r:2 w:0) fn end_charging_customers() -> Weight { - Weight::from_ref_time(1_978_000_000_u64) + Weight::from_ref_time(89_000_000_u64) .saturating_add(RocksDbWeight::get().reads(10_u64)) .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn begin_rewarding_providers() -> Weight { - Weight::from_ref_time(446_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -185,9 +185,9 @@ impl WeightInfo for () { // Storage: System Account (r:2 w:2) /// The range of component `b` is `[1, 1000]`. fn send_rewarding_providers_batch(b: u32, ) -> Weight { - Weight::from_ref_time(758_000_000_u64) - // Standard Error: 148_210 - .saturating_add(Weight::from_ref_time(336_218_526_u64).saturating_mul(b as u64)) + Weight::from_ref_time(32_000_000_u64) + // Standard Error: 5_087 + .saturating_add(Weight::from_ref_time(14_402_776_u64).saturating_mul(b as u64)) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(b as u64))) .saturating_add(RocksDbWeight::get().writes(2_u64)) @@ -196,15 +196,15 @@ impl WeightInfo for () { // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_rewarding_providers() -> Weight { - Weight::from_ref_time(458_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcPayouts AuthorisedCaller (r:1 w:0) // Storage: DdcPayouts ActiveBillingReports (r:1 w:1) fn end_billing_report() -> Weight { - Weight::from_ref_time(449_000_000_u64) + Weight::from_ref_time(18_000_000_u64) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } -} +} \ No newline at end of file diff --git a/pallets/ddc-staking/README.md b/pallets/ddc-staking/README.md index f8ac2385a..2db79884a 100644 --- a/pallets/ddc-staking/README.md +++ b/pallets/ddc-staking/README.md @@ -4,13 +4,12 @@ The DDC Staking module is used to manage funds at stake by Cere DDC participants ## Overview -The DDC Staking module is the means by which an account can voluntarily place funds under deposit to join DDC CDN or storage network. +The DDC Staking module is the means by which an account can voluntarily place funds under deposit to join DDC network. ### Terminology - DDC Staking: The process of locking up funds for some time in order to become a participant of the DDC. - Stash account: The account holding an owner's funds used for staking. - Controller account: The account that controls an owner's funds for staking. -- CDN: CDN network participant. - Storage: Storage network participant. - Era: A time period of DDC participants activity data capture and accumulation which will further be used to calculate pay outs. diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index 37eb110a1..60a84e05b 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::{CDNNodeParams, CDNNodePubKey, NodeParams, NodeType, StorageNodePubKey}; +use ddc_primitives::{NodeParams, NodeType, StorageNodeParams, StorageNodePubKey}; use testing_utils::*; use frame_support::traits::Currency; @@ -22,11 +22,11 @@ benchmarks! { let controller = create_funded_user::("controller", USER_SEED, 100); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); - let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + let node = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); let _ = T::NodeCreator::create_node( node.clone(), stash.clone(), - NodeParams::CDNParams(CDNNodeParams { + NodeParams::StorageParams(StorageNodeParams { host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, @@ -44,7 +44,7 @@ benchmarks! { unbond { // clean up any existing state. - clear_storages_and_cdns::(); + clear_activated_nodes::(); let (stash, controller, _) = create_stash_controller_node::(0, 100)?; let ledger = Ledger::::get(&controller).ok_or("ledger not created before")?; @@ -76,7 +76,7 @@ benchmarks! { store { 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)?; + let (stash, controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::Storage).unwrap_or(100u128), node_pub_key)?; whitelist_account!(controller); }: _(RawOrigin::Signed(controller), ClusterId::from([1; 20])) @@ -84,32 +84,23 @@ benchmarks! { assert!(Storages::::contains_key(&stash)); } - serve { - 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])) - verify { - assert!(CDNs::::contains_key(&stash)); - } chill { // clean up any existing state. - clear_storages_and_cdns::(); + clear_activated_nodes::(); - 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)); + let node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); + let (storage_stash, storage_controller, _) = create_stash_controller_node_with_balance::(0, T::ClusterVisitor::get_bond_size(&ClusterId::from([1; 20]), NodeType::Storage).unwrap_or(10u128), node_pub_key)?; + DdcStaking::::store(RawOrigin::Signed(storage_controller.clone()).into(), ClusterId::from([1; 20]))?; + assert!(Storages::::contains_key(&storage_stash)); frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32)); - DdcStaking::::chill(RawOrigin::Signed(cdn_controller.clone()).into())?; - frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32) + T::ClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or_else(|_| T::BlockNumber::from(10u32))); + DdcStaking::::chill(RawOrigin::Signed(storage_controller.clone()).into())?; + frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32) + T::ClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::Storage).unwrap_or_else(|_| T::BlockNumber::from(10u32))); - whitelist_account!(cdn_controller); - }: _(RawOrigin::Signed(cdn_controller)) + whitelist_account!(storage_controller); + }: _(RawOrigin::Signed(storage_controller)) verify { - assert!(!CDNs::::contains_key(&cdn_stash)); + assert!(!Storages::::contains_key(&storage_stash)); } set_controller { @@ -124,7 +115,7 @@ benchmarks! { set_node { let (stash, _, _) = create_stash_controller_node::(USER_SEED, 100)?; - let new_node = NodePubKey::CDNPubKey(CDNNodePubKey::new([1; 32])); + let new_node = NodePubKey::StoragePubKey(StorageNodePubKey::new([1; 32])); whitelist_account!(stash); }: _(RawOrigin::Signed(stash), new_node.clone()) verify { diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index d7bbad30e..f9e09fcd3 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -1,6 +1,6 @@ //! # DDC Staking Pallet //! -//! The DDC Staking pallet is used to manage funds at stake by CDN and storage network maintainers. +//! The DDC Staking pallet is used to manage funds at stake by DDC network maintainers. //! //! - [`Config`] //! - [`Call`] @@ -181,12 +181,6 @@ pub mod pallet { pub type Ledger = StorageMap<_, Blake2_128Concat, T::AccountId, StakingLedger, T>>; - /// The map of (wannabe) CDN nodes participants stash keys to the DDC cluster ID they wish to - /// participate into. - #[pallet::storage] - #[pallet::getter(fn cdns)] - pub type CDNs = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; - /// The map of (wannabe) Storage nodes participants stash keys to the DDC cluster ID they /// wish to participate into. #[pallet::storage] @@ -208,15 +202,8 @@ pub mod pallet { #[pallet::getter(fn leaving_storages)] pub type LeavingStorages = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; - // Map of CDN node provider stash accounts that aim to leave a cluster - #[pallet::storage] - #[pallet::getter(fn leaving_cdns)] - pub type LeavingCDNs = StorageMap<_, Twox64Concat, T::AccountId, ClusterId>; - #[pallet::genesis_config] pub struct GenesisConfig { - #[allow(clippy::type_complexity)] - pub cdns: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, #[allow(clippy::type_complexity)] pub storages: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, } @@ -224,31 +211,13 @@ pub mod pallet { #[cfg(feature = "std")] impl Default for GenesisConfig { fn default() -> Self { - GenesisConfig { cdns: Default::default(), storages: Default::default() } + GenesisConfig { storages: Default::default() } } } #[pallet::genesis_build] impl GenesisBuild for GenesisConfig { fn build(&self) { - // Add initial CDN participants - for &(ref stash, ref controller, ref node, balance, cluster) in &self.cdns { - assert!( - T::Currency::free_balance(stash) >= balance, - "Stash do not have enough balance to participate in CDN." - ); - assert_ok!(Pallet::::bond( - T::RuntimeOrigin::from(Some(stash.clone()).into()), - T::Lookup::unlookup(controller.clone()), - node.clone(), - balance, - )); - assert_ok!(Pallet::::serve( - T::RuntimeOrigin::from(Some(controller.clone()).into()), - cluster, - )); - } - // Add initial storage network participants for &(ref stash, ref controller, ref node, balance, cluster) in &self.storages { assert!( @@ -282,20 +251,20 @@ pub mod pallet { /// An account has called `withdraw_unbonded` and removed unbonding chunks worth `Balance` /// from the unlocking queue. \[stash, amount\] Withdrawn(T::AccountId, BalanceOf), - /// An account has stopped participating as either a storage network or CDN participant. + /// An account has stopped participating as DDC network participant. /// \[stash\] Chilled(T::AccountId), - /// An account has declared desire to stop participating in CDN or storage network soon. + /// An account has declared desire to stop participating in DDC network soon. /// \[stash, cluster, block\] ChillSoon(T::AccountId, ClusterId, T::BlockNumber), - /// An account that started participating as either a storage network or CDN participant. + /// An account that started participating as DDC network participant. /// \[stash\] Activated(T::AccountId), /// An account that started unbonding tokens below the minimum value set for the cluster - /// his CDN or Storage node is assigned to \[stash\] + /// his DDC node is assigned to \[stash\] LeaveSoon(T::AccountId), /// An account that unbonded tokens below the minimum value set for the cluster his - /// CDN or Storage node was assigned to \[stash\] + /// DDC node was assigned to \[stash\] Left(T::AccountId), } @@ -309,9 +278,9 @@ pub mod pallet { AlreadyBonded, /// Controller or node is already paired. AlreadyPaired, - /// Cannot have a storage network or CDN participant, with the size less than defined by + /// Cannot have a DDC network participant, with the size less than defined by /// governance (see `BondSize`). If unbonding is the intention, `chill` first to remove - /// one's role as storage/cdn node. + /// one's role as activated DDC node. InsufficientBond, /// Can not schedule more unlock chunks. NoMoreChunks, @@ -332,8 +301,6 @@ pub mod pallet { NoClusterGovParams, /// Conditions for fast chill are not met, try the regular `chill` from FastChillProhibited, - /// Serving operation is called for non-CDN node - ServingProhibited, /// Storing operation is called for non-Storage node StoringProhibited, /// Arithmetic overflow occurred @@ -457,11 +424,7 @@ pub mod pallet { ledger.active = Zero::zero(); } - let min_active_bond = if let Some(cluster_id) = Self::cdns(&ledger.stash) { - let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::CDN) - .map_err(Into::>::into)?; - bond_size.saturated_into::>() - } else if let Some(cluster_id) = Self::storages(&ledger.stash) { + let min_active_bond = if let Some(cluster_id) = Self::storages(&ledger.stash) { let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::Storage) .map_err(Into::>::into)?; @@ -488,7 +451,6 @@ pub mod pallet { .map_err(Into::>::into)?; let min_bond_size = match node_pub_key { - NodePubKey::CDNPubKey(_) => bonding_params.cdn_bond_size, NodePubKey::StoragePubKey(_) => bonding_params.storage_bond_size, }; @@ -496,8 +458,6 @@ pub mod pallet { // cluster eventually, we keep its stake till the end of unbonding period. if ledger.active < min_bond_size.saturated_into::>() { match node_pub_key { - NodePubKey::CDNPubKey(_) => - LeavingCDNs::::insert(ledger.stash.clone(), cluster_id), NodePubKey::StoragePubKey(_) => LeavingStorages::::insert(ledger.stash.clone(), cluster_id), }; @@ -506,7 +466,6 @@ pub mod pallet { }; match node_pub_key { - NodePubKey::CDNPubKey(_) => bonding_params.cdn_unbonding_delay, NodePubKey::StoragePubKey(_) => bonding_params.storage_unbonding_delay, } } else { @@ -582,15 +541,12 @@ pub mod pallet { // If provider aimed to leave the cluster and the unbonding period ends, remove // the node from the cluster - if let Some(cluster_id) = - >::get(&stash).or_else(|| >::get(&stash)) - { + if let Some(cluster_id) = >::get(&stash) { // Cluster manager could remove the node from cluster by this moment already, so // it is ok to ignore result. let _ = T::ClusterManager::remove_node(&cluster_id, &node_pub_key); >::remove(&stash); - >::remove(&stash); Self::deposit_event(Event::::Left(stash)); } @@ -599,59 +555,6 @@ pub mod pallet { Ok(()) } - /// Declare the desire to participate in CDN for the origin controller. Also works to cancel - /// a previous "chill". - /// - /// `cluster` is the ID of the DDC cluster the participant wishes to join. - /// - /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. The - /// bond size must be greater than or equal to the `CDNBondSize`. - #[pallet::weight(T::WeightInfo::serve())] - pub fn serve(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { - let controller = ensure_signed(origin)?; - - T::ClusterVisitor::ensure_cluster(&cluster_id).map_err(Into::>::into)?; - - let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; - // Retrieve the respective bond size from Cluster Visitor - let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::CDN) - .map_err(Into::>::into)?; - - ensure!( - ledger.active >= bond_size.saturated_into::>(), - Error::::InsufficientBond - ); - let stash = &ledger.stash; - - // Can't participate in CDN if already participating in storage network. - ensure!(!Storages::::contains_key(stash), Error::::AlreadyInRole); - - // Only CDN node can perform serving (i.e. streaming content) - let node_pub_key = >::get(stash).ok_or(Error::::BadState)?; - ensure!( - matches!(node_pub_key, NodePubKey::CDNPubKey(_)), - Error::::ServingProhibited - ); - - // Is it an attempt to cancel a previous "chill"? - if let Some(current_cluster) = Self::cdns(stash) { - // Switching the cluster is prohibited. The user should chill first. - ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); - // Cancel previous "chill" attempts - Self::reset_chilling(&controller); - return Ok(()) - } else { - // Can't participate in new CDN network if provider hasn't left the previous cluster - // yet - ensure!(!LeavingCDNs::::contains_key(stash), Error::::NodeIsLeaving); - } - - Self::do_add_cdn(stash, cluster_id); - Self::deposit_event(Event::::Activated(stash.clone())); - - Ok(()) - } - /// Declare the desire to participate in storage network for the origin controller. Also /// works to cancel a previous "chill". /// @@ -675,9 +578,6 @@ pub mod pallet { ); let stash = &ledger.stash; - // Can't participate in storage network if already participating in CDN. - ensure!(!CDNs::::contains_key(stash), Error::::AlreadyInRole); - // Only Storage node can perform storing (i.e. saving content) let node_pub_key = >::get(stash).ok_or(Error::::BadState)?; ensure!( @@ -704,15 +604,15 @@ pub mod pallet { Ok(()) } - /// Declare no desire to either participate in storage network or CDN. + /// Declare no desire to either participate in DDC network. /// /// Only in case the delay for the role _origin_ maintains in the cluster is set to zero in /// cluster settings, it removes the participant immediately. Otherwise, it requires at /// least two invocations to effectively remove the participant. The first invocation only /// updates the [`Ledger`] to note the block number at which the participant may "chill" /// (current block + the delay from the cluster settings). The second invocation made at the - /// noted block (or any further block) will remove the participant from the list of CDN or - /// storage network participants. If the cluster settings updated significantly decreasing + /// noted block (or any further block) will remove the participant from the list of DDC + /// network participants. If the cluster settings updated significantly decreasing /// the delay, one may invoke it again to decrease the block at with the participant may /// "chill". But it never increases the block at which the participant may "chill" even when /// the cluster settings updated increasing the delay. @@ -727,11 +627,7 @@ pub mod pallet { let current_block = >::block_number(); // Extract delay from the cluster settings. - let (cluster, delay) = if let Some(cluster) = Self::cdns(&ledger.stash) { - let chill_delay = T::ClusterVisitor::get_chill_delay(&cluster, NodeType::CDN) - .map_err(Into::>::into)?; - (cluster, chill_delay) - } else if let Some(cluster) = Self::storages(&ledger.stash) { + let (cluster, delay) = if let Some(cluster) = Self::storages(&ledger.stash) { let chill_delay = T::ClusterVisitor::get_chill_delay(&cluster, NodeType::Storage) .map_err(Into::>::into)?; (cluster, chill_delay) @@ -813,12 +709,10 @@ pub mod pallet { } // Ensure only one node per stash. - ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); ensure!(!>::contains_key(&stash), Error::::AlreadyInRole); // Ensure that provider is not about leaving the cluster as it may cause the removal // of an unexpected node after unbonding. - ensure!(!>::contains_key(&stash), Error::::NodeIsLeaving); ensure!(!>::contains_key(&stash), Error::::NodeIsLeaving); >::insert(new_node.clone(), stash.clone()); @@ -839,9 +733,7 @@ pub mod pallet { let node_stash = >::get(&node_pub_key).ok_or(Error::::BadState)?; ensure!(stash == node_stash, Error::::NotNodeController); - let cluster_id = >::get(&stash) - .or_else(|| >::get(&stash)) - .ok_or(Error::::NodeHasNoStake)?; + let cluster_id = >::get(&stash).ok_or(Error::::NodeHasNoStake)?; let is_cluster_node = T::ClusterManager::contains_node(&cluster_id, &node_pub_key); ensure!(!is_cluster_node, Error::::FastChillProhibited); @@ -875,8 +767,7 @@ pub mod pallet { /// Chill a stash account. fn chill_stash(stash: &T::AccountId) { let chilled_as_storage = Self::do_remove_storage(stash); - let chilled_as_cdn = Self::do_remove_cdn(stash); - if chilled_as_storage || chilled_as_cdn { + if chilled_as_storage { Self::deposit_event(Event::::Chilled(stash.clone())); } } @@ -914,27 +805,12 @@ pub mod pallet { }; Self::do_remove_storage(stash); - Self::do_remove_cdn(stash); frame_system::Pallet::::dec_consumers(stash); Ok(()) } - /// This function will add a CDN participant to the `CDNs` storage map. - /// - /// If the CDN participant already exists, their cluster will be updated. - pub fn do_add_cdn(who: &T::AccountId, cluster: ClusterId) { - CDNs::::insert(who, cluster); - } - - /// This function will remove a CDN participant from the `CDNs` map. - /// - /// Returns true if `who` was removed from `CDNs`, otherwise false. - pub fn do_remove_cdn(who: &T::AccountId) -> bool { - CDNs::::take(who).is_some() - } - /// This function will add a storage network participant to the `Storages` storage map. /// /// If the storage network participant already exists, their cluster will be updated. @@ -983,7 +859,6 @@ pub mod pallet { Self::update_ledger(&controller, &item); match node { NodePubKey::StoragePubKey(_node) => Self::do_add_storage(&stash, cluster_id), - NodePubKey::CDNPubKey(_node) => Self::do_add_cdn(&stash, cluster_id), } Ok(()) @@ -997,11 +872,9 @@ pub mod pallet { ) -> Result { let stash = >::get(node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; - let maybe_cdn_in_cluster = CDNs::::get(&stash); let maybe_storage_in_cluster = Storages::::get(&stash); - let has_activated_stake: bool = maybe_cdn_in_cluster - .or(maybe_storage_in_cluster) + let has_activated_stake: bool = maybe_storage_in_cluster .is_some_and(|staking_cluster| staking_cluster == *cluster_id); Ok(has_activated_stake) diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index c1aa469f5..75ff7684b 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -4,8 +4,8 @@ use crate::{self as pallet_ddc_staking, *}; use ddc_primitives::{ - CDNNodePubKey, ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterParams, - ClusterPricingParams, NodeParams, NodePubKey, StorageNodePubKey, + ClusterBondingParams, ClusterFeesParams, ClusterGovParams, ClusterParams, ClusterPricingParams, + NodeParams, NodePubKey, StorageNodePubKey, }; use ddc_traits::{ cluster::{ClusterManager, ClusterManagerError, ClusterVisitor, ClusterVisitorError}, @@ -195,21 +195,6 @@ impl ClusterVisitor for TestClusterVisitor { cluster_id: &ClusterId, ) -> Result, ClusterVisitorError> { Ok(ClusterBondingParams { - cdn_bond_size: >::get_bond_size( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), - cdn_chill_delay: >::get_chill_delay( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), - cdn_unbonding_delay: >::get_unbonding_delay( - cluster_id, - NodeType::CDN, - ) - .unwrap_or_default(), storage_bond_size: >::get_bond_size( cluster_id, NodeType::Storage, @@ -301,30 +286,18 @@ impl NodeVisitor for MockNodeVisitor { } pub struct ExtBuilder { - has_cdns: bool, has_storages: bool, stakes: BTreeMap, - cdns: Vec<(AccountId, AccountId, Balance, ClusterId)>, storages: Vec<(AccountId, AccountId, Balance, ClusterId)>, } impl Default for ExtBuilder { fn default() -> Self { - Self { - has_cdns: true, - has_storages: true, - stakes: Default::default(), - cdns: Default::default(), - storages: Default::default(), - } + Self { has_storages: true, stakes: Default::default(), storages: Default::default() } } } impl ExtBuilder { - pub fn has_cdns(mut self, has: bool) -> Self { - self.has_cdns = has; - self - } pub fn has_storages(mut self, has: bool) -> Self { self.has_storages = has; self @@ -333,16 +306,6 @@ impl ExtBuilder { self.stakes.insert(who, stake); self } - pub fn add_cdn( - mut self, - stash: AccountId, - controller: AccountId, - stake: Balance, - cluster: ClusterId, - ) -> Self { - self.cdns.push((stash, controller, stake, cluster)); - self - } pub fn add_storage( mut self, stash: AccountId, @@ -363,45 +326,37 @@ impl ExtBuilder { (2, 100), (3, 100), (4, 100), - // cdn controllers + // storage controllers (10, 100), (20, 100), - // storage controllers (30, 100), (40, 100), - // cdn stashes + // storage stashes (11, 100), (21, 100), - // storage stashes (31, 100), (41, 100), ], } .assimilate_storage(&mut storage); - let mut cdns = vec![]; - if self.has_cdns { - cdns = vec![ + let mut storages = vec![]; + if self.has_storages { + storages = vec![ // (stash, controller, node, stake, cluster) ( 11, 10, - NodePubKey::CDNPubKey(CDNNodePubKey::new([12; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([12; 32])), 100, ClusterId::from([1; 20]), ), ( 21, 20, - NodePubKey::CDNPubKey(CDNNodePubKey::new([22; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([22; 32])), 100, ClusterId::from([1; 20]), ), - ]; - } - let mut storages = vec![]; - if self.has_storages { - storages = vec![ - // (stash, controller, node, stake, cluster) ( 31, 30, @@ -419,8 +374,8 @@ impl ExtBuilder { ]; } - let _ = pallet_ddc_staking::GenesisConfig:: { cdns, storages } - .assimilate_storage(&mut storage); + let _ = + pallet_ddc_staking::GenesisConfig:: { storages }.assimilate_storage(&mut storage); TestExternalities::new(storage) } diff --git a/pallets/ddc-staking/src/testing_utils.rs b/pallets/ddc-staking/src/testing_utils.rs index 7dec075cc..666e20779 100644 --- a/pallets/ddc-staking/src/testing_utils.rs +++ b/pallets/ddc-staking/src/testing_utils.rs @@ -2,8 +2,7 @@ use crate::{Pallet as DdcStaking, *}; use ddc_primitives::{ - CDNNodeParams, CDNNodePubKey, ClusterGovParams, ClusterId, ClusterParams, NodeParams, - StorageNodeParams, + ClusterGovParams, ClusterId, ClusterParams, NodeParams, StorageNodeParams, StorageNodePubKey, }; use frame_benchmarking::account; @@ -15,11 +14,10 @@ use sp_std::prelude::*; const SEED: u32 = 0; -/// This function removes all storage and CDN nodes from storage. -pub fn clear_storages_and_cdns() { +/// This function removes all storage and Storages nodes from storage. +pub fn clear_activated_nodes() { #[allow(unused_must_use)] { - CDNs::::clear(u32::MAX, None); Storages::::clear(u32::MAX, None); } } @@ -57,12 +55,12 @@ pub fn create_stash_controller_node( let controller = create_funded_user::("controller", n, balance_factor); let controller_lookup: ::Source = T::Lookup::unlookup(controller.clone()); - let node = NodePubKey::CDNPubKey(CDNNodePubKey::new([0; 32])); + let node = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32])); T::NodeCreator::create_node( node.clone(), stash.clone(), - NodeParams::CDNParams(CDNNodeParams { + NodeParams::StorageParams(StorageNodeParams { host: vec![1u8, 255], http_port: 35000u16, grpc_port: 25000u16, @@ -92,21 +90,9 @@ pub fn create_stash_controller_node_with_balance( 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), + ddc_primitives::NodePubKey::StoragePubKey(node_pub_key), stash.clone(), NodeParams::StorageParams(StorageNodeParams { host: vec![1u8, 255], @@ -124,9 +110,6 @@ pub fn create_stash_controller_node_with_balance( treasury_share: Perquintill::default(), validators_share: Perquintill::default(), cluster_reserve_share: Perquintill::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(), diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 358b736ce..53f400101 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -1,8 +1,7 @@ //! Tests for the module. use super::{mock::*, *}; -use ddc_primitives::{CDNNodePubKey, StorageNodePubKey}; - +use ddc_primitives::StorageNodePubKey; use frame_support::{assert_noop, assert_ok, traits::ReservableCurrency}; use pallet_balances::Error as BalancesError; @@ -81,11 +80,11 @@ fn change_controller_works() { // 10 is no longer in control. assert_noop!( - DdcStaking::serve(RuntimeOrigin::signed(10), ClusterId::from([1; 20])), + DdcStaking::store(RuntimeOrigin::signed(10), ClusterId::from([1; 20])), Error::::NotController ); // 3 is a new controller. - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(3), ClusterId::from([1; 20]))); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(3), ClusterId::from([1; 20]))); }) } @@ -94,17 +93,17 @@ fn not_enough_inital_bond_flow() { ExtBuilder::default().build_and_execute(|| { System::set_block_number(1); - // Add new CDN participant, account 3 controlled by 4 with node 5. + // Add new Storage participant, account 3 controlled by 4 with node 5. assert_ok!(DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 5 )); // Not enough tokens bonded to serve assert_noop!( - DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20])), + DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20])), Error::::InsufficientBond ); @@ -127,7 +126,7 @@ fn not_enough_inital_bond_flow() { DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 5 ), Error::::AlreadyBonded @@ -145,12 +144,12 @@ fn not_enough_inital_bond_flow() { assert_ok!(DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 10 )); // Serving should work - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); }) } @@ -159,15 +158,15 @@ fn unbonding_edge_cases_work() { ExtBuilder::default().build_and_execute(|| { System::set_block_number(1); - // Add new CDN participant, account 3 controlled by 4 with node 5. + // Add new Storage participant, account 3 controlled by 4 with node 5. assert_ok!(DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 100 )); - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); assert_ok!(DdcStaking::unbond(RuntimeOrigin::signed(4), 1)); while System::block_number() < 33 { @@ -180,41 +179,6 @@ fn unbonding_edge_cases_work() { }) } -#[test] -fn serve_or_store_should_be_prohibited() { - ExtBuilder::default().build_and_execute(|| { - System::set_block_number(1); - - // Add new CDN participant, account 3 controlled by 4 with node 5. - assert_ok!(DdcStaking::bond( - RuntimeOrigin::signed(3), - 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), - 100 - )); - - // Add new Storage participant, account 1 controlled by 2 with node 3. - assert_ok!(DdcStaking::bond( - RuntimeOrigin::signed(1), - 2, - NodePubKey::StoragePubKey(StorageNodePubKey::new([3; 32])), - 100 - )); - - // Not enough tokens bonded to serve - assert_noop!( - DdcStaking::serve(RuntimeOrigin::signed(2), ClusterId::from([1; 20])), - Error::::ServingProhibited - ); - - // Not enough tokens bonded to store - assert_noop!( - DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20])), - Error::::StoringProhibited - ); - }) -} - #[test] fn set_node_works() { ExtBuilder::default().build_and_execute(|| { @@ -226,7 +190,7 @@ fn set_node_works() { assert_noop!( DdcStaking::set_node( RuntimeOrigin::signed(10), - NodePubKey::CDNPubKey(CDNNodePubKey::new([12; 32])) + NodePubKey::StoragePubKey(StorageNodePubKey::new([12; 32])) ), Error::::AlreadyPaired ); @@ -235,21 +199,21 @@ fn set_node_works() { assert_noop!( DdcStaking::set_node( RuntimeOrigin::signed(11), - NodePubKey::CDNPubKey(CDNNodePubKey::new([12; 32])) + NodePubKey::StoragePubKey(StorageNodePubKey::new([12; 32])) ), Error::::AlreadyInRole ); - // Schedule CDN participant removal. + // Schedule Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(10))); System::set_block_number(11); - // Actual CDN participant removal. + // Actual Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(10))); // Setting node should work assert_ok!(DdcStaking::set_node( RuntimeOrigin::signed(11), - NodePubKey::CDNPubKey(CDNNodePubKey::new([13; 32])) + NodePubKey::StoragePubKey(StorageNodePubKey::new([13; 32])) )); }) } @@ -260,11 +224,11 @@ fn cancel_previous_chill_works() { System::set_block_number(1); let cluster_id = ClusterId::from([1; 20]); - // Add new CDN participant, account 3 controlled by 4 with node 5. + // Add new Storage participant, account 3 controlled by 4 with node 5. assert_ok!(DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 100 )); @@ -277,16 +241,16 @@ fn cancel_previous_chill_works() { )); // Not enough tokens bonded to serve - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), cluster_id)); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), cluster_id)); assert_ok!(DdcStaking::store(RuntimeOrigin::signed(2), ClusterId::from([1; 20]))); - // Schedule CDN participant removal. + // Schedule Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); // Not enough tokens bonded to serve - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), cluster_id)); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), cluster_id)); - // Schedule CDN participant removal. + // Schedule Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(2))); // Not enough tokens bonded to serve assert_ok!(DdcStaking::store(RuntimeOrigin::signed(2), cluster_id)); @@ -308,21 +272,21 @@ fn staking_should_work() { DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 0 ), Error::::InsufficientBond ); - // Add new CDN participant, account 3 controlled by 4 with node 5. + // Add new Storage participant, account 3 controlled by 4 with node 5. assert_ok!(DdcStaking::bond( RuntimeOrigin::signed(3), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 1500 )); System::assert_last_event(Event::Bonded(3, 1500).into()); - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([0; 20]))); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([0; 20]))); System::assert_last_event(Event::Activated(3).into()); // Controller already paired @@ -330,7 +294,7 @@ fn staking_should_work() { DdcStaking::bond( RuntimeOrigin::signed(5), 4, - NodePubKey::CDNPubKey(CDNNodePubKey::new([10; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([10; 32])), 10 ), Error::::AlreadyPaired @@ -341,13 +305,13 @@ fn staking_should_work() { DdcStaking::bond( RuntimeOrigin::signed(5), 6, - NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])), + NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])), 10 ), Error::::AlreadyPaired ); - // Account 4 controls the stash from account 3, which is 1500 units, 3 is a CDN + // Account 4 controls the stash from account 3, which is 1500 units, 3 is a Storage // participant, 5 is a DDC node. assert_eq!(DdcStaking::bonded(&3), Some(4)); assert_eq!( @@ -360,19 +324,22 @@ fn staking_should_work() { unlocking: Default::default(), }) ); - assert_eq!(DdcStaking::cdns(3), Some(ClusterId::from([0; 20]))); - assert_eq!(DdcStaking::nodes(NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32]))), Some(3)); + assert_eq!(DdcStaking::storages(3), Some(ClusterId::from([0; 20]))); + assert_eq!( + DdcStaking::nodes(NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32]))), + Some(3) + ); // Set initial block timestamp. Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); - // Schedule CDN participant removal. + // Schedule Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); System::assert_last_event(Event::ChillSoon(3, ClusterId::from([0; 20]), 11).into()); // Removal is scheduled, stashed value of 4 is still lock. let chilling = System::block_number() + 10u64; - // TestClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN) + // TestClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::Storage) // .unwrap_or(10_u64); assert_eq!( DdcStaking::ledger(&4), @@ -415,92 +382,12 @@ fn staking_should_work() { }) ); - // Actual CDN participant removal. + // Actual Storage participant removal. assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); System::assert_last_event(Event::Chilled(3).into()); - // Account 3 is no longer a CDN participant. - assert_eq!(DdcStaking::cdns(3), None); - }); -} - -#[test] -fn cdn_full_unbonding_works() { - ExtBuilder::default().build_and_execute(|| { - System::set_block_number(1); - - let provider_stash: u64 = 1; - let provider_controller: u64 = 2; - let cluster_id = ClusterId::from([1; 20]); - let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([1; 32])); - - let lock = MockNodeVisitor::set_and_hold_lock(MockNode { - cluster_id: Some(cluster_id), - exists: true, - }); - - let cdn_bond_size = 10_u128; - let cdn_chill_delay = 10_u64; - let cdn_unbond_delay = 10_u64; - - // Put some money in account that we'll use. - let _ = Balances::make_free_balance_be(&provider_controller, 2000); - let _ = Balances::make_free_balance_be(&provider_stash, 2000); - - // Add new CDN participant, account 1 controlled by 2 with node 1. - assert_ok!(DdcStaking::bond( - RuntimeOrigin::signed(provider_stash), - provider_controller, - node_pub_key.clone(), - cdn_bond_size, // min bond size - )); - System::assert_last_event(Event::Bonded(provider_stash, cdn_bond_size).into()); - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(provider_controller), cluster_id)); - System::assert_last_event(Event::Activated(provider_stash).into()); - - assert_eq!(DdcStaking::cdns(provider_stash), Some(cluster_id)); - assert_eq!(DdcStaking::nodes(node_pub_key), Some(provider_stash)); - - // Set block timestamp. - Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); - - // Schedule CDN participant removal. - assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(provider_controller))); - let chilling = System::block_number() + cdn_chill_delay; - System::assert_last_event(Event::ChillSoon(provider_stash, cluster_id, chilling).into()); - - // Set the block number that allows us to chill. - while System::block_number() < chilling { - System::set_block_number(System::block_number() + 1); - Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); - } - - // Actual CDN participant removal. - assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(provider_controller))); - System::assert_last_event(Event::Chilled(provider_stash).into()); - - // Account is no longer a CDN participant. - assert_eq!(DdcStaking::cdns(provider_stash), None); - - // Start unbonding all tokens - assert_ok!(DdcStaking::unbond(RuntimeOrigin::signed(provider_controller), cdn_bond_size)); - System::assert_has_event(Event::LeaveSoon(provider_stash).into()); - assert_eq!(DdcStaking::leaving_cdns(provider_stash), Some(cluster_id)); - System::assert_last_event(Event::Unbonded(provider_stash, cdn_bond_size).into()); - - let unbonding = System::block_number() + cdn_unbond_delay; - // Set the block number that allows us to chill. - while System::block_number() < unbonding { - System::set_block_number(System::block_number() + 1); - Timestamp::set_timestamp(System::block_number() * BLOCK_TIME + INIT_TIMESTAMP); - } - - assert_ok!(DdcStaking::withdraw_unbonded(RuntimeOrigin::signed(provider_controller))); - System::assert_has_event(Event::Withdrawn(provider_stash, cdn_bond_size).into()); - assert_eq!(DdcStaking::leaving_cdns(provider_stash), None); - System::assert_last_event(Event::Left(provider_stash).into()); - - MockNodeVisitor::reset_and_release_lock(lock); + // Account 3 is no longer a Storage participant. + assert_eq!(DdcStaking::storages(3), None); }); } @@ -595,18 +482,7 @@ fn staking_creator_works() { let controller: u64 = 2; let cluster_id = ClusterId::from([1; 20]); let value = 5; - let cdn_node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([2; 32])); - let storage_node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([2; 32])); - - assert_ok!( - >>::bond_stake_and_participate( - stash, - controller, - cdn_node_pub_key, - value, - cluster_id, - ) - ); + let storage_node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([2; 32])); assert_ok!( >>::bond_stake_and_participate( @@ -625,9 +501,9 @@ fn staking_visitor_works() { // Verifies initial conditions of mock ExtBuilder::default().build_and_execute(|| { let cluster_id = ClusterId::from([1; 20]); - let node_pub_key = NodePubKey::CDNPubKey(CDNNodePubKey::new([5; 32])); + let node_pub_key = NodePubKey::StoragePubKey(StorageNodePubKey::new([5; 32])); - // Add new CDN participant, account 3 controlled by 4 with node 5. + // Add new Storage participant, account 3 controlled by 4 with node 5. assert_ok!(DdcStaking::bond(RuntimeOrigin::signed(3), 4, node_pub_key.clone(), 100)); assert!(>::has_stake(&node_pub_key,)); @@ -638,7 +514,7 @@ fn staking_visitor_works() { assert!(!result); } - assert_ok!(DdcStaking::serve(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); + assert_ok!(DdcStaking::store(RuntimeOrigin::signed(4), ClusterId::from([1; 20]))); if let Ok(result) = >::has_activated_stake(&node_pub_key, &cluster_id) diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index 5437d12a2..e7157a60d 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -1,8 +1,8 @@ //! Autogenerated weights for pallet_ddc_staking //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-10-10, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! HOSTNAME: `e14`, CPU: `11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz` +//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -10,14 +10,13 @@ // benchmark // pallet // --chain=dev +// --execution=wasm +// --pallet=pallet-ddc-staking +// --extrinsic=* // --steps=50 // --repeat=20 -// --pallet=pallet_ddc_staking -// --extrinsic=* -// --execution=wasm -// --wasm-execution=compiled // --template=./.maintain/frame-weight-template.hbs -// --output=./pallets/ddc-staking/src +// --output=pallets/ddc-staking/src/weights.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -32,7 +31,6 @@ pub trait WeightInfo { fn unbond() -> Weight; fn withdraw_unbonded() -> Weight; fn store() -> Weight; - fn serve() -> Weight; fn chill() -> Weight; fn set_controller() -> Weight; fn set_node() -> Weight; @@ -45,93 +43,67 @@ impl WeightInfo for SubstrateWeight { // 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: DdcNodes StorageNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(37_000_000_u64) + Weight::from_ref_time(39_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 Providers (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:0) + // Storage: DdcNodes StorageNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(38_000_000_u64) - .saturating_add(T::DbWeight::get().reads(7_u64)) + Weight::from_ref_time(37_000_000_u64) + .saturating_add(T::DbWeight::get().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // 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 { - // Minimum execution time: 33_000 nanoseconds. - Weight::from_ref_time(34_000_000_u64) - .saturating_add(T::DbWeight::get().reads(6_u64)) + Weight::from_ref_time(33_000_000_u64) + .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (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 { - // 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: 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 { - // 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().reads(6_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CDNs (r:1 w:1) + // Storage: DdcStaking Storages (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:1 w:0) - // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - // 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().reads(3_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 { - // Minimum execution time: 12_000 nanoseconds. - Weight::from_ref_time(13_000_000_u64) + Weight::from_ref_time(14_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: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 { - // 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().reads(4_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) } } @@ -142,93 +114,67 @@ impl WeightInfo for () { // 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: DdcNodes StorageNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - // Minimum execution time: 35_000 nanoseconds. - Weight::from_ref_time(37_000_000_u64) + Weight::from_ref_time(39_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 Providers (r:1 w:0) - // Storage: DdcNodes CDNNodes (r:1 w:0) + // Storage: DdcNodes StorageNodes (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - // Minimum execution time: 37_000 nanoseconds. - Weight::from_ref_time(38_000_000_u64) - .saturating_add(RocksDbWeight::get().reads(7_u64)) + Weight::from_ref_time(37_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // 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 { - // Minimum execution time: 33_000 nanoseconds. - Weight::from_ref_time(34_000_000_u64) - .saturating_add(RocksDbWeight::get().reads(6_u64)) + Weight::from_ref_time(33_000_000_u64) + .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcClusters Clusters (r:1 w:0) // Storage: DdcStaking Ledger (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 { - // 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: 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 { - // 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().reads(6_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) - // Storage: DdcStaking CDNs (r:1 w:1) + // Storage: DdcStaking Storages (r:1 w:1) // Storage: DdcClusters ClustersGovParams (r:1 w:0) - // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - // 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().reads(3_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 { - // Minimum execution time: 12_000 nanoseconds. - Weight::from_ref_time(13_000_000_u64) + Weight::from_ref_time(14_000_000_u64) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } // 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 { - // 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().reads(4_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } -} +} \ No newline at end of file diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 456c33299..a15d20071 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -11,7 +11,6 @@ pub type ClusterId = H160; pub type DdcEra = u32; pub type BucketId = u64; pub type StorageNodePubKey = AccountId32; -pub type CDNNodePubKey = AccountId32; // ClusterParams includes Governance non-sensetive parameters only #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] @@ -27,9 +26,6 @@ pub struct ClusterGovParams { pub treasury_share: Perquintill, pub validators_share: Perquintill, pub cluster_reserve_share: Perquintill, - pub cdn_bond_size: Balance, - pub cdn_chill_delay: BlockNumber, - pub cdn_unbonding_delay: BlockNumber, pub storage_bond_size: Balance, pub storage_chill_delay: BlockNumber, pub storage_unbonding_delay: BlockNumber, @@ -56,9 +52,6 @@ pub struct ClusterFeesParams { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub struct ClusterBondingParams { - pub cdn_bond_size: u128, - pub cdn_chill_delay: BlockNumber, - pub cdn_unbonding_delay: BlockNumber, pub storage_bond_size: u128, pub storage_chill_delay: BlockNumber, pub storage_unbonding_delay: BlockNumber, @@ -68,20 +61,17 @@ pub struct ClusterBondingParams { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodePubKey { StoragePubKey(StorageNodePubKey), - CDNPubKey(CDNNodePubKey), } #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeType { Storage = 1, - CDN = 2, } impl From for u8 { fn from(node_type: NodeType) -> Self { match node_type { NodeType::Storage => 1, - NodeType::CDN => 2, } } } @@ -91,20 +81,11 @@ impl TryFrom for NodeType { fn try_from(value: u8) -> Result { match value { 1 => Ok(NodeType::Storage), - 2 => Ok(NodeType::CDN), _ => Err(()), } } } -#[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, @@ -117,5 +98,4 @@ pub struct StorageNodeParams { #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeParams { StorageParams(StorageNodeParams), - CDNParams(CDNNodeParams), }