Skip to content

Commit 04288e8

Browse files
authored
feat: add curator agent freezing toggling (#109)
Closes CHAIN-100
1 parent e94b5b1 commit 04288e8

File tree

14 files changed

+290
-69
lines changed

14 files changed

+290
-69
lines changed

pallets/emission0/src/weights.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
//! Autogenerated weights for `pallet_emission0`
33
//!
44
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0
5-
//! DATE: 2025-06-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
5+
//! DATE: 2025-06-18, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
66
//! WORST CASE MAP SIZE: `1000000`
7-
//! HOSTNAME: `Luizs-MacBook-Pro.local`, CPU: `<UNKNOWN>`
7+
//! HOSTNAME: `MacBook-Pro-de-Joao.local`, CPU: `<UNKNOWN>`
88
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024`
99
1010
// Executed Command:
@@ -94,7 +94,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
9494
// Proof Size summary in bytes:
9595
// Measured: `333`
9696
// Estimated: `3529`
97-
// Minimum execution time: 12_000_000 picoseconds.
97+
// Minimum execution time: 11_000_000 picoseconds.
9898
Weight::from_parts(12_000_000, 3529)
9999
.saturating_add(T::DbWeight::get().reads(2_u64))
100100
.saturating_add(T::DbWeight::get().writes(1_u64))
@@ -151,7 +151,7 @@ impl WeightInfo for () {
151151
// Proof Size summary in bytes:
152152
// Measured: `333`
153153
// Estimated: `3529`
154-
// Minimum execution time: 12_000_000 picoseconds.
154+
// Minimum execution time: 11_000_000 picoseconds.
155155
Weight::from_parts(12_000_000, 3529)
156156
.saturating_add(RocksDbWeight::get().reads(2_u64))
157157
.saturating_add(RocksDbWeight::get().writes(1_u64))

pallets/governance/api/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pub trait GovernanceApi<AccountId> {
1515

1616
fn set_allocator(key: &AccountId);
1717

18+
fn can_create_namespace(key: &AccountId) -> bool;
19+
20+
fn can_register_agent(key: &AccountId) -> bool;
21+
1822
#[doc(hidden)]
1923
#[cfg(feature = "runtime-benchmarks")]
2024
fn force_set_whitelisted(key: &AccountId);

pallets/governance/src/benchmarking.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,16 @@ mod benchmarks {
266266
data,
267267
)
268268
}
269+
270+
#[benchmark]
271+
fn toggle_agent_freezing() {
272+
#[extrinsic_call]
273+
toggle_agent_freezing(RawOrigin::Signed(curator::<T>()))
274+
}
275+
276+
#[benchmark]
277+
fn toggle_namespace_freezing() {
278+
#[extrinsic_call]
279+
toggle_namespace_freezing(RawOrigin::Signed(curator::<T>()))
280+
}
269281
}

pallets/governance/src/lib.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub mod pallet {
4444
const STORAGE_VERSION: StorageVersion = StorageVersion::new(5);
4545

4646
use pallet_permission0_api::{CuratorPermissions, Permission0Api, Permission0CuratorApi};
47+
use polkadot_sdk::sp_core::ConstBool;
4748
use proposal::GlobalParamsData;
4849
use weights::WeightInfo;
4950

@@ -101,6 +102,14 @@ pub mod pallet {
101102
pub type TreasuryEmissionFee<T: Config> =
102103
StorageValue<_, Percent, ValueQuery, T::DefaultTreasuryEmissionFee>;
103104

105+
/// Determines if new agents can be registered on the chain.
106+
#[pallet::storage]
107+
pub type AgentsFrozen<T: Config> = StorageValue<_, bool, ValueQuery, ConstBool<false>>;
108+
109+
/// Determines if new namespaces can be created on the chain.
110+
#[pallet::storage]
111+
pub type NamespacesFrozen<T: Config> = StorageValue<_, bool, ValueQuery, ConstBool<false>>;
112+
104113
#[pallet::config]
105114
pub trait Config:
106115
polkadot_sdk::frame_system::Config + pallet_torus0::Config + pallet_emission0::Config
@@ -378,6 +387,44 @@ pub mod pallet {
378387

379388
Ok(())
380389
}
390+
391+
#[pallet::call_index(19)]
392+
#[pallet::weight((<T as Config>::WeightInfo::toggle_agent_freezing(), DispatchClass::Normal, Pays::No))]
393+
pub fn toggle_agent_freezing(origin: OriginFor<T>) -> DispatchResult {
394+
let curator = <T as pallet::Config>::Permission0::ensure_curator_permission(
395+
origin,
396+
CuratorPermissions::AGENT_FREEZING_TOGGLING,
397+
)?;
398+
399+
let new_state = !crate::AgentsFrozen::<T>::get();
400+
AgentsFrozen::<T>::set(new_state);
401+
402+
crate::Pallet::<T>::deposit_event(crate::Event::AgentFreezingToggled {
403+
curator,
404+
new_state,
405+
});
406+
407+
Ok(())
408+
}
409+
410+
#[pallet::call_index(20)]
411+
#[pallet::weight((<T as Config>::WeightInfo::toggle_namespace_freezing(), DispatchClass::Normal, Pays::No))]
412+
pub fn toggle_namespace_freezing(origin: OriginFor<T>) -> DispatchResult {
413+
let curator = <T as pallet::Config>::Permission0::ensure_curator_permission(
414+
origin,
415+
CuratorPermissions::NAMESPACE_FREEZING_TOGGLING,
416+
)?;
417+
418+
let new_state = !crate::NamespacesFrozen::<T>::get();
419+
NamespacesFrozen::<T>::set(new_state);
420+
421+
crate::Pallet::<T>::deposit_event(crate::Event::NamespaceFreezingToggled {
422+
curator,
423+
new_state,
424+
});
425+
426+
Ok(())
427+
}
381428
}
382429

383430
#[pallet::event]
@@ -413,6 +460,16 @@ pub mod pallet {
413460
agent: T::AccountId,
414461
penalty: Percent,
415462
},
463+
/// The agent freezing feature was toggled by a curator.
464+
AgentFreezingToggled {
465+
curator: T::AccountId,
466+
new_state: bool,
467+
},
468+
/// The namespace freezing feature was toggled by a curator.
469+
NamespaceFreezingToggled {
470+
curator: T::AccountId,
471+
new_state: bool,
472+
},
416473
}
417474

418475
#[pallet::error]
@@ -529,6 +586,14 @@ impl<T: Config> pallet_governance_api::GovernanceApi<T::AccountId> for Pallet<T>
529586
Allocators::<T>::insert(key, ());
530587
}
531588

589+
fn can_create_namespace(key: &T::AccountId) -> bool {
590+
!NamespacesFrozen::<T>::get() || Self::is_whitelisted(key)
591+
}
592+
593+
fn can_register_agent(key: &T::AccountId) -> bool {
594+
!AgentsFrozen::<T>::get() || Self::is_whitelisted(key)
595+
}
596+
532597
#[cfg(feature = "runtime-benchmarks")]
533598
fn force_set_whitelisted(key: &T::AccountId) {
534599
Whitelist::<T>::insert(key, ());

0 commit comments

Comments
 (0)