From 9d30501ae949e62c1fd80027515de65fb1a8810e Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 11 Nov 2024 14:14:26 +0800 Subject: [PATCH] Test Aragon DAO whitelist origin on Koi (#1624) * Test Aragon DAO whitelist origin on Koi Signed-off-by: Xavier Lau * Add benchmark * Set whitelist dispatch origin --------- Signed-off-by: Xavier Lau --- runtime/common/src/gov_origin.rs | 31 +++++++- runtime/koi/src/pallets/asset_manager.rs | 2 +- runtime/koi/src/pallets/assets.rs | 2 +- runtime/koi/src/pallets/governance.rs | 24 +++--- runtime/koi/src/pallets/governance/origin.rs | 80 ++++++++------------ runtime/koi/src/pallets/governance/track.rs | 71 +---------------- runtime/koi/src/pallets/polkadot_xcm.rs | 2 +- runtime/koi/src/pallets/preimage.rs | 2 +- runtime/koi/src/pallets/scheduler.rs | 2 +- runtime/koi/src/pallets/xcmp_queue.rs | 2 +- 10 files changed, 87 insertions(+), 131 deletions(-) diff --git a/runtime/common/src/gov_origin.rs b/runtime/common/src/gov_origin.rs index 9dda93504..7be481c86 100644 --- a/runtime/common/src/gov_origin.rs +++ b/runtime/common/src/gov_origin.rs @@ -16,8 +16,13 @@ // You should have received a copy of the GNU General Public License // along with Darwinia. If not, see . -pub use frame_support::traits::{EitherOf, EitherOfDiverse}; +pub use frame_support::{ + dispatch::RawOrigin, + traits::{EitherOf, EitherOfDiverse, EnsureOrigin, Get}, +}; +// core +use core::marker::PhantomData; // darwinia use dc_primitives::AccountId; // frontier @@ -56,3 +61,27 @@ 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(PhantomData) +where + RingDaoAccount: Get; +impl EnsureOrigin for RingDao +where + O: Into, O>> + From>, + RingDaoAccount: Get, +{ + type Success = (); + + fn try_origin(o: O) -> Result { + 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 { + Ok(O::from(RawOrigin::Root)) + } +} diff --git a/runtime/koi/src/pallets/asset_manager.rs b/runtime/koi/src/pallets/asset_manager.rs index 5b4fb015b..10938bcd0 100644 --- a/runtime/koi/src/pallets/asset_manager.rs +++ b/runtime/koi/src/pallets/asset_manager.rs @@ -143,7 +143,7 @@ impl pallet_asset_manager::Config for Runtime { type AssetRegistrar = AssetRegistrar; type AssetRegistrarMetadata = xcm_config::AssetRegistrarMetadata; type Balance = Balance; - type ForeignAssetModifierOrigin = RootOr; + type ForeignAssetModifierOrigin = Root; type ForeignAssetType = AssetType; type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_asset_manager::WeightInfo; diff --git a/runtime/koi/src/pallets/assets.rs b/runtime/koi/src/pallets/assets.rs index fc07e336a..f85f891ed 100644 --- a/runtime/koi/src/pallets/assets.rs +++ b/runtime/koi/src/pallets/assets.rs @@ -45,7 +45,7 @@ impl pallet_assets::Config for Runtime { >; type Currency = Balances; type Extra = (); - type ForceOrigin = RootOr; + type ForceOrigin = Root; type Freezer = (); type MetadataDepositBase = (); type MetadataDepositPerByte = (); diff --git a/runtime/koi/src/pallets/governance.rs b/runtime/koi/src/pallets/governance.rs index 689e16e3f..d24bb6cc5 100644 --- a/runtime/koi/src/pallets/governance.rs +++ b/runtime/koi/src/pallets/governance.rs @@ -17,8 +17,8 @@ // along with Darwinia. If not, see . mod origin; +pub use origin::custom_origins; use origin::*; -pub use origin::{custom_origins, GeneralAdmin}; mod track; use track::*; @@ -42,7 +42,7 @@ impl pallet_collective::Config for Runtime { type Proposal = RuntimeCall; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; - type SetMembersOrigin = RootOr; + type SetMembersOrigin = Root; type WeightInfo = weights::pallet_collective::WeightInfo; } @@ -80,15 +80,21 @@ impl pallet_referenda::Config for Runtime { impl custom_origins::Config for Runtime {} +frame_support::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(); +} + // 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; + type DispatchWhitelistedOrigin = + RootOr>>; type Preimages = Preimage; type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_whitelist::WeightInfo; - type WhitelistOrigin = RootOrAtLeastFourFifth; + type WhitelistOrigin = AtLeastFourFifth; } frame_support::parameter_types! { @@ -96,7 +102,7 @@ frame_support::parameter_types! { } impl pallet_treasury::Config for Runtime { - type ApproveOrigin = RootOr; + type ApproveOrigin = Root; type AssetKind = (); type BalanceConverter = frame_support::traits::tokens::UnityAssetBalanceConversion; #[cfg(feature = "runtime-benchmarks")] @@ -115,13 +121,11 @@ impl pallet_treasury::Config for Runtime { type ProposalBond = ProposalBond; type ProposalBondMaximum = (); type ProposalBondMinimum = ConstU128; - type RejectOrigin = RootOr; + type RejectOrigin = Root; type RuntimeEvent = RuntimeEvent; type SpendFunds = (); - type SpendOrigin = EitherOf< - frame_system::EnsureRootWithSuccess, - Spender, - >; + type SpendOrigin = + frame_system::EnsureRootWithSuccess; type SpendPeriod = Time1; type WeightInfo = weights::pallet_treasury::WeightInfo; } diff --git a/runtime/koi/src/pallets/governance/origin.rs b/runtime/koi/src/pallets/governance/origin.rs index afde720f7..ac7f3e0a6 100644 --- a/runtime/koi/src/pallets/governance/origin.rs +++ b/runtime/koi/src/pallets/governance/origin.rs @@ -20,8 +20,6 @@ pub mod custom_origins { // crates.io use strum::EnumString; - // darwinia - use dc_primitives::{Balance, UNIT}; // polkadot-sdk use frame_support::pallet_prelude::*; use sp_runtime::RuntimeDebug; @@ -40,16 +38,10 @@ pub mod custom_origins { pub enum Origin { /// Origin able to dispatch a whitelisted call. WhitelistedCaller, - /// General admin - GeneralAdmin, /// Origin able to cancel referenda. ReferendumCanceller, /// Origin able to kill referenda. ReferendumKiller, - /// Origin able to spend up to 4M KRING from the treasury at once. - MediumSpender, - /// Origin able to spend up to 20M KRING from the treasury at once. - BigSpender, } macro_rules! decl_unit_ensures { @@ -82,45 +74,39 @@ pub mod custom_origins { }; () => {} } - decl_unit_ensures!(ReferendumCanceller, ReferendumKiller, WhitelistedCaller, GeneralAdmin); + decl_unit_ensures!(ReferendumCanceller, ReferendumKiller, WhitelistedCaller); - macro_rules! decl_ensure { - ( - $vis:vis type $name:ident: EnsureOrigin { - $( $item:ident = $success:expr, )* - } - ) => { - $vis struct $name; - impl> + From> - EnsureOrigin for $name - { - type Success = $success_type; - fn try_origin(o: O) -> Result { - o.into().and_then(|o| match o { - $( - Origin::$item => Ok($success), - )* - r => Err(O::from(r)), - }) - } - #[cfg(feature = "runtime-benchmarks")] - fn try_successful_origin() -> Result { - // By convention the more privileged origins go later, so for greatest chance - // of success, we want the last one. - let _result: Result = Err(()); - $( - let _result: Result = Ok(O::from(Origin::$item)); - )* - _result - } - } - } - } - decl_ensure! { - pub type Spender: EnsureOrigin { - MediumSpender = 4_000_000 * UNIT, - BigSpender = 20_000_000 * UNIT, - } - } + // macro_rules! decl_ensure { + // ( + // $vis:vis type $name:ident: EnsureOrigin { + // $( $item:ident = $success:expr, )* + // } + // ) => { + // $vis struct $name; + // impl> + From> + // EnsureOrigin for $name + // { + // type Success = $success_type; + // fn try_origin(o: O) -> Result { + // o.into().and_then(|o| match o { + // $( + // Origin::$item => Ok($success), + // )* + // r => Err(O::from(r)), + // }) + // } + // #[cfg(feature = "runtime-benchmarks")] + // fn try_successful_origin() -> Result { + // // By convention the more privileged origins go later, so for greatest chance + // // of success, we want the last one. + // let _result: Result = Err(()); + // $( + // let _result: Result = Ok(O::from(Origin::$item)); + // )* + // _result + // } + // } + // } + // } } pub use custom_origins::*; diff --git a/runtime/koi/src/pallets/governance/track.rs b/runtime/koi/src/pallets/governance/track.rs index 507012cb7..596370d7c 100644 --- a/runtime/koi/src/pallets/governance/track.rs +++ b/runtime/koi/src/pallets/governance/track.rs @@ -21,7 +21,7 @@ use core::str::FromStr; // darwinia use super::*; -const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 7] = [ +const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 4] = [ ( 0, pallet_referenda::TrackInfo { @@ -80,32 +80,7 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 7] ), }, ), - ( - 2, - pallet_referenda::TrackInfo { - name: "general_admin", - max_deciding: 10, - decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, - prepare_period: TIME_1, - decision_period: TIME_1, - confirm_period: TIME_1, - min_enactment_period: TIME_1, - min_approval: pallet_referenda::Curve::make_reciprocal( - 1, - 2, - percent(80), - percent(50), - percent(100), - ), - min_support: pallet_referenda::Curve::make_reciprocal( - 1, - 2, - percent(10), - percent(0), - percent(50), - ), - }, - ), + // 2 for deprecated general admin. ( 3, pallet_referenda::TrackInfo { @@ -158,46 +133,8 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 7] ), }, ), - ( - 5, - pallet_referenda::TrackInfo { - name: "medium_spender", - max_deciding: 50, - decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, - prepare_period: TIME_1, - decision_period: TIME_1, - confirm_period: TIME_1, - min_enactment_period: TIME_1, - min_approval: pallet_referenda::Curve::make_linear(1, 2, percent(50), percent(100)), - min_support: pallet_referenda::Curve::make_reciprocal( - 1, - 2, - percent(1), - percent(0), - percent(50), - ), - }, - ), - ( - 6, - pallet_referenda::TrackInfo { - name: "big_spender", - max_deciding: 50, - decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, - prepare_period: TIME_1, - decision_period: TIME_1, - confirm_period: TIME_1, - min_enactment_period: TIME_1, - min_approval: pallet_referenda::Curve::make_linear(1, 2, percent(50), percent(100)), - min_support: pallet_referenda::Curve::make_reciprocal( - 1, - 2, - percent(1), - percent(0), - percent(50), - ), - }, - ), + // 5 for deprecated medium spender. + // 6 for deprecated big spender. ]; pub struct TracksInfo; diff --git a/runtime/koi/src/pallets/polkadot_xcm.rs b/runtime/koi/src/pallets/polkadot_xcm.rs index 937e99103..44c6f221d 100644 --- a/runtime/koi/src/pallets/polkadot_xcm.rs +++ b/runtime/koi/src/pallets/polkadot_xcm.rs @@ -205,7 +205,7 @@ impl xcm_executor::Config for XcmExecutorConfig { } impl pallet_xcm::Config for Runtime { - type AdminOrigin = RootOr; + type AdminOrigin = Root; // ^ Override for AdvertisedXcmVersion default type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; type Currency = Balances; diff --git a/runtime/koi/src/pallets/preimage.rs b/runtime/koi/src/pallets/preimage.rs index e08c6e245..de2e71b0f 100644 --- a/runtime/koi/src/pallets/preimage.rs +++ b/runtime/koi/src/pallets/preimage.rs @@ -37,7 +37,7 @@ impl pallet_preimage::Config for Runtime { >, >; type Currency = Balances; - type ManagerOrigin = RootOr; + type ManagerOrigin = Root; type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_preimage::WeightInfo; } diff --git a/runtime/koi/src/pallets/scheduler.rs b/runtime/koi/src/pallets/scheduler.rs index 3f46d2e0a..19f77c2a7 100644 --- a/runtime/koi/src/pallets/scheduler.rs +++ b/runtime/koi/src/pallets/scheduler.rs @@ -57,6 +57,6 @@ impl pallet_scheduler::Config for Runtime { type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; - type ScheduleOrigin = RootOr; + type ScheduleOrigin = Root; type WeightInfo = weights::pallet_scheduler::WeightInfo; } diff --git a/runtime/koi/src/pallets/xcmp_queue.rs b/runtime/koi/src/pallets/xcmp_queue.rs index e38c6f192..d1dff89e4 100644 --- a/runtime/koi/src/pallets/xcmp_queue.rs +++ b/runtime/koi/src/pallets/xcmp_queue.rs @@ -21,7 +21,7 @@ use crate::*; impl cumulus_pallet_xcmp_queue::Config for Runtime { type ChannelInfo = ParachainSystem; - type ControllerOrigin = RootOr; + type ControllerOrigin = Root; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type MaxInboundSuspended = sp_core::ConstU32<1_000>; type PriceForSiblingDelivery = polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery<