Skip to content

Commit

Permalink
Introduce ControlOrigin (#574)
Browse files Browse the repository at this point in the history
* Introduce ControlOrigin

* import EnsureRoot
  • Loading branch information
KaiserKarel committed Feb 1, 2022
1 parent 650d387 commit 1a2200f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 7 additions & 3 deletions frame/mosaic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ pub mod pallet {
+ PartialEq;

type NetworkId: FullCodec + TypeInfo + Clone + Debug + PartialEq;

/// Origin capable of setting the relayer. Inteded to be RootOrHalfCouncil, as it is also
/// used as the origin capable of stopping attackers.
type ControlOrigin: EnsureOrigin<Self::Origin>;
}

#[pallet::pallet]
Expand Down Expand Up @@ -254,7 +258,7 @@ pub mod pallet {
origin: OriginFor<T>,
relayer: T::AccountId,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
T::ControlOrigin::ensure_origin(origin)?;
Relayer::<T>::set(Some(StaleRelayer::new(relayer.clone())));
Self::deposit_event(Event::RelayerSet { relayer });
Ok(().into())
Expand Down Expand Up @@ -308,7 +312,7 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
// Can also be token governance associated I reckon, as Angular holders should be able
// to grant mosaic permission to mint. We'll save that for phase 3.
ensure_root(origin)?;
T::ControlOrigin::ensure_origin(origin)?;
let current_block = <frame_system::Pallet<T>>::block_number();

AssetsInfo::<T>::mutate(asset_id, |item| {
Expand Down Expand Up @@ -549,7 +553,7 @@ pub mod pallet {
origin: OriginFor<T>,
period: BlockNumberOf<T>,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
T::ControlOrigin::ensure_origin(origin)?;
ensure!(period > T::MinimumTimeLockPeriod::get(), Error::<T>::BadTimelockPeriod);
TimeLockPeriod::<T>::set(period);
Ok(().into())
Expand Down
2 changes: 2 additions & 0 deletions frame/mosaic/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use system::EnsureRoot;

pub type AccountId = u128;
pub type BlockNumber = u64;
Expand Down Expand Up @@ -105,6 +106,7 @@ impl pallet_mosaic::Config for Test {
type BudgetPenaltyDecayer = pallet_mosaic::BudgetPenaltyDecayer<Balance, BlockNumber>;

type NetworkId = NetworkId;
type ControlOrigin = EnsureRoot<Self::AccountId>;
}

// Build genesis storage according to the mock runtime.
Expand Down
3 changes: 2 additions & 1 deletion runtime/dali/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ impl dutch_auction::Config for Runtime {
}

parameter_types! {
pub const MosaicId: PalletId = PalletId(*b"plmosaic");
pub const MosaicId: PalletId = PalletId(*b"plmosaic");
pub const MinimumTTL: BlockNumber = 10;
pub const MinimumTimeLockPeriod: BlockNumber = 20;
}
Expand All @@ -873,6 +873,7 @@ impl mosaic::Config for Runtime {
type MinimumTimeLockPeriod = MinimumTimeLockPeriod;
type BudgetPenaltyDecayer = mosaic::BudgetPenaltyDecayer<Balance, BlockNumber>;
type NetworkId = u32;
type ControlOrigin = EnsureRootOrHalfCouncil;
}

construct_runtime!(
Expand Down

0 comments on commit 1a2200f

Please sign in to comment.