Skip to content

Commit

Permalink
Merge branch 'dev' into chore/cleanup-ddc-offchain
Browse files Browse the repository at this point in the history
  • Loading branch information
rakanalh authored Dec 18, 2023
2 parents b6332e4 + d970a49 commit a582c78
Show file tree
Hide file tree
Showing 31 changed files with 707 additions and 1,446 deletions.
7 changes: 6 additions & 1 deletion docs/genesis-state.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# State preset
# Genesis state

Sometimes we use the blockchain as a part of a test environment.
Those tests typically want a certain state of the blockchain.
Expand All @@ -22,6 +22,11 @@ And a _raw_ form with key-value pairs which will be written to the database.
1. Set genesis state for each module.
There is an example in `node/service/example.json`, you can copy everything except the `code` field value from it to the `plain.json`.

> Special note for a `ddcNodes.storageNodes.host` field.
> In the `example.json` it is set as:
> `"host": [ 49, 50, 55, 46, 48, 46, 48, 46, 49 ]`.
> Where the array is an encoded `127.0.0.1` value.

1. Create a raw form chain spec.

```console
Expand Down
20 changes: 13 additions & 7 deletions node/service/chain-specs/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@
"maxMembers": 512
},
"ddcStaking": {
"cdns": [],
"storages": []
},
"ddcCustomers": {
"buckets": [
[
"0x0000000000000000000000000000000000000001",
"5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",
10000000000
10000000000,
false
]
]
},
Expand All @@ -176,14 +176,23 @@
"provider_id": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"cluster_id": "0x0000000000000000000000000000000000000001",
"props": {
"host": [],
"host": [
49,
50,
55,
46,
48,
46,
48,
46,
49
],
"http_port": 8080,
"grpc_port": 8081,
"p2p_port": 8082
}
}
],
"cdnNodes": []
},
"ddcClusters": {
"clusters": [
Expand All @@ -203,9 +212,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
20 changes: 9 additions & 11 deletions 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::{
CDNNodeParams, ClusterGovParams, ClusterId, ClusterParams, NodeParams, NodePubKey,
ClusterGovParams, ClusterId, ClusterParams, NodeParams, NodePubKey, StorageNodeMode,
StorageNodeParams,
};
pub use frame_benchmarking::{
account, benchmarks, impl_benchmark_test_suite, whitelist_account, whitelisted_caller,
Expand All @@ -24,9 +25,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 +53,8 @@ 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 {
mode: StorageNodeMode::Storage,
host: vec![1u8, 255],
http_port: 35000u16,
grpc_port: 25000u16,
Expand All @@ -66,9 +65,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 +83,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 a582c78

Please sign in to comment.