Skip to content

Commit

Permalink
Merge pull request #1857 from subspace/domains/include_raw_genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhavyas authored Aug 21, 2023
2 parents 086664e + 809ff91 commit f043734
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion crates/pallet-domains/src/block_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ mod tests {
bundle_slot_probability: (1, 1),
target_bundles_per_block: 1,
},
vec![],
)
.unwrap();

Expand Down Expand Up @@ -629,7 +630,7 @@ mod tests {
);
assert!(ConsensusBlockHash::<Test>::get(
domain_id,
pruned_receipt.consensus_block_number
pruned_receipt.consensus_block_number,
)
.is_none());
});
Expand Down
18 changes: 15 additions & 3 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ mod pallet {
/// The maximum number of pending staking operation that can perform upon epoch transition.
#[pallet::constant]
type MaxPendingStakingOperation: Get<u32>;

#[pallet::constant]
type SudoId: Get<Self::AccountId>;
}

#[pallet::pallet]
Expand Down Expand Up @@ -903,12 +906,21 @@ mod pallet {
pub fn instantiate_domain(
origin: OriginFor<T>,
domain_config: DomainConfig,
raw_genesis: Vec<u8>,
) -> 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::<T>::current_block_number();

let domain_id = do_instantiate_domain::<T>(domain_config, who, created_at, None)
.map_err(Error::<T>::from)?;
let domain_id =
do_instantiate_domain::<T>(domain_config, who, created_at, Some(raw_genesis))
.map_err(Error::<T>::from)?;

Self::deposit_event(Event::DomainInstantiated { domain_id });

Expand Down
1 change: 1 addition & 0 deletions crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions test/subspace-test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -569,6 +570,7 @@ impl pallet_domains::Config for Runtime {
type TreasuryAccount = TreasuryAccount;
type DomainBlockReward = BlockReward;
type MaxPendingStakingOperation = MaxPendingStakingOperation;
type SudoId = SudoId;
}

parameter_types! {
Expand Down

0 comments on commit f043734

Please sign in to comment.