Skip to content

Commit

Permalink
Operation mode for DDC Storage node type is added (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk authored Dec 18, 2023
1 parent d9312c5 commit d970a49
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 @@ -2,7 +2,7 @@

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 @@ -143,6 +143,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,5 +1,7 @@
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 @@ -30,6 +32,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 @@ -45,6 +48,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,6 +1,6 @@
//! Testing utils for ddc-staking.

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

Expand All @@ -16,13 +16,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,6 +1,6 @@
//! Tests for the module.

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

Expand All @@ -13,6 +13,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 @@ -25,6 +26,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 @@ -77,6 +79,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 @@ -110,6 +113,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 @@ -171,6 +175,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 @@ -196,6 +201,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
@@ -1,6 +1,6 @@
//! DdcStaking pallet benchmarking.

use ddc_primitives::{NodeParams, NodeType, StorageNodeParams, StorageNodePubKey};
use ddc_primitives::{NodeParams, NodeType, StorageNodeMode, StorageNodeParams, StorageNodePubKey};
pub use frame_benchmarking::{
account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller,
};
Expand All @@ -26,6 +26,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
@@ -1,7 +1,8 @@
//! Testing utils for ddc-staking.

use ddc_primitives::{
ClusterGovParams, ClusterId, ClusterParams, NodeParams, StorageNodeParams, StorageNodePubKey,
ClusterGovParams, ClusterId, ClusterParams, NodeParams, StorageNodeMode, StorageNodeParams,
StorageNodePubKey,
};
use frame_benchmarking::account;
use frame_support::traits::Currency;
Expand Down Expand Up @@ -60,6 +61,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 @@ -94,6 +96,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 @@ -85,8 +85,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 d970a49

Please sign in to comment.