Skip to content

Commit

Permalink
chore: PR #200 is backported
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Dec 18, 2023
1 parent ccb8315 commit e6b3852
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 16 deletions.
4 changes: 3 additions & 1 deletion pallets/ddc-clusters/src/testing_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! DdcStaking pallet benchmarking.

use ddc_primitives::{
ClusterGovParams, ClusterId, ClusterParams, NodeParams, NodePubKey, StorageNodeParams,
ClusterGovParams, ClusterId, ClusterParams, NodeParams, NodePubKey, StorageNodeMode,
StorageNodeParams,
};
pub use frame_benchmarking::{
account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller,
Expand Down Expand Up @@ -53,6 +54,7 @@ where
{
let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) };
let storage_node_params = StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8, 255],
http_port: 35000u16,
grpc_port: 25000u16,
Expand Down
3 changes: 2 additions & 1 deletion pallets/ddc-clusters/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::{mock::*, *};
use ddc_primitives::{
ClusterBondingParams, ClusterFeesParams, ClusterId, ClusterParams, ClusterPricingParams,
NodeParams, NodePubKey, StorageNodeParams,
NodeParams, NodePubKey, StorageNodeMode, StorageNodeParams,
};
use ddc_traits::cluster::ClusterManager;
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
Expand Down Expand Up @@ -142,6 +142,7 @@ fn add_and_delete_node_works() {
);

let storage_node_params = StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8, 255],
http_port: 35000u16,
grpc_port: 25000u16,
Expand Down
3 changes: 2 additions & 1 deletion pallets/ddc-nodes/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! DdcStaking pallet benchmarking.

use ddc_primitives::StorageNodePubKey;
use ddc_primitives::{StorageNodeMode, StorageNodePubKey};
pub use frame_benchmarking::{
account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller,
};
Expand Down Expand Up @@ -45,6 +45,7 @@ benchmarks! {
assert_eq!(StorageNodes::<T>::try_get(
StorageNodePubKey::new([0; 32])).unwrap().props,
StorageNodeProps {
mode: StorageNodeMode::Storage,
host: vec![2u8, 255].try_into().unwrap(),
http_port: 45000u16,
grpc_port: 55000u16,
Expand Down
6 changes: 5 additions & 1 deletion pallets/ddc-nodes/src/storage_node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::node::{NodeError, NodeProps, NodeTrait};
use codec::{Decode, Encode};
use ddc_primitives::{ClusterId, NodeParams, NodePubKey, NodeType, StorageNodePubKey};
use ddc_primitives::{
ClusterId, NodeParams, NodePubKey, NodeType, StorageNodeMode, StorageNodePubKey,
};
use frame_support::{parameter_types, BoundedVec};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -29,6 +31,7 @@ pub struct StorageNodeProps {
pub http_port: u16,
pub grpc_port: u16,
pub p2p_port: u16,
pub mode: StorageNodeMode,
}

impl<T: frame_system::Config> StorageNode<T> {
Expand All @@ -44,6 +47,7 @@ impl<T: frame_system::Config> StorageNode<T> {
pub_key,
cluster_id: None,
props: StorageNodeProps {
mode: node_params.mode,
host: match node_params.host.try_into() {
Ok(vec) => vec,
Err(_) => return Err(NodeError::StorageHostLenExceedsLimit),
Expand Down
4 changes: 3 additions & 1 deletion pallets/ddc-nodes/src/testing_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Testing utils for ddc-staking.

use crate::{Config, NodePubKey};
use ddc_primitives::{NodeParams, StorageNodeParams, StorageNodePubKey};
use ddc_primitives::{NodeParams, StorageNodeMode, StorageNodeParams, StorageNodePubKey};
use frame_benchmarking::account;
use sp_std::vec;

Expand All @@ -15,13 +15,15 @@ pub fn create_user_and_config<T: Config>(
let user = account(string, n, SEED);
let node = NodePubKey::StoragePubKey(StorageNodePubKey::new([0; 32]));
let storage_node_params = NodeParams::StorageParams(StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8, 255],
http_port: 35000u16,
grpc_port: 25000u16,
p2p_port: 15000u16,
});

let new_storage_node_params = NodeParams::StorageParams(StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![2u8, 255],
http_port: 45000u16,
grpc_port: 55000u16,
Expand Down
8 changes: 7 additions & 1 deletion pallets/ddc-nodes/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Tests for the module.

use super::{mock::*, *};
use ddc_primitives::{NodePubKey, StorageNodeParams};
use ddc_primitives::{NodePubKey, StorageNodeMode, StorageNodeParams};
use frame_support::{assert_noop, assert_ok};
use sp_runtime::AccountId32;

Expand All @@ -12,6 +12,7 @@ fn create_storage_node_works() {
let bytes = [0u8; 32];
let node_pub_key = AccountId32::from(bytes);
let storage_node_params = StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8, 255],
http_port: 35000u16,
grpc_port: 25000u16,
Expand All @@ -24,6 +25,7 @@ fn create_storage_node_works() {
RuntimeOrigin::signed(1),
NodePubKey::StoragePubKey(node_pub_key.clone()),
NodeParams::StorageParams(StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8; 256],
http_port: 35000u16,
grpc_port: 25000u16,
Expand Down Expand Up @@ -76,6 +78,7 @@ fn create_storage_node_with_node_creator() {
let bytes = [0u8; 32];
let node_pub_key = AccountId32::from(bytes);
let storage_node_params = StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8, 255],
http_port: 35000u16,
grpc_port: 25000u16,
Expand Down Expand Up @@ -109,6 +112,7 @@ fn set_storage_node_params_works() {
let bytes = [0u8; 32];
let node_pub_key = AccountId32::from(bytes);
let storage_node_params = StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8, 255],
http_port: 35000u16,
grpc_port: 25000u16,
Expand Down Expand Up @@ -170,6 +174,7 @@ fn set_storage_node_params_works() {
RuntimeOrigin::signed(1),
NodePubKey::StoragePubKey(node_pub_key.clone()),
NodeParams::StorageParams(StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8; 256],
http_port: 35000u16,
grpc_port: 25000u16,
Expand All @@ -195,6 +200,7 @@ fn delete_storage_node_works() {
let bytes = [0u8; 32];
let node_pub_key = AccountId32::from(bytes);
let storage_node_params = StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8, 255],
http_port: 35000u16,
grpc_port: 25000u16,
Expand Down
16 changes: 8 additions & 8 deletions pallets/ddc-nodes/src/weights.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Autogenerated weights for pallet_ddc_nodes
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-12-14, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-12-15, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `Yahors-MacBook-Pro.local`, CPU: `<UNKNOWN>`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

Expand Down Expand Up @@ -37,20 +37,20 @@ pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: DdcNodes StorageNodes (r:1 w:1)
fn create_node() -> Weight {
Weight::from_ref_time(13_000_000_u64)
Weight::from_ref_time(12_000_000_u64)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
// Storage: DdcNodes StorageNodes (r:1 w:1)
// Storage: DdcStaking Nodes (r:1 w:0)
fn delete_node() -> Weight {
Weight::from_ref_time(17_000_000_u64)
Weight::from_ref_time(16_000_000_u64)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
// Storage: DdcNodes StorageNodes (r:1 w:1)
fn set_node_params() -> Weight {
Weight::from_ref_time(16_000_000_u64)
Weight::from_ref_time(15_000_000_u64)
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
Expand All @@ -60,21 +60,21 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
impl WeightInfo for () {
// Storage: DdcNodes StorageNodes (r:1 w:1)
fn create_node() -> Weight {
Weight::from_ref_time(13_000_000_u64)
Weight::from_ref_time(12_000_000_u64)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
// Storage: DdcNodes StorageNodes (r:1 w:1)
// Storage: DdcStaking Nodes (r:1 w:0)
fn delete_node() -> Weight {
Weight::from_ref_time(17_000_000_u64)
Weight::from_ref_time(16_000_000_u64)
.saturating_add(RocksDbWeight::get().reads(2_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
// Storage: DdcNodes StorageNodes (r:1 w:1)
fn set_node_params() -> Weight {
Weight::from_ref_time(16_000_000_u64)
Weight::from_ref_time(15_000_000_u64)
.saturating_add(RocksDbWeight::get().reads(1_u64))
.saturating_add(RocksDbWeight::get().writes(1_u64))
}
}
}
3 changes: 2 additions & 1 deletion pallets/ddc-staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use super::*;
use crate::Pallet as DdcStaking;
use ddc_primitives::{NodeParams, NodeType, StorageNodeParams, StorageNodePubKey};
use ddc_primitives::{NodeParams, NodeType, StorageNodeMode, StorageNodeParams, StorageNodePubKey};
use testing_utils::*;

use frame_support::traits::Currency;
Expand All @@ -27,6 +27,7 @@ benchmarks! {
node.clone(),
stash.clone(),
NodeParams::StorageParams(StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8, 255],
http_port: 35000u16,
grpc_port: 25000u16,
Expand Down
5 changes: 4 additions & 1 deletion pallets/ddc-staking/src/testing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use crate::{Pallet as DdcStaking, *};
use ddc_primitives::{
ClusterGovParams, ClusterId, ClusterParams, NodeParams, StorageNodeParams, StorageNodePubKey,
ClusterGovParams, ClusterId, ClusterParams, NodeParams, StorageNodeMode, StorageNodeParams,
StorageNodePubKey,
};

use frame_benchmarking::account;
Expand Down Expand Up @@ -61,6 +62,7 @@ pub fn create_stash_controller_node<T: Config>(
node.clone(),
stash.clone(),
NodeParams::StorageParams(StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8, 255],
http_port: 35000u16,
grpc_port: 25000u16,
Expand Down Expand Up @@ -95,6 +97,7 @@ pub fn create_stash_controller_node_with_balance<T: Config>(
ddc_primitives::NodePubKey::StoragePubKey(node_pub_key),
stash.clone(),
NodeParams::StorageParams(StorageNodeParams {
mode: StorageNodeMode::Storage,
host: vec![1u8, 255],
http_port: 35000u16,
grpc_port: 25000u16,
Expand Down
12 changes: 12 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,20 @@ impl TryFrom<u8> for NodeType {
}
}

#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)]
pub enum StorageNodeMode {
/// DDC Storage node operates with enabled caching in RAM and stores data in Hard Drive
Full = 1,
/// DDC Storage node operates with disabled caching in RAM and stores data in Hard Drive
Storage = 2,
/// DDC Storage node operates with enabled caching in RAM and doesn't store data in Hard Drive
Cache = 3,
}

#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)]
pub struct StorageNodeParams {
pub mode: StorageNodeMode,
pub host: Vec<u8>,
pub http_port: u16,
pub grpc_port: u16,
Expand Down

0 comments on commit e6b3852

Please sign in to comment.