From 90fa4c2281f077ff1f619076c0013c153b53c141 Mon Sep 17 00:00:00 2001 From: WMQ <46511820+wangminqi@users.noreply.github.com> Date: Mon, 21 Aug 2023 01:35:18 +0800 Subject: [PATCH] feat: enable bounty implementation for litentry (#2031) * feat: enable bounty implementation for litentry * debug: fix bug * add: bump runtime version --- runtime/litentry/src/lib.rs | 28 +++++++++++++++++++++++----- runtime/litmus/src/lib.rs | 2 +- runtime/rococo/src/lib.rs | 26 ++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/runtime/litentry/src/lib.rs b/runtime/litentry/src/lib.rs index 8b317e839d..8b1a49f0bc 100644 --- a/runtime/litentry/src/lib.rs +++ b/runtime/litentry/src/lib.rs @@ -28,7 +28,7 @@ use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use frame_support::{ construct_runtime, parameter_types, traits::{ - ConstU128, ConstU32, ConstU64, ConstU8, Contains, Everything, InstanceFilter, + ConstU128, ConstU32, ConstU64, ConstU8, Contains, EnsureOrigin, Everything, InstanceFilter, SortedMembers, WithdrawReasons, }, weights::{constants::RocksDbWeight, ConstantMultiplier, IdentityFee, Weight}, @@ -142,7 +142,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { impl_name: create_runtime_str!("litentry-parachain"), authoring_version: 1, // same versioning-mechanism as polkadot: use last digit for minor updates - spec_version: 9167, + spec_version: 9168, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -543,6 +543,21 @@ parameter_types! { pub const MaximumReasonLength: u32 = 8192; } +pub struct EnsureRootOrTwoThirdsCouncilWrapper; +impl EnsureOrigin for EnsureRootOrTwoThirdsCouncilWrapper { + type Success = Balance; + fn try_origin(o: RuntimeOrigin) -> Result { + match EnsureRootOrTwoThirdsCouncil::try_origin(o) { + Ok(_) => Ok(Balance::max_value()), + Err(o) => Err(o), + } + } + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + Ok(RuntimeOrigin::root()) + } +} + impl pallet_treasury::Config for Runtime { type PalletId = TreasuryPalletId; type Currency = Balances; @@ -553,12 +568,13 @@ impl pallet_treasury::Config for Runtime { type ProposalBond = ProposalBond; type ProposalBondMinimum = ProposalBondMinimum; type ProposalBondMaximum = ProposalBondMaximum; - type SpendOrigin = frame_support::traits::NeverEnsureOrigin; + // Once passed, at most all is allowed to be spent + type SpendOrigin = EnsureRootOrTwoThirdsCouncilWrapper; type SpendPeriod = SpendPeriod; type Burn = Burn; type BurnDestination = (); - // Bounties is not enabled yet - type SpendFunds = (); + // Bounties is enabled now + type SpendFunds = Bounties; type WeightInfo = weights::pallet_treasury::WeightInfo; type MaxApprovals = ConstU32<100>; } @@ -943,6 +959,8 @@ impl Contains for NormalModeFilter { RuntimeCall::Vesting(pallet_vesting::Call::vest { .. }) | // ChainBridge RuntimeCall::ChainBridge(_) | + // Bounties + RuntimeCall::Bounties(_) | // BridgeTransfer RuntimeCall::BridgeTransfer(_) | // Utility diff --git a/runtime/litmus/src/lib.rs b/runtime/litmus/src/lib.rs index ca5ecbbee4..5029eba5e7 100644 --- a/runtime/litmus/src/lib.rs +++ b/runtime/litmus/src/lib.rs @@ -153,7 +153,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { impl_name: create_runtime_str!("litmus-parachain"), authoring_version: 1, // same versioning-mechanism as polkadot: use last digit for minor updates - spec_version: 9167, + spec_version: 9168, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 85fdf2ed23..d4b8d1af61 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -28,8 +28,8 @@ use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use frame_support::{ construct_runtime, ord_parameter_types, parameter_types, traits::{ - ConstU128, ConstU32, ConstU64, ConstU8, Contains, ContainsLengthBound, Everything, - InstanceFilter, SortedMembers, WithdrawReasons, + ConstU128, ConstU32, ConstU64, ConstU8, Contains, ContainsLengthBound, EnsureOrigin, + Everything, InstanceFilter, SortedMembers, WithdrawReasons, }, weights::{constants::RocksDbWeight, ConstantMultiplier, IdentityFee, Weight}, PalletId, RuntimeDebug, @@ -152,7 +152,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { impl_name: create_runtime_str!("rococo-parachain"), authoring_version: 1, // same versioning-mechanism as polkadot: use last digit for minor updates - spec_version: 9167, + spec_version: 9168, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -560,6 +560,21 @@ parameter_types! { pub const MaximumReasonLength: u32 = 8192; } +pub struct EnsureRootOrTwoThirdsCouncilWrapper; +impl EnsureOrigin for EnsureRootOrTwoThirdsCouncilWrapper { + type Success = Balance; + fn try_origin(o: RuntimeOrigin) -> Result { + match EnsureRootOrTwoThirdsCouncil::try_origin(o) { + Ok(_) => Ok(Balance::max_value()), + Err(o) => Err(o), + } + } + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + Ok(RuntimeOrigin::root()) + } +} + impl pallet_treasury::Config for Runtime { type PalletId = TreasuryPalletId; type Currency = Balances; @@ -570,7 +585,8 @@ impl pallet_treasury::Config for Runtime { type ProposalBond = ProposalBond; type ProposalBondMinimum = ProposalBondMinimum; type ProposalBondMaximum = ProposalBondMaximum; - type SpendOrigin = frame_support::traits::NeverEnsureOrigin; + // Once passed, at most all is allowed to be spent + type SpendOrigin = EnsureRootOrTwoThirdsCouncilWrapper; type SpendPeriod = SpendPeriod; type Burn = Burn; type BurnDestination = (); @@ -1051,6 +1067,8 @@ impl Contains for NormalModeFilter { RuntimeCall::Vesting(pallet_vesting::Call::vest { .. }) | // ChainBridge RuntimeCall::ChainBridge(_) | + // Bounties + RuntimeCall::Bounties(_) | // BridgeTransfer RuntimeCall::BridgeTransfer(_) | // XTokens::transfer for normal users