From 54953240c6ce931e47d0a10cb8f9510714bf6032 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Mon, 13 Nov 2023 20:41:38 +0100 Subject: [PATCH] fix(pallet_ddc_staking): checking node type before making node active for specific ddc action --- pallets/ddc-staking/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 9c8469785..d68cadab8 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -303,6 +303,10 @@ pub mod pallet { NoClusterGovParams, /// Conditions for fast chill are not met, try the regular `chill` from FastChillProhibited, + /// Serving operation is called for non-CDN node + ServingProhibited, + /// Storing operation is called for non-Storage node + StoringProhibited, } #[pallet::call] @@ -544,6 +548,13 @@ pub mod pallet { // Can't participate in CDN if already participating in storage network. ensure!(!Storages::::contains_key(stash), Error::::AlreadyInRole); + // Only CDN node can perform serving (i.e. streaming content) + let node_pub_key = >::get(&stash).ok_or(Error::::BadState)?; + ensure!( + matches!(node_pub_key, NodePubKey::CDNPubKey(_)), + Error::::ServingProhibited + ); + // Is it an attempt to cancel a previous "chill"? if let Some(current_cluster) = Self::cdns(stash) { // Switching the cluster is prohibited. The user should chill first. @@ -583,6 +594,13 @@ pub mod pallet { // Can't participate in storage network if already participating in CDN. ensure!(!CDNs::::contains_key(stash), Error::::AlreadyInRole); + // Only Storage node can perform storing (i.e. saving content) + let node_pub_key = >::get(&stash).ok_or(Error::::BadState)?; + ensure!( + matches!(node_pub_key, NodePubKey::StoragePubKey(_)), + Error::::StoringProhibited + ); + // Is it an attempt to cancel a previous "chill"? if let Some(current_cluster) = Self::storages(stash) { // Switching the cluster is prohibited. The user should chill first.