Skip to content

Commit

Permalink
CDN node type is removed (#197)
Browse files Browse the repository at this point in the history
This PR removes the CDN node type from the protocol as now the DDC
network uses Storage nodes with enabled cache mode instead of CDN nodes
  • Loading branch information
yahortsaryk authored Dec 15, 2023
1 parent 4861b4b commit b09be69
Show file tree
Hide file tree
Showing 29 changed files with 446 additions and 1,429 deletions.
5 changes: 0 additions & 5 deletions node/service/chain-specs/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@
"maxMembers": 512
},
"ddcStaking": {
"cdns": [],
"storages": []
},
"ddcCustomers": {
Expand All @@ -183,7 +182,6 @@
}
}
],
"cdnNodes": []
},
"ddcClusters": {
"clusters": [
Expand All @@ -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,
Expand Down
126 changes: 60 additions & 66 deletions pallets/ddc-clusters/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,93 +22,87 @@ benchmarks! {
T::AccountId: UncheckedFrom<T::Hash> + AsRef<[u8]> }

create_cluster {
let cluster_id = ClusterId::from([1; 20]);
let cluster_id = ClusterId::from([1; 20]);
let user = account::<T::AccountId>("user", USER_SEED, 0u32);
let cluster_params = ClusterParams { node_provider_auth_contract: Some(user.clone()) };
let cluster_gov_params: ClusterGovParams<BalanceOf<T>, T::BlockNumber> = ClusterGovParams {
treasury_share: Perbill::default(),
validators_share: Perbill::default(),
cluster_reserve_share: Perbill::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<BalanceOf<T>, T::BlockNumber> = ClusterGovParams {
treasury_share: Perbill::default(),
validators_share: Perbill::default(),
cluster_reserve_share: Perbill::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::<T>::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::<T::AccountId>("user", USER_SEED, 0u32);
let balance = <T as pallet::Config>::Currency::minimum_balance() * 1_000_000u32.into();
let _ = <T as pallet::Config>::Currency::make_free_balance_be(&user, balance);
let _ = config_cluster_and_node::<T>(user.clone(), node_pub_key.clone(), cluster_id);
}: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone())
verify {
assert!(ClustersNodes::<T>::contains_key(cluster_id, node_pub_key));
}
let balance = <T as pallet::Config>::Currency::minimum_balance() * 1_000_000u32.into();
let _ = <T as pallet::Config>::Currency::make_free_balance_be(&user, balance);
let _ = config_cluster_and_node::<T>(user.clone(), node_pub_key.clone(), cluster_id);
}: _(RawOrigin::Signed(user.clone()), cluster_id, node_pub_key.clone())
verify {
assert!(ClustersNodes::<T>::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::<T::AccountId>("user", USER_SEED, 0u32);
let balance = <T as pallet::Config>::Currency::minimum_balance() * 1_000_000u32.into();
let _ = <T as pallet::Config>::Currency::make_free_balance_be(&user, balance);
let _ = config_cluster_and_node::<T>(user.clone(), node_pub_key.clone(), cluster_id);
let _ = DdcClusters::<T>::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::<T>::contains_key(cluster_id, node_pub_key));
}
let balance = <T as pallet::Config>::Currency::minimum_balance() * 1_000_000u32.into();
let _ = <T as pallet::Config>::Currency::make_free_balance_be(&user, balance);
let _ = config_cluster_and_node::<T>(user.clone(), node_pub_key.clone(), cluster_id);
let _ = DdcClusters::<T>::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::<T>::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::<T::AccountId>("user", USER_SEED, 0u32);
let user_2 = account::<T::AccountId>("user", USER_SEED_2, 0u32);
let _ = config_cluster::<T>(user.clone(), cluster_id);
let new_cluster_params = ClusterParams { node_provider_auth_contract: Some(user_2.clone()) };
let _ = config_cluster::<T>(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::<T>::try_get(cluster_id).unwrap().props, ClusterProps { node_provider_auth_contract: Some(user_2) });
assert_eq!(Clusters::<T>::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::<T::AccountId>("user", USER_SEED, 0u32);
let _ = config_cluster::<T>(user, cluster_id);
let new_cluster_gov_params: ClusterGovParams<BalanceOf<T>, T::BlockNumber> = ClusterGovParams {
treasury_share: Perbill::default(),
validators_share: Perbill::default(),
cluster_reserve_share: Perbill::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::<T>(user, cluster_id);
let new_cluster_gov_params: ClusterGovParams<BalanceOf<T>, T::BlockNumber> = ClusterGovParams {
treasury_share: Perbill::default(),
validators_share: Perbill::default(),
cluster_reserve_share: Perbill::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::<T>::try_get(cluster_id).unwrap(), new_cluster_gov_params);
assert_eq!(ClustersGovParams::<T>::try_get(cluster_id).unwrap(), new_cluster_gov_params);
}

impl_benchmark_test_suite!(
Expand Down
6 changes: 0 additions & 6 deletions pallets/ddc-clusters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ pub mod pallet {
match node_type {
NodeType::Storage =>
Ok(cluster_gov_params.storage_bond_size.saturated_into::<u128>()),
NodeType::CDN => Ok(cluster_gov_params.cdn_bond_size.saturated_into::<u128>()),
}
}

Expand Down Expand Up @@ -398,7 +397,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),
}
}

Expand All @@ -410,7 +408,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),
}
}

Expand All @@ -420,9 +417,6 @@ pub mod pallet {
let cluster_gov_params = ClustersGovParams::<T>::try_get(cluster_id)
.map_err(|_| ClusterVisitorError::ClusterGovParamsNotSet)?;
Ok(ClusterBondingParams {
cdn_bond_size: cluster_gov_params.cdn_bond_size.saturated_into::<u128>(),
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::<u128>(),
storage_chill_delay: cluster_gov_params.storage_chill_delay,
storage_unbonding_delay: cluster_gov_params.storage_unbonding_delay,
Expand Down
5 changes: 1 addition & 4 deletions pallets/ddc-clusters/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,6 @@ impl ExtBuilder {
treasury_share: Perbill::from_float(0.05),
validators_share: Perbill::from_float(0.01),
cluster_reserve_share: Perbill::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,
Expand All @@ -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::<Test>::default().build();
Expand Down
18 changes: 7 additions & 11 deletions pallets/ddc-clusters/src/testing_utils.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -24,9 +24,6 @@ where
treasury_share: Perbill::default(),
validators_share: Perbill::default(),
cluster_reserve_share: Perbill::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(),
Expand Down Expand Up @@ -55,7 +52,7 @@ where
T::AccountId: UncheckedFrom<T::Hash> + 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,
Expand All @@ -66,9 +63,6 @@ where
treasury_share: Perbill::default(),
validators_share: Perbill::default(),
cluster_reserve_share: Perbill::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(),
Expand All @@ -87,9 +81,11 @@ where
cluster_gov_params,
);

if let Ok(new_node) =
Node::<T>::new(node_pub_key.clone(), user.clone(), NodeParams::CDNParams(cdn_node_params))
{
if let Ok(new_node) = Node::<T>::new(
node_pub_key.clone(),
user.clone(),
NodeParams::StorageParams(storage_node_params),
) {
let _ = T::NodeRepository::create(new_node);
}

Expand Down
Loading

0 comments on commit b09be69

Please sign in to comment.