From 809ff9105261310a9c958473b3408c58637c9da1 Mon Sep 17 00:00:00 2001 From: vedhavyas Date: Mon, 21 Aug 2023 16:34:26 +0200 Subject: [PATCH] allow raw genesis to be passed during the domain instantiation to enable sudo --- crates/pallet-domains/src/block_tree.rs | 3 ++- crates/pallet-domains/src/lib.rs | 18 +++++++++++++++--- crates/pallet-domains/src/tests.rs | 1 + crates/subspace-runtime/src/lib.rs | 2 ++ test/subspace-test-runtime/src/lib.rs | 2 ++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/crates/pallet-domains/src/block_tree.rs b/crates/pallet-domains/src/block_tree.rs index 5cb67e4d73..ad93c8bd80 100644 --- a/crates/pallet-domains/src/block_tree.rs +++ b/crates/pallet-domains/src/block_tree.rs @@ -412,6 +412,7 @@ mod tests { bundle_slot_probability: (1, 1), target_bundles_per_block: 1, }, + vec![], ) .unwrap(); @@ -629,7 +630,7 @@ mod tests { ); assert!(ConsensusBlockHash::::get( domain_id, - pruned_receipt.consensus_block_number + pruned_receipt.consensus_block_number, ) .is_none()); }); diff --git a/crates/pallet-domains/src/lib.rs b/crates/pallet-domains/src/lib.rs index d701570289..75c72a3ae0 100644 --- a/crates/pallet-domains/src/lib.rs +++ b/crates/pallet-domains/src/lib.rs @@ -272,6 +272,9 @@ mod pallet { /// The maximum number of pending staking operation that can perform upon epoch transition. #[pallet::constant] type MaxPendingStakingOperation: Get; + + #[pallet::constant] + type SudoId: Get; } #[pallet::pallet] @@ -903,12 +906,21 @@ mod pallet { pub fn instantiate_domain( origin: OriginFor, domain_config: DomainConfig, + raw_genesis: Vec, ) -> DispatchResult { - let who = ensure_signed(origin)?; + let who = if raw_genesis.is_empty() { + ensure_signed(origin)? + } else { + // TODO: remove once XDM is finished + ensure_root(origin)?; + T::SudoId::get() + }; + let created_at = frame_system::Pallet::::current_block_number(); - let domain_id = do_instantiate_domain::(domain_config, who, created_at, None) - .map_err(Error::::from)?; + let domain_id = + do_instantiate_domain::(domain_config, who, created_at, Some(raw_genesis)) + .map_err(Error::::from)?; Self::deposit_event(Event::DomainInstantiated { domain_id }); diff --git a/crates/pallet-domains/src/tests.rs b/crates/pallet-domains/src/tests.rs index d961e3a9a1..f06348ca0b 100644 --- a/crates/pallet-domains/src/tests.rs +++ b/crates/pallet-domains/src/tests.rs @@ -193,6 +193,7 @@ impl pallet_domains::Config for Test { type TreasuryAccount = TreasuryAccount; type DomainBlockReward = BlockReward; type MaxPendingStakingOperation = MaxPendingStakingOperation; + type SudoId = (); } pub(crate) fn new_test_ext() -> sp_io::TestExternalities { diff --git a/crates/subspace-runtime/src/lib.rs b/crates/subspace-runtime/src/lib.rs index 2264fc4492..bc96e1baca 100644 --- a/crates/subspace-runtime/src/lib.rs +++ b/crates/subspace-runtime/src/lib.rs @@ -488,6 +488,7 @@ parameter_types! { pub const StakeEpochDuration: DomainNumber = 100; pub TreasuryAccount: AccountId = PalletId(*b"treasury").into_account_truncating(); pub const MaxPendingStakingOperation: u32 = 100; + pub SudoId: AccountId = Sudo::key().expect("Sudo account must exist"); } impl pallet_domains::Config for Runtime { @@ -514,6 +515,7 @@ impl pallet_domains::Config for Runtime { type TreasuryAccount = TreasuryAccount; type DomainBlockReward = BlockReward; type MaxPendingStakingOperation = MaxPendingStakingOperation; + 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 d7a81b6f14..17f898a21f 100644 --- a/test/subspace-test-runtime/src/lib.rs +++ b/test/subspace-test-runtime/src/lib.rs @@ -543,6 +543,7 @@ parameter_types! { pub const StakeEpochDuration: DomainNumber = 5; pub TreasuryAccount: AccountId = PalletId(*b"treasury").into_account_truncating(); pub const MaxPendingStakingOperation: u32 = 100; + pub SudoId: AccountId = Sudo::key().expect("Sudo account must exist"); } impl pallet_domains::Config for Runtime { @@ -569,6 +570,7 @@ impl pallet_domains::Config for Runtime { type TreasuryAccount = TreasuryAccount; type DomainBlockReward = BlockReward; type MaxPendingStakingOperation = MaxPendingStakingOperation; + type SudoId = SudoId; } parameter_types! {