Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ControlOrigin #574

Merged
merged 2 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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