diff --git a/pallets/ddc-clusters/src/cluster.rs b/pallets/ddc-clusters/src/cluster.rs index 862c42ddf..7274fbf16 100644 --- a/pallets/ddc-clusters/src/cluster.rs +++ b/pallets/ddc-clusters/src/cluster.rs @@ -3,6 +3,8 @@ use codec::{Decode, Encode}; use ddc_primitives::ClusterId; use frame_support::{pallet_prelude::*, parameter_types, BoundedVec}; use scale_info::TypeInfo; +use sp_runtime::Perbill; +use sp_staking::EraIndex; use sp_std::vec::Vec; parameter_types! { @@ -31,6 +33,26 @@ pub struct ClusterParams { pub node_provider_auth_contract: AccountId, } +// ClusterGovParams includes Governance sensetive parameters +#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] +pub struct ClusterGovParams { + pub treasury_share: Perbill, + pub validators_share: Perbill, + pub cluster_reserve_share: Perbill, + #[codec(compact)] + pub cdn_bond_size: Balance, + pub cdn_chill_delay: EraIndex, + pub cdn_unbonding_delay: EraIndex, + #[codec(compact)] + pub storage_bond_size: Balance, + pub storage_chill_delay: EraIndex, + pub storage_unbonding_delay: EraIndex, + pub unit_per_mb_stored: u128, + pub unit_per_mb_streamed: u128, + pub unit_per_put_request: u128, + pub unit_per_get_request: u128, +} + impl Cluster { pub fn new( cluster_id: ClusterId, diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index 2d389b431..59ce7fb52 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -16,7 +16,7 @@ #![feature(is_some_and)] // ToDo: delete at rustc > 1.70 use crate::{ - cluster::{Cluster, ClusterError, ClusterParams}, + cluster::{Cluster, ClusterError, ClusterGovParams, ClusterParams}, node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError}, }; use ddc_primitives::{ClusterId, NodePubKey}; @@ -24,7 +24,10 @@ use ddc_traits::{ cluster::{ClusterVisitor, ClusterVisitorError}, staking::{StakingVisitor, StakingVisitorError}, }; -use frame_support::pallet_prelude::*; +use frame_support::{ + pallet_prelude::*, + traits::{Currency, LockableCurrency}, +}; use frame_system::pallet_prelude::*; pub use pallet::*; use pallet_ddc_nodes::{NodeRepository, NodeTrait}; @@ -33,6 +36,10 @@ use sp_std::prelude::*; mod cluster; mod node_provider_auth; +/// The balance type of this pallet. +pub type BalanceOf = + <::Currency as Currency<::AccountId>>::Balance; + #[frame_support::pallet] pub mod pallet { use super::*; @@ -48,6 +55,7 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; type NodeRepository: NodeRepository; // todo: get rid of tight coupling with nodes-pallet type StakingVisitor: StakingVisitor; + type Currency: LockableCurrency; } #[pallet::event] @@ -57,6 +65,7 @@ pub mod pallet { ClusterNodeAdded { cluster_id: ClusterId, node_pub_key: NodePubKey }, ClusterNodeRemoved { cluster_id: ClusterId, node_pub_key: NodePubKey }, ClusterParamsSet { cluster_id: ClusterId }, + ClusterGovParamsSet { cluster_id: ClusterId }, } #[pallet::error] @@ -82,6 +91,11 @@ pub mod pallet { pub type Clusters = StorageMap<_, Blake2_128Concat, ClusterId, Cluster>; + #[pallet::storage] + #[pallet::getter(fn clusters_gov_params)] + pub type ClustersGovParams = + StorageMap<_, Twox64Concat, ClusterId, ClusterGovParams>>; + #[pallet::storage] #[pallet::getter(fn clusters_nodes)] pub type ClustersNodes = StorageDoubleMap< @@ -204,6 +218,23 @@ pub mod pallet { Ok(()) } + + // Sets Governance sensetive parameters + #[pallet::weight(10_000)] + pub fn set_cluster_gov_params( + origin: OriginFor, + cluster_id: ClusterId, + cluster_gov_params: ClusterGovParams>, + ) -> DispatchResult { + let caller_id = ensure_signed(origin)?; + let cluster = + Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); + ClustersGovParams::::insert(cluster_id.clone(), cluster_gov_params); + Self::deposit_event(Event::::ClusterGovParamsSet { cluster_id }); + + Ok(()) + } } impl ClusterVisitor for Pallet { diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 58e95dab4..b2ff75c80 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -1357,6 +1357,7 @@ impl pallet_ddc_clusters::Config for Runtime { type RuntimeEvent = RuntimeEvent; type NodeRepository = pallet_ddc_nodes::Pallet; type StakingVisitor = pallet_ddc_staking::Pallet; + type Currency = Balances; } construct_runtime!(