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

Audited updates #1628

Merged
merged 1 commit into from
Nov 25, 2024
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
6 changes: 1 addition & 5 deletions pallet/account-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ pub mod pallet {
let wt = T::DbWeight::get().writes(1);
let mut consumer = <Ledgers<T>>::iter().drain();

for i in 0..MAX_TASKS {
if i >= MAX_TASKS {
break;
}

for _ in 0..MAX_TASKS {
if let Some(rw) = remaining_weight.checked_sub(&wt) {
remaining_weight = rw;
} else {
Expand Down
12 changes: 2 additions & 10 deletions pallet/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,7 @@ pub mod pallet {
let wt = T::WeightInfo::allocate_ring_staking_reward_of();
let mut consumer = <PendingRewards<T>>::iter().drain();

for i in 0..MAX_TASKS {
if i >= MAX_TASKS {
break;
}

for _ in 0..MAX_TASKS {
if let Some(rw) = remaining_weight.checked_sub(&wt) {
*remaining_weight = rw;
} else {
Expand All @@ -459,11 +455,7 @@ pub mod pallet {
let wt = T::WeightInfo::unstake_all_for();
let mut consumer = <Ledgers<T>>::iter().drain();

for i in 0..MAX_TASKS {
if i >= MAX_TASKS {
break;
}

for _ in 0..MAX_TASKS {
if let Some(rw) = remaining_weight.checked_sub(&wt) {
*remaining_weight = rw;
} else {
Expand Down
26 changes: 0 additions & 26 deletions runtime/common/src/gov_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ pub use frame_support::{
traits::{EitherOf, EitherOfDiverse, EnsureOrigin, Get},
};

// core
use core::marker::PhantomData;
// darwinia
use dc_primitives::AccountId;
// frontier
Expand Down Expand Up @@ -61,27 +59,3 @@ pub const ROOT: AccountId20 =
pub const KTON_ADMIN: AccountId20 = AccountId20([
70, 39, 93, 41, 17, 63, 6, 92, 42, 172, 38, 47, 52, 199, 163, 216, 168, 183, 55, 125,
]);

/// Ensure the origin is RingDAO.
pub struct RingDao<RingDaoAccount>(PhantomData<RingDaoAccount>)
where
RingDaoAccount: Get<AccountId20>;
impl<O, RingDaoAccount> EnsureOrigin<O> for RingDao<RingDaoAccount>
where
O: Into<Result<RawOrigin<AccountId20>, O>> + From<RawOrigin<AccountId20>>,
RingDaoAccount: Get<AccountId20>,
{
type Success = ();

fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
RawOrigin::Signed(who) if who == RingDaoAccount::get() => Ok(()),
r => Err(O::from(r)),
})
}

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<O, ()> {
Ok(O::from(RawOrigin::Root))
}
}
12 changes: 8 additions & 4 deletions runtime/koi/src/pallets/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,20 @@ impl pallet_referenda::Config for Runtime {

impl custom_origins::Config for Runtime {}

frame_support::parameter_types! {
frame_support::ord_parameter_types! {
// 0x005493b5658e6201F06FE2adF492610635505F4C.
pub RingDaoAccount: AccountId = [0, 84, 147, 181, 101, 142, 98, 1, 240, 111, 226, 173, 244, 146, 97, 6, 53, 80, 95, 76].into();
pub const RingDaoAccount: AccountId = AccountId::from([0, 84, 147, 181, 101, 142, 98, 1, 240, 111, 226, 173, 244, 146, 97, 6, 53, 80, 95, 76]);
}

// The purpose of this pallet is to queue calls to be dispatched as by root later => the Dispatch
// origin corresponds to the Gov2 Whitelist track.
impl pallet_whitelist::Config for Runtime {
type DispatchWhitelistedOrigin =
RootOr<frame_support::traits::EitherOf<WhitelistedCaller, RingDao<RingDaoAccount>>>;
type DispatchWhitelistedOrigin = RootOrDiverse<
frame_support::traits::EitherOfDiverse<
WhitelistedCaller,
frame_system::EnsureSignedBy<RingDaoAccount, AccountId>,
>,
>;
type Preimages = Preimage;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
Expand Down