git.delta.rocks / unique-network / refs/commits / 0e75cd977fe9

difftreelog

Merge pull request #978 from UniqueNetwork/fix/opal-governance-timings

Yaroslav Bolyukin2023-09-04parents: #c6d53cc #a797a1d.patch.diff
in: master

14 files changed

modified.docker/docker-compose.gov.j2diffbeforeafterboth
--- a/.docker/docker-compose.gov.j2
+++ b/.docker/docker-compose.gov.j2
@@ -21,4 +21,4 @@
       options:
         max-size: "1m"
         max-file: "3"
-    command: cargo run --release --features={{ NETWORK }}-runtime,{{ WASM_NAME }}-runtime/test-env -- --dev -linfo --rpc-cors=all --unsafe-rpc-external
+    command: cargo run --release --features={{ NETWORK }}-runtime,{{ WASM_NAME }}-runtime/gov-test-timings -- --dev -linfo --rpc-cors=all --unsafe-rpc-external
modified.github/workflows/gov.ymldiffbeforeafterboth
--- a/.github/workflows/gov.yml
+++ b/.github/workflows/gov.yml
@@ -1,4 +1,4 @@
-# Governance tests in --dev mode with test-env feature enabled to reduce gov timings
+# Governance tests in --dev mode with gov-test-timings feature enabled to reduce gov timings
 name: governance tests
 
 # Triger: only call from main workflow(re-usable workflows)
modifiedruntime/common/config/governance/council.rsdiffbeforeafterboth
--- a/runtime/common/config/governance/council.rs
+++ b/runtime/common/config/governance/council.rs
@@ -5,10 +5,10 @@
 	pub CouncilMaxMembers: u32 = 100;
 }
 
-#[cfg(not(feature = "test-env"))]
+#[cfg(not(feature = "gov-test-timings"))]
 use crate::governance_timings::council as council_timings;
 
-#[cfg(feature = "test-env")]
+#[cfg(feature = "gov-test-timings")]
 pub mod council_timings {
 	use super::*;
 
modifiedruntime/common/config/governance/democracy.rsdiffbeforeafterboth
--- a/runtime/common/config/governance/democracy.rs
+++ b/runtime/common/config/governance/democracy.rs
@@ -7,10 +7,10 @@
 	pub MaxProposals: u32 = 100;
 }
 
-#[cfg(not(feature = "test-env"))]
+#[cfg(not(feature = "gov-test-timings"))]
 use crate::governance_timings::democracy as democracy_timings;
 
-#[cfg(feature = "test-env")]
+#[cfg(feature = "gov-test-timings")]
 pub mod democracy_timings {
 	use super::*;
 
modifiedruntime/common/config/governance/fellowship.rsdiffbeforeafterboth
before · runtime/common/config/governance/fellowship.rs
1use crate::{Preimage, Treasury, RuntimeCall, RuntimeEvent, Scheduler, FellowshipReferenda, Runtime};2use super::*;3use pallet_gov_origins::Origin as GovOrigins;4use pallet_ranked_collective::{Config as RankedConfig, Rank, TallyOf};56pub const FELLOWSHIP_MODULE_ID: PalletId = PalletId(*b"flowship");7pub const DEMOCRACY_TRACK_ID: u16 = 10;89parameter_types! {10	pub FellowshipAccountId: <Runtime as frame_system::Config>::AccountId = FELLOWSHIP_MODULE_ID.into_account_truncating();11	pub AlarmInterval: BlockNumber = 1;12	pub SubmissionDeposit: Balance = 1000;13}1415#[cfg(not(feature = "test-env"))]16use crate::governance_timings::fellowship as fellowship_timings;1718#[cfg(feature = "test-env")]19pub mod fellowship_timings {20	use super::*;2122	parameter_types! {23		pub UndecidingTimeout: BlockNumber = 35;24	}2526	pub mod track {27		use super::*;2829		pub mod democracy_proposals {30			use super::*;3132			pub const PREPARE_PERIOD: BlockNumber = 3;33			pub const DECISION_PERIOD: BlockNumber = 35;34			pub const CONFIRM_PERIOD: BlockNumber = 3;35			pub const MIN_ENACTMENT_PERIOD: BlockNumber = 1;36		}37	}38}3940impl pallet_referenda::Config for Runtime {41	type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;42	type RuntimeCall = RuntimeCall;43	type RuntimeEvent = RuntimeEvent;44	type Scheduler = Scheduler;45	type Currency = Balances;46	type SubmitOrigin = pallet_ranked_collective::EnsureMember<Runtime, (), 1>;47	type CancelOrigin = RootOrAllTechnicalCommittee;48	type KillOrigin = RootOrAllTechnicalCommittee;49	type Slash = Treasury;50	type Votes = pallet_ranked_collective::Votes;51	type Tally = pallet_ranked_collective::TallyOf<Runtime>;52	type SubmissionDeposit = SubmissionDeposit;53	type MaxQueued = ConstU32<100>;54	type UndecidingTimeout = fellowship_timings::UndecidingTimeout;55	type AlarmInterval = AlarmInterval;56	type Tracks = TracksInfo;57	type Preimages = Preimage;58}5960impl RankedConfig for Runtime {61	type WeightInfo = pallet_ranked_collective::weights::SubstrateWeight<Self>;62	type RuntimeEvent = RuntimeEvent;63	// Promotion is by any of:64	// - Council member.65	// - Technical committee member.66	type PromoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;67	// Demotion is by any of:68	// - Council member.69	// - Technical committee member.70	type DemoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;71	type Polls = FellowshipReferenda;72	type MinRankOfClass = ClassToRankMapper<Self, ()>;73	type VoteWeight = pallet_ranked_collective::Geometric;74}7576pub struct EnsureFellowshipProposition;77impl<O> EnsureOrigin<O> for EnsureFellowshipProposition78where79	O: Into<Result<GovOrigins, O>> + From<GovOrigins>,80{81	type Success = AccountId;8283	fn try_origin(o: O) -> Result<Self::Success, O> {84		o.into().and_then(|o| match o {85			GovOrigins::FellowshipProposition => Ok(FellowshipAccountId::get()),86			o => Err(O::from(o)),87		})88	}8990	#[cfg(feature = "runtime-benchmarks")]91	fn try_successful_origin() -> Result<O, ()> {92		Ok(O::from(GovOrigins::FellowshipProposition))93	}94}9596pub type FellowshipPromoteDemoteOrigin<AccountId> = EitherOf<97	MapSuccess<EnsureRoot<AccountId>, Replace<ConstU16<65535>>>,98	MapSuccess<MoreThanHalfCouncil, Replace<ConstU16<9>>>,99>;100101pub struct TracksInfo;102impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {103	type Id = u16;104	type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;105	fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {106		static DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 1] = [(107			DEMOCRACY_TRACK_ID,108			pallet_referenda::TrackInfo {109				name: "democracy_proposals",110				max_deciding: 10,111				decision_deposit: 10 * UNIQUE,112				prepare_period: fellowship_timings::track::democracy_proposals::PREPARE_PERIOD,113				decision_period: fellowship_timings::track::democracy_proposals::DECISION_PERIOD,114				confirm_period: fellowship_timings::track::democracy_proposals::CONFIRM_PERIOD,115				min_enactment_period:116					fellowship_timings::track::democracy_proposals::MIN_ENACTMENT_PERIOD,117				min_approval: pallet_referenda::Curve::LinearDecreasing {118					length: Perbill::from_percent(100),119					floor: Perbill::from_percent(50),120					ceil: Perbill::from_percent(100),121				},122				min_support: pallet_referenda::Curve::LinearDecreasing {123					length: Perbill::from_percent(100),124					floor: Perbill::from_percent(0),125					ceil: Perbill::from_percent(50),126				},127			},128		)];129		&DATA[..]130	}131	fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {132		#[cfg(feature = "runtime-benchmarks")]133		{134			// For benchmarks, we enable a root origin.135			// It is important that this is not available in production!136			let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();137			if &root == id {138				return Ok(9);139			}140		}141142		match GovOrigins::try_from(id.clone()) {143			Ok(_) => Ok(DEMOCRACY_TRACK_ID),144			_ => Err(()),145		}146	}147}148149pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);150151pub struct ClassToRankMapper<T, I>(PhantomData<(T, I)>);152153//TODO: Remove the type when it appears in the release.154pub type ClassOf<T, I = ()> = <<T as RankedConfig<I>>::Polls as Polling<TallyOf<T, I>>>::Class;155156impl<T, I> Convert<ClassOf<T, I>, Rank> for ClassToRankMapper<T, I>157where158	T: RankedConfig<I>,159	ClassOf<T, I>: Into<Rank>,160{161	fn convert(track_id: ClassOf<T, I>) -> Rank {162		match track_id.into() {163			DEMOCRACY_TRACK_ID => 3,164			other => other,165		}166	}167}
after · runtime/common/config/governance/fellowship.rs
1use crate::{Preimage, Treasury, RuntimeCall, RuntimeEvent, Scheduler, FellowshipReferenda, Runtime};2use super::*;3use pallet_gov_origins::Origin as GovOrigins;4use pallet_ranked_collective::{Config as RankedConfig, Rank, TallyOf};56pub const FELLOWSHIP_MODULE_ID: PalletId = PalletId(*b"flowship");7pub const DEMOCRACY_TRACK_ID: u16 = 10;89parameter_types! {10	pub FellowshipAccountId: <Runtime as frame_system::Config>::AccountId = FELLOWSHIP_MODULE_ID.into_account_truncating();11	pub AlarmInterval: BlockNumber = 1;12	pub SubmissionDeposit: Balance = 1000;13}1415#[cfg(not(feature = "gov-test-timings"))]16use crate::governance_timings::fellowship as fellowship_timings;1718#[cfg(feature = "gov-test-timings")]19pub mod fellowship_timings {20	use super::*;2122	parameter_types! {23		pub UndecidingTimeout: BlockNumber = 35;24	}2526	pub mod track {27		use super::*;2829		pub mod democracy_proposals {30			use super::*;3132			pub const PREPARE_PERIOD: BlockNumber = 3;33			pub const DECISION_PERIOD: BlockNumber = 35;34			pub const CONFIRM_PERIOD: BlockNumber = 3;35			pub const MIN_ENACTMENT_PERIOD: BlockNumber = 1;36		}37	}38}3940impl pallet_referenda::Config for Runtime {41	type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;42	type RuntimeCall = RuntimeCall;43	type RuntimeEvent = RuntimeEvent;44	type Scheduler = Scheduler;45	type Currency = Balances;46	type SubmitOrigin = pallet_ranked_collective::EnsureMember<Runtime, (), 1>;47	type CancelOrigin = RootOrAllTechnicalCommittee;48	type KillOrigin = RootOrAllTechnicalCommittee;49	type Slash = Treasury;50	type Votes = pallet_ranked_collective::Votes;51	type Tally = pallet_ranked_collective::TallyOf<Runtime>;52	type SubmissionDeposit = SubmissionDeposit;53	type MaxQueued = ConstU32<100>;54	type UndecidingTimeout = fellowship_timings::UndecidingTimeout;55	type AlarmInterval = AlarmInterval;56	type Tracks = TracksInfo;57	type Preimages = Preimage;58}5960impl RankedConfig for Runtime {61	type WeightInfo = pallet_ranked_collective::weights::SubstrateWeight<Self>;62	type RuntimeEvent = RuntimeEvent;63	// Promotion is by any of:64	// - Council member.65	// - Technical committee member.66	type PromoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;67	// Demotion is by any of:68	// - Council member.69	// - Technical committee member.70	type DemoteOrigin = FellowshipPromoteDemoteOrigin<Self::AccountId>;71	type Polls = FellowshipReferenda;72	type MinRankOfClass = ClassToRankMapper<Self, ()>;73	type VoteWeight = pallet_ranked_collective::Geometric;74}7576pub struct EnsureFellowshipProposition;77impl<O> EnsureOrigin<O> for EnsureFellowshipProposition78where79	O: Into<Result<GovOrigins, O>> + From<GovOrigins>,80{81	type Success = AccountId;8283	fn try_origin(o: O) -> Result<Self::Success, O> {84		o.into().and_then(|o| match o {85			GovOrigins::FellowshipProposition => Ok(FellowshipAccountId::get()),86			o => Err(O::from(o)),87		})88	}8990	#[cfg(feature = "runtime-benchmarks")]91	fn try_successful_origin() -> Result<O, ()> {92		Ok(O::from(GovOrigins::FellowshipProposition))93	}94}9596pub type FellowshipPromoteDemoteOrigin<AccountId> = EitherOf<97	MapSuccess<EnsureRoot<AccountId>, Replace<ConstU16<65535>>>,98	MapSuccess<MoreThanHalfCouncil, Replace<ConstU16<9>>>,99>;100101pub struct TracksInfo;102impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {103	type Id = u16;104	type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;105	fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {106		static DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 1] = [(107			DEMOCRACY_TRACK_ID,108			pallet_referenda::TrackInfo {109				name: "democracy_proposals",110				max_deciding: 10,111				decision_deposit: 10 * UNIQUE,112				prepare_period: fellowship_timings::track::democracy_proposals::PREPARE_PERIOD,113				decision_period: fellowship_timings::track::democracy_proposals::DECISION_PERIOD,114				confirm_period: fellowship_timings::track::democracy_proposals::CONFIRM_PERIOD,115				min_enactment_period:116					fellowship_timings::track::democracy_proposals::MIN_ENACTMENT_PERIOD,117				min_approval: pallet_referenda::Curve::LinearDecreasing {118					length: Perbill::from_percent(100),119					floor: Perbill::from_percent(50),120					ceil: Perbill::from_percent(100),121				},122				min_support: pallet_referenda::Curve::LinearDecreasing {123					length: Perbill::from_percent(100),124					floor: Perbill::from_percent(0),125					ceil: Perbill::from_percent(50),126				},127			},128		)];129		&DATA[..]130	}131	fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {132		#[cfg(feature = "runtime-benchmarks")]133		{134			// For benchmarks, we enable a root origin.135			// It is important that this is not available in production!136			let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();137			if &root == id {138				return Ok(9);139			}140		}141142		match GovOrigins::try_from(id.clone()) {143			Ok(_) => Ok(DEMOCRACY_TRACK_ID),144			_ => Err(()),145		}146	}147}148149pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);150151pub struct ClassToRankMapper<T, I>(PhantomData<(T, I)>);152153//TODO: Remove the type when it appears in the release.154pub type ClassOf<T, I = ()> = <<T as RankedConfig<I>>::Polls as Polling<TallyOf<T, I>>>::Class;155156impl<T, I> Convert<ClassOf<T, I>, Rank> for ClassToRankMapper<T, I>157where158	T: RankedConfig<I>,159	ClassOf<T, I>: Into<Rank>,160{161	fn convert(track_id: ClassOf<T, I>) -> Rank {162		match track_id.into() {163			DEMOCRACY_TRACK_ID => 3,164			other => other,165		}166	}167}
modifiedruntime/common/config/governance/technical_committee.rsdiffbeforeafterboth
--- a/runtime/common/config/governance/technical_committee.rs
+++ b/runtime/common/config/governance/technical_committee.rs
@@ -5,10 +5,10 @@
 	pub TechnicalMaxMembers: u32 = 100;
 }
 
-#[cfg(not(feature = "test-env"))]
+#[cfg(not(feature = "gov-test-timings"))]
 use crate::governance_timings::technical_committee as technical_committee_timings;
 
-#[cfg(feature = "test-env")]
+#[cfg(feature = "gov-test-timings")]
 pub mod technical_committee_timings {
 	use super::*;
 
modifiedruntime/common/config/mod.rsdiffbeforeafterboth
--- a/runtime/common/config/mod.rs
+++ b/runtime/common/config/mod.rs
@@ -25,5 +25,5 @@
 #[cfg(feature = "governance")]
 pub mod governance;
 
-#[cfg(feature = "test-env")]
+#[cfg(feature = "pallet-test-utils")]
 pub mod test_pallets;
modifiedruntime/common/construct_runtime.rsdiffbeforeafterboth
--- a/runtime/common/construct_runtime.rs
+++ b/runtime/common/construct_runtime.rs
@@ -136,7 +136,7 @@
 
 				BalancesAdapter: pallet_balances_adapter = 155,
 
-				#[cfg(feature = "test-env")]
+				#[cfg(feature = "pallet-test-utils")]
 				TestUtils: pallet_test_utils = 255,
 			}
 		}
modifiedruntime/common/maintenance.rsdiffbeforeafterboth
--- a/runtime/common/maintenance.rs
+++ b/runtime/common/maintenance.rs
@@ -85,7 +85,7 @@
 				| RuntimeCall::Session(_)
 				| RuntimeCall::Identity(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),
 
-				#[cfg(feature = "test-env")]
+				#[cfg(feature = "pallet-test-utils")]
 				RuntimeCall::TestUtils(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),
 
 				_ => Ok(ValidTransaction::default()),
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -23,7 +23,7 @@
 	'collator-selection',
 	'foreign-assets',
 	'governance',
-	'test-env',
+	'pallet-test-utils',
 	'preimage',
 	'refungible',
 ]
@@ -156,7 +156,7 @@
 	"pallet-foreign-assets/std",
 
 	'pallet-maintenance/std',
-	'pallet-test-utils/std',
+	'pallet-test-utils?/std',
 ]
 try-runtime = [
 	"pallet-authorship/try-runtime",
@@ -212,7 +212,7 @@
 	'pallet-scheduler/try-runtime',
 	'pallet-structure/try-runtime',
 	'pallet-sudo/try-runtime',
-	'pallet-test-utils/try-runtime',
+	'pallet-test-utils?/try-runtime',
 	'pallet-timestamp/try-runtime',
 	'pallet-transaction-payment/try-runtime',
 	'pallet-treasury/try-runtime',
@@ -226,7 +226,7 @@
 collator-selection = []
 foreign-assets = []
 governance = []
-test-env = []
+gov-test-timings = []
 preimage = []
 refungible = []
 unique-scheduler = []
@@ -345,7 +345,7 @@
 ################################################################################
 # Test dependencies
 
-pallet-test-utils = { workspace = true }
+pallet-test-utils = { workspace = true, optional = true }
 
 ################################################################################
 # Other Dependencies
addedruntime/opal/src/governance_timings.rsdiffbeforeafterboth
--- /dev/null
+++ b/runtime/opal/src/governance_timings.rs
@@ -0,0 +1,54 @@
+use frame_support::parameter_types;
+pub use up_common::{
+	constants::{DAYS, HOURS, MINUTES},
+	types::BlockNumber,
+};
+
+pub mod council {
+	use super::*;
+
+	parameter_types! {
+		pub CouncilMotionDuration: BlockNumber = 1 * HOURS;
+	}
+}
+
+pub mod democracy {
+	use super::*;
+
+	parameter_types! {
+		pub LaunchPeriod: BlockNumber = 1 * HOURS;
+		pub VotingPeriod: BlockNumber = 1 * HOURS;
+		pub FastTrackVotingPeriod: BlockNumber = 10 * MINUTES;
+		pub EnactmentPeriod: BlockNumber = 5 * MINUTES;
+		pub CooloffPeriod: BlockNumber = 1 * HOURS;
+	}
+}
+
+pub mod fellowship {
+	use super::*;
+
+	parameter_types! {
+		pub UndecidingTimeout: BlockNumber = 1 * HOURS;
+	}
+
+	pub mod track {
+		use super::*;
+
+		pub mod democracy_proposals {
+			use super::*;
+
+			pub const PREPARE_PERIOD: BlockNumber = 5 * MINUTES;
+			pub const DECISION_PERIOD: BlockNumber = 1 * HOURS;
+			pub const CONFIRM_PERIOD: BlockNumber = 10 * MINUTES;
+			pub const MIN_ENACTMENT_PERIOD: BlockNumber = 1 * MINUTES;
+		}
+	}
+}
+
+pub mod technical_committee {
+	use super::*;
+
+	parameter_types! {
+		pub TechnicalMotionDuration: BlockNumber = 15 * MINUTES;
+	}
+}
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -38,6 +38,7 @@
 
 mod runtime_common;
 
+pub mod governance_timings;
 pub mod xcm_barrier;
 
 pub use runtime_common::*;
modifiedruntime/quartz/Cargo.tomldiffbeforeafterboth
--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -218,7 +218,7 @@
 preimage = []
 refungible = []
 unique-scheduler = []
-test-env = []
+gov-test-timings = []
 
 ################################################################################
 # local dependencies
modifiedruntime/unique/Cargo.tomldiffbeforeafterboth
--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -221,7 +221,7 @@
 preimage = []
 refungible = []
 unique-scheduler = []
-test-env = []
+gov-test-timings = []
 
 ################################################################################
 # local dependencies