From 2b8da57bf092680485e363f3b7a6b5a4d213850f Mon Sep 17 00:00:00 2001 From: linning Date: Sat, 4 Nov 2023 00:02:27 +0800 Subject: [PATCH] Make the instantiate_domain call permissioned Signed-off-by: linning --- crates/pallet-domains/src/lib.rs | 8 +++++++- crates/pallet-domains/src/tests.rs | 3 ++- crates/subspace-runtime/src/lib.rs | 2 ++ test/subspace-test-runtime/src/lib.rs | 2 ++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/pallet-domains/src/lib.rs b/crates/pallet-domains/src/lib.rs index 7b06de7195..f06f440569 100644 --- a/crates/pallet-domains/src/lib.rs +++ b/crates/pallet-domains/src/lib.rs @@ -288,6 +288,10 @@ mod pallet { /// Randomness source. type Randomness: RandomnessT>; + + /// The sudo account id + #[pallet::constant] + type SudoId: Get; } #[pallet::pallet] @@ -1044,7 +1048,9 @@ mod pallet { origin: OriginFor, domain_config: DomainConfig, ) -> DispatchResult { - let who = ensure_signed(origin)?; + ensure_root(origin)?; + + let who = T::SudoId::get(); let created_at = frame_system::Pallet::::current_block_number(); diff --git a/crates/pallet-domains/src/tests.rs b/crates/pallet-domains/src/tests.rs index d6d9cda0a2..13ca06cc96 100644 --- a/crates/pallet-domains/src/tests.rs +++ b/crates/pallet-domains/src/tests.rs @@ -239,6 +239,7 @@ impl pallet_domains::Config for Test { type MaxPendingStakingOperation = MaxPendingStakingOperation; type MaxNominators = MaxNominators; type Randomness = MockRandomness; + type SudoId = (); } impl domain_pallet_executive::Config for Test { @@ -476,7 +477,7 @@ pub(crate) fn register_genesis_domain(creator: u64, operator_ids: Vec::ExistentialDeposit::get(), ); crate::Pallet::::instantiate_domain( - RawOrigin::Signed(creator).into(), + RawOrigin::Root.into(), DomainConfig { domain_name: "evm-domain".to_owned(), runtime_id: 0, diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index abd1a14d42..e24a20e8ba 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -605,6 +605,7 @@ parameter_types! { pub const MaxPendingStakingOperation: u32 = 100; // TODO: reset `MaxNominators` back to `100` once the gemini-3g chain spec is created pub const MaxNominators: u32 = 0; + pub SudoId: AccountId = Sudo::key().expect("Sudo account must exist"); } impl pallet_domains::Config for Runtime { @@ -632,6 +633,7 @@ impl pallet_domains::Config for Runtime { type MaxPendingStakingOperation = MaxPendingStakingOperation; type MaxNominators = MaxNominators; type Randomness = Subspace; + type SudoId = SudoId; } pub struct StakingOnReward; diff --git a/test/subspace-test-runtime/src/lib.rs b/test/subspace-test-runtime/src/lib.rs index afea9bfed9..c447500738 100644 --- a/test/subspace-test-runtime/src/lib.rs +++ b/test/subspace-test-runtime/src/lib.rs @@ -637,6 +637,7 @@ parameter_types! { pub TreasuryAccount: AccountId = PalletId(*b"treasury").into_account_truncating(); pub const MaxPendingStakingOperation: u32 = 100; pub const MaxNominators: u32 = 100; + pub SudoId: AccountId = Sudo::key().expect("Sudo account must exist"); } impl pallet_domains::Config for Runtime { @@ -664,6 +665,7 @@ impl pallet_domains::Config for Runtime { type MaxPendingStakingOperation = MaxPendingStakingOperation; type MaxNominators = MaxNominators; type Randomness = Subspace; + type SudoId = SudoId; } parameter_types! {