diff --git a/Cargo.lock b/Cargo.lock index ace24c0bf6c38..b5f644705f4c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3674,6 +3674,7 @@ dependencies = [ "frame-system-rpc-runtime-api 26.0.0", "frame-try-runtime 0.34.0", "hex-literal", + "lazy_static", "log", "pallet-alliance 27.0.0", "pallet-asset-rate 7.0.0", @@ -21689,6 +21690,7 @@ dependencies = [ "frame-system-rpc-runtime-api 26.0.0", "frame-try-runtime 0.34.0", "hex-literal", + "lazy_static", "log", "pallet-asset-rate 7.0.0", "pallet-authority-discovery 28.0.0", @@ -31471,6 +31473,7 @@ dependencies = [ "frame-system-rpc-runtime-api 26.0.0", "frame-try-runtime 0.34.0", "hex-literal", + "lazy_static", "log", "pallet-asset-rate 7.0.0", "pallet-authority-discovery 28.0.0", diff --git a/Cargo.toml b/Cargo.toml index 80026d7d4fe15..686bd7268daef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -846,6 +846,7 @@ kvdb-memorydb = { version = "0.13.0" } kvdb-rocksdb = { version = "0.19.0" } kvdb-shared-tests = { version = "0.11.0" } landlock = { version = "0.3.0" } +lazy_static = { version = "1.5.0", default-features = false, features = ["spin_no_std"] } libc = { version = "0.2.155" } libfuzzer-sys = { version = "0.4" } libp2p = { version = "0.54.1" } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml index f9cc54495aea0..7eccd0b8a600c 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml @@ -14,6 +14,7 @@ workspace = true [dependencies] codec = { features = ["derive", "max-encoded-len"], workspace = true } hex-literal = { workspace = true, default-features = true } +lazy_static = { workspace = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde_json = { features = ["alloc"], workspace = true } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/tracks.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/tracks.rs index aa1f67d18afe4..6c1e5c1133658 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/tracks.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/tracks.rs @@ -17,7 +17,7 @@ use super::Origin; use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, DOLLARS, HOURS}; -use sp_runtime::{str_array as s, Perbill}; +use sp_runtime::{BoundedVec, Perbill}; use sp_std::borrow::Cow; /// Referendum `TrackId` type. @@ -38,24 +38,12 @@ pub mod constants { pub const MASTER_AMBASSADOR_TIER_9: TrackId = 9; } -/// The type implementing the [`pallet_referenda::TracksInfo`] trait for referenda pallet. -pub struct TracksInfo; - -/// Information on the voting tracks. -impl pallet_referenda::TracksInfo for TracksInfo { - type Id = TrackId; - - type RuntimeOrigin = ::PalletsOrigin; - - /// Return the list of available tracks and their information. - fn tracks( - ) -> impl Iterator>> - { - static DATA: [pallet_referenda::Track; 9] = [ +lazy_static::lazy_static! { + pub static ref DATA: [pallet_referenda::Track; 9] = [ pallet_referenda::Track { id: constants::AMBASSADOR_TIER_1, info: pallet_referenda::TrackInfo { - name: s("ambassador tier 1"), + name: BoundedVec::truncate_from(b"ambassador tier 1".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 24 * HOURS, @@ -77,7 +65,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: constants::AMBASSADOR_TIER_2, info: pallet_referenda::TrackInfo { - name: s("ambassador tier 2"), + name: BoundedVec::truncate_from(b"ambassador tier 2".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 24 * HOURS, @@ -99,7 +87,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: constants::SENIOR_AMBASSADOR_TIER_3, info: pallet_referenda::TrackInfo { - name: s("senior ambassador tier 3"), + name: BoundedVec::truncate_from(b"ambassador tier 3".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 24 * HOURS, @@ -121,7 +109,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: constants::SENIOR_AMBASSADOR_TIER_4, info: pallet_referenda::TrackInfo { - name: s("senior ambassador tier 4"), + name: BoundedVec::truncate_from(b"ambassador tier 4".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 24 * HOURS, @@ -143,7 +131,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: constants::HEAD_AMBASSADOR_TIER_5, info: pallet_referenda::TrackInfo { - name: s("head ambassador tier 5"), + name: BoundedVec::truncate_from(b"ambassador tier 5".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 24 * HOURS, @@ -165,7 +153,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: constants::HEAD_AMBASSADOR_TIER_6, info: pallet_referenda::TrackInfo { - name: s("head ambassador tier 6"), + name: BoundedVec::truncate_from(b"ambassador tier 6".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 24 * HOURS, @@ -187,7 +175,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: constants::HEAD_AMBASSADOR_TIER_7, info: pallet_referenda::TrackInfo { - name: s("head ambassador tier 7"), + name: BoundedVec::truncate_from(b"ambassador tier 7".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 24 * HOURS, @@ -209,7 +197,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: constants::MASTER_AMBASSADOR_TIER_8, info: pallet_referenda::TrackInfo { - name: s("master ambassador tier 8"), + name: BoundedVec::truncate_from(b"ambassador tier 8".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 24 * HOURS, @@ -231,7 +219,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: constants::MASTER_AMBASSADOR_TIER_9, info: pallet_referenda::TrackInfo { - name: s("master ambassador tier 9"), + name: BoundedVec::truncate_from(b"ambassador tier 9".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 24 * HOURS, @@ -251,6 +239,21 @@ impl pallet_referenda::TracksInfo for TracksInfo { }, }, ]; +} + +/// The type implementing the [`pallet_referenda::TracksInfo`] trait for referenda pallet. +pub struct TracksInfo; + +/// Information on the voting tracks. +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = TrackId; + + type RuntimeOrigin = ::PalletsOrigin; + + /// Return the list of available tracks and their information. + fn tracks( + ) -> impl Iterator>> + { DATA.iter().map(Cow::Borrowed) } diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/tracks.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/tracks.rs index 6c3c88935dd22..5a028d61cc153 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/tracks.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/tracks.rs @@ -18,7 +18,7 @@ use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, DOLLARS, HOURS, MINUTES}; use pallet_ranked_collective::Rank; -use sp_runtime::{str_array as s, traits::Convert, Perbill}; +use sp_runtime::{traits::Convert, BoundedVec, Perbill}; use sp_std::borrow::Cow; /// Referendum `TrackId` type. @@ -111,20 +111,13 @@ const PROMOTE_MIN_SUPPORT: pallet_referenda::Curve = pallet_referenda::Curve::Li ceil: Perbill::from_percent(100), }; -pub struct TracksInfo; -impl pallet_referenda::TracksInfo for TracksInfo { - type Id = TrackId; - type RuntimeOrigin = ::PalletsOrigin; - - fn tracks( - ) -> impl Iterator>> - { - use constants as tracks; - static DATA: [pallet_referenda::Track; 21] = [ +use constants as tracks; +lazy_static::lazy_static! { + pub static ref DATA: [pallet_referenda::Track; 21] = [ pallet_referenda::Track { id: tracks::MEMBERS, info: pallet_referenda::TrackInfo { - name: s("members"), + name: BoundedVec::truncate_from(b"members".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, @@ -146,7 +139,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::PROFICIENTS, info: pallet_referenda::TrackInfo { - name: s("proficient members"), + name: BoundedVec::truncate_from(b"proficient members".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, @@ -168,7 +161,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::FELLOWS, info: pallet_referenda::TrackInfo { - name: s("fellows"), + name: BoundedVec::truncate_from(b"fellows".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, @@ -190,7 +183,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::ARCHITECTS, info: pallet_referenda::TrackInfo { - name: s("architects"), + name: BoundedVec::truncate_from(b"architects".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, @@ -212,7 +205,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::ARCHITECTS_ADEPT, info: pallet_referenda::TrackInfo { - name: s("architects adept"), + name: BoundedVec::truncate_from(b"architects adept".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, @@ -234,7 +227,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::GRAND_ARCHITECTS, info: pallet_referenda::TrackInfo { - name: s("grand architects"), + name: BoundedVec::truncate_from(b"grand architects".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, @@ -256,7 +249,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::MASTERS, info: pallet_referenda::TrackInfo { - name: s("masters"), + name: BoundedVec::truncate_from(b"masters".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, @@ -278,7 +271,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::MASTERS_CONSTANT, info: pallet_referenda::TrackInfo { - name: s("masters constant"), + name: BoundedVec::truncate_from(b"masters constant".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, @@ -300,7 +293,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::GRAND_MASTERS, info: pallet_referenda::TrackInfo { - name: s("grand masters"), + name: BoundedVec::truncate_from(b"grand masters".to_vec()), max_deciding: 10, decision_deposit: 5 * DOLLARS, prepare_period: 30 * MINUTES, @@ -322,7 +315,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::RETAIN_AT_1DAN, info: pallet_referenda::TrackInfo { - name: s("retain at I Dan"), + name: BoundedVec::truncate_from(b"retain at I Dan".to_vec()), max_deciding: RETAIN_MAX_DECIDING, decision_deposit: RETAIN_DECISION_DEPOSIT, prepare_period: RETAIN_PREPARE_PERIOD, @@ -336,7 +329,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::RETAIN_AT_2DAN, info: pallet_referenda::TrackInfo { - name: s("retain at II Dan"), + name: BoundedVec::truncate_from(b"retain at II Dan".to_vec()), max_deciding: RETAIN_MAX_DECIDING, decision_deposit: RETAIN_DECISION_DEPOSIT, prepare_period: RETAIN_PREPARE_PERIOD, @@ -350,7 +343,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::RETAIN_AT_3DAN, info: pallet_referenda::TrackInfo { - name: s("retain at III Dan"), + name: BoundedVec::truncate_from(b"retain at III Dan".to_vec()), max_deciding: RETAIN_MAX_DECIDING, decision_deposit: RETAIN_DECISION_DEPOSIT, prepare_period: RETAIN_PREPARE_PERIOD, @@ -364,7 +357,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::RETAIN_AT_4DAN, info: pallet_referenda::TrackInfo { - name: s("retain at IV Dan"), + name: BoundedVec::truncate_from(b"retain at IV Dan".to_vec()), max_deciding: RETAIN_MAX_DECIDING, decision_deposit: RETAIN_DECISION_DEPOSIT, prepare_period: RETAIN_PREPARE_PERIOD, @@ -378,7 +371,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::RETAIN_AT_5DAN, info: pallet_referenda::TrackInfo { - name: s("retain at V Dan"), + name: BoundedVec::truncate_from(b"retain at V Dan".to_vec()), max_deciding: RETAIN_MAX_DECIDING, decision_deposit: RETAIN_DECISION_DEPOSIT, prepare_period: RETAIN_PREPARE_PERIOD, @@ -392,7 +385,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::RETAIN_AT_6DAN, info: pallet_referenda::TrackInfo { - name: s("retain at VI Dan"), + name: BoundedVec::truncate_from(b"retain at VI Dan".to_vec()), max_deciding: RETAIN_MAX_DECIDING, decision_deposit: RETAIN_DECISION_DEPOSIT, prepare_period: RETAIN_PREPARE_PERIOD, @@ -406,7 +399,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::PROMOTE_TO_1DAN, info: pallet_referenda::TrackInfo { - name: s("promote to I Dan"), + name: BoundedVec::truncate_from(b"promote to I Dan".to_vec()), max_deciding: PROMOTE_MAX_DECIDING, decision_deposit: PROMOTE_DECISION_DEPOSIT, prepare_period: PROMOTE_PREPARE_PERIOD, @@ -420,7 +413,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::PROMOTE_TO_2DAN, info: pallet_referenda::TrackInfo { - name: s("promote to II Dan"), + name: BoundedVec::truncate_from(b"promote to II Dan".to_vec()), max_deciding: PROMOTE_MAX_DECIDING, decision_deposit: PROMOTE_DECISION_DEPOSIT, prepare_period: PROMOTE_PREPARE_PERIOD, @@ -434,7 +427,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::PROMOTE_TO_3DAN, info: pallet_referenda::TrackInfo { - name: s("promote to III Dan"), + name: BoundedVec::truncate_from(b"promote to III Dan".to_vec()), max_deciding: PROMOTE_MAX_DECIDING, decision_deposit: PROMOTE_DECISION_DEPOSIT, prepare_period: PROMOTE_PREPARE_PERIOD, @@ -448,7 +441,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::PROMOTE_TO_4DAN, info: pallet_referenda::TrackInfo { - name: s("promote to IV Dan"), + name: BoundedVec::truncate_from(b"promote to IV Dan".to_vec()), max_deciding: PROMOTE_MAX_DECIDING, decision_deposit: PROMOTE_DECISION_DEPOSIT, prepare_period: PROMOTE_PREPARE_PERIOD, @@ -462,7 +455,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::PROMOTE_TO_5DAN, info: pallet_referenda::TrackInfo { - name: s("promote to V Dan"), + name: BoundedVec::truncate_from(b"promote to V Dan".to_vec()), max_deciding: PROMOTE_MAX_DECIDING, decision_deposit: PROMOTE_DECISION_DEPOSIT, prepare_period: PROMOTE_PREPARE_PERIOD, @@ -476,7 +469,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { pallet_referenda::Track { id: tracks::PROMOTE_TO_6DAN, info: pallet_referenda::TrackInfo { - name: s("promote to VI Dan"), + name: BoundedVec::truncate_from(b"promote to VI Dan".to_vec()), max_deciding: PROMOTE_MAX_DECIDING, decision_deposit: PROMOTE_DECISION_DEPOSIT, prepare_period: PROMOTE_PREPARE_PERIOD, @@ -488,6 +481,16 @@ impl pallet_referenda::TracksInfo for TracksInfo { }, }, ]; +} + +pub struct TracksInfo; +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = TrackId; + type RuntimeOrigin = ::PalletsOrigin; + + fn tracks( + ) -> impl Iterator>> + { DATA.iter().map(Cow::Borrowed) } fn track_for(id: &Self::RuntimeOrigin) -> Result { diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index 67c7cacc296b9..e7a27d9e21034 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -16,6 +16,7 @@ workspace = true bitvec = { features = ["alloc"], workspace = true } codec = { features = ["derive", "max-encoded-len"], workspace = true } log = { workspace = true } +lazy_static = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde = { workspace = true } serde_derive = { optional = true, workspace = true } diff --git a/polkadot/runtime/rococo/src/governance/fellowship.rs b/polkadot/runtime/rococo/src/governance/fellowship.rs index cb194e05e9ce9..c519f82395704 100644 --- a/polkadot/runtime/rococo/src/governance/fellowship.rs +++ b/polkadot/runtime/rococo/src/governance/fellowship.rs @@ -20,8 +20,8 @@ use alloc::borrow::Cow; use frame_support::traits::{MapSuccess, TryMapSuccess}; use pallet_referenda::{Track, TrackInfo}; use sp_runtime::{ - str_array as s, traits::{CheckedReduceBy, ConstU16, Replace, ReplaceWithDefault}, + BoundedVec, }; use super::*; @@ -33,17 +33,12 @@ parameter_types! { pub const UndecidingTimeout: BlockNumber = 7 * DAYS; } -pub struct TracksInfo; -impl pallet_referenda::TracksInfo for TracksInfo { - type Id = u16; - type RuntimeOrigin = ::PalletsOrigin; - - fn tracks() -> impl Iterator>> { - static DATA: [Track; 10] = [ +lazy_static::lazy_static! { + pub static ref DATA: [Track; 10] = [ Track { id: 0u16, info: TrackInfo { - name: s("candidates"), + name: BoundedVec::truncate_from(b"candidates".to_vec()), max_deciding: 10, decision_deposit: 100 * 3 * CENTS, prepare_period: 30 * MINUTES, @@ -65,7 +60,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { Track { id: 1u16, info: TrackInfo { - name: s("members"), + name: BoundedVec::truncate_from(b"members".to_vec()), max_deciding: 10, decision_deposit: 10 * 3 * CENTS, prepare_period: 30 * MINUTES, @@ -87,7 +82,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { Track { id: 2u16, info: TrackInfo { - name: s("proficients"), + name: BoundedVec::truncate_from(b"proficients".to_vec()), max_deciding: 10, decision_deposit: 10 * 3 * CENTS, prepare_period: 30 * MINUTES, @@ -109,7 +104,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { Track { id: 3u16, info: TrackInfo { - name: s("fellows"), + name: BoundedVec::truncate_from(b"fellows".to_vec()), max_deciding: 10, decision_deposit: 10 * 3 * CENTS, prepare_period: 30 * MINUTES, @@ -131,7 +126,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { Track { id: 4u16, info: TrackInfo { - name: s("senior fellows"), + name: BoundedVec::truncate_from(b"senior fellows".to_vec()), max_deciding: 10, decision_deposit: 10 * 3 * CENTS, prepare_period: 30 * MINUTES, @@ -153,7 +148,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { Track { id: 5u16, info: TrackInfo { - name: s("experts"), + name: BoundedVec::truncate_from(b"experts".to_vec()), max_deciding: 10, decision_deposit: 1 * 3 * CENTS, prepare_period: 30 * MINUTES, @@ -175,7 +170,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { Track { id: 6u16, info: TrackInfo { - name: s("senior experts"), + name: BoundedVec::truncate_from(b"senior experts".to_vec()), max_deciding: 10, decision_deposit: 1 * 3 * CENTS, prepare_period: 30 * MINUTES, @@ -197,7 +192,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { Track { id: 7u16, info: TrackInfo { - name: s("masters"), + name: BoundedVec::truncate_from(b"masters".to_vec()), max_deciding: 10, decision_deposit: 1 * 3 * CENTS, prepare_period: 30 * MINUTES, @@ -219,7 +214,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { Track { id: 8u16, info: TrackInfo { - name: s("senior masters"), + name: BoundedVec::truncate_from(b"senior masters".to_vec()), max_deciding: 10, decision_deposit: 1 * 3 * CENTS, prepare_period: 30 * MINUTES, @@ -241,7 +236,7 @@ impl pallet_referenda::TracksInfo for TracksInfo { Track { id: 9u16, info: TrackInfo { - name: s("grand masters"), + name: BoundedVec::truncate_from(b"grand masters".to_vec()), max_deciding: 10, decision_deposit: 1 * 3 * CENTS, prepare_period: 30 * MINUTES, @@ -261,6 +256,14 @@ impl pallet_referenda::TracksInfo for TracksInfo { }, }, ]; +} + +pub struct TracksInfo; +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = u16; + type RuntimeOrigin = ::PalletsOrigin; + + fn tracks() -> impl Iterator>> { DATA.iter().map(Cow::Borrowed) } fn track_for(id: &Self::RuntimeOrigin) -> Result { diff --git a/polkadot/runtime/rococo/src/governance/tracks.rs b/polkadot/runtime/rococo/src/governance/tracks.rs index 62229ff5ef5c9..79e808e5abdf3 100644 --- a/polkadot/runtime/rococo/src/governance/tracks.rs +++ b/polkadot/runtime/rococo/src/governance/tracks.rs @@ -19,7 +19,7 @@ use super::*; use alloc::borrow::Cow; -use sp_runtime::str_array as s; +use sp_runtime::BoundedVec; const fn percent(x: i32) -> sp_arithmetic::FixedI64 { sp_arithmetic::FixedI64::from_rational(x as u128, 100) @@ -68,218 +68,220 @@ const APP_WHITELISTED_CALLER: Curve = const SUP_WHITELISTED_CALLER: Curve = Curve::make_reciprocal(1, 28, percent(20), percent(5), percent(50)); -const TRACKS_DATA: [pallet_referenda::Track; 15] = [ - pallet_referenda::Track { - id: 0, - info: pallet_referenda::TrackInfo { - name: s("root"), - max_deciding: 1, - decision_deposit: 100 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 12 * MINUTES, - min_enactment_period: 5 * MINUTES, - min_approval: APP_ROOT, - min_support: SUP_ROOT, +lazy_static::lazy_static! { + pub static ref TRACKS_DATA: [pallet_referenda::Track; 15] = [ + pallet_referenda::Track { + id: 0, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"root".to_vec()), + max_deciding: 1, + decision_deposit: 100 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 12 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: APP_ROOT, + min_support: SUP_ROOT, + }, }, - }, - pallet_referenda::Track { - id: 1, - info: pallet_referenda::TrackInfo { - name: s("whitelisted_caller"), - max_deciding: 100, - decision_deposit: 10 * GRAND, - prepare_period: 6 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 4 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_WHITELISTED_CALLER, - min_support: SUP_WHITELISTED_CALLER, + pallet_referenda::Track { + id: 1, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"whitelisted_caller".to_vec()), + max_deciding: 100, + decision_deposit: 10 * GRAND, + prepare_period: 6 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 4 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_WHITELISTED_CALLER, + min_support: SUP_WHITELISTED_CALLER, + }, }, - }, - pallet_referenda::Track { - id: 10, - info: pallet_referenda::TrackInfo { - name: s("staking_admin"), - max_deciding: 10, - decision_deposit: 5 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_STAKING_ADMIN, - min_support: SUP_STAKING_ADMIN, + pallet_referenda::Track { + id: 10, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"staking_admin".to_vec()), + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_STAKING_ADMIN, + min_support: SUP_STAKING_ADMIN, + }, }, - }, - pallet_referenda::Track { - id: 11, - info: pallet_referenda::TrackInfo { - name: s("treasurer"), - max_deciding: 10, - decision_deposit: 1 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 5 * MINUTES, - min_approval: APP_TREASURER, - min_support: SUP_TREASURER, + pallet_referenda::Track { + id: 11, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"treasurer".to_vec()), + max_deciding: 10, + decision_deposit: 1 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: APP_TREASURER, + min_support: SUP_TREASURER, + }, }, - }, - pallet_referenda::Track { - id: 12, - info: pallet_referenda::TrackInfo { - name: s("lease_admin"), - max_deciding: 10, - decision_deposit: 5 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_LEASE_ADMIN, - min_support: SUP_LEASE_ADMIN, + pallet_referenda::Track { + id: 12, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"lease_admin".to_vec()), + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_LEASE_ADMIN, + min_support: SUP_LEASE_ADMIN, + }, }, - }, - pallet_referenda::Track { - id: 13, - info: pallet_referenda::TrackInfo { - name: s("fellowship_admin"), - max_deciding: 10, - decision_deposit: 5 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_FELLOWSHIP_ADMIN, - min_support: SUP_FELLOWSHIP_ADMIN, + pallet_referenda::Track { + id: 13, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"fellowship_admin".to_vec()), + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_FELLOWSHIP_ADMIN, + min_support: SUP_FELLOWSHIP_ADMIN, + }, }, - }, - pallet_referenda::Track { - id: 14, - info: pallet_referenda::TrackInfo { - name: s("general_admin"), - max_deciding: 10, - decision_deposit: 5 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_GENERAL_ADMIN, - min_support: SUP_GENERAL_ADMIN, + pallet_referenda::Track { + id: 14, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"general_admin".to_vec()), + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_GENERAL_ADMIN, + min_support: SUP_GENERAL_ADMIN, + }, }, - }, - pallet_referenda::Track { - id: 15, - info: pallet_referenda::TrackInfo { - name: s("auction_admin"), - max_deciding: 10, - decision_deposit: 5 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_AUCTION_ADMIN, - min_support: SUP_AUCTION_ADMIN, + pallet_referenda::Track { + id: 15, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"auction_admin".to_vec()), + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_AUCTION_ADMIN, + min_support: SUP_AUCTION_ADMIN, + }, }, - }, - pallet_referenda::Track { - id: 20, - info: pallet_referenda::TrackInfo { - name: s("referendum_canceller"), - max_deciding: 1_000, - decision_deposit: 10 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 14 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_REFERENDUM_CANCELLER, - min_support: SUP_REFERENDUM_CANCELLER, + pallet_referenda::Track { + id: 20, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"referendum_canceller".to_vec()), + max_deciding: 1_000, + decision_deposit: 10 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 14 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_REFERENDUM_CANCELLER, + min_support: SUP_REFERENDUM_CANCELLER, + }, }, - }, - pallet_referenda::Track { - id: 21, - info: pallet_referenda::TrackInfo { - name: s("referendum_killer"), - max_deciding: 1_000, - decision_deposit: 50 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_REFERENDUM_KILLER, - min_support: SUP_REFERENDUM_KILLER, + pallet_referenda::Track { + id: 21, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"referendum_killer".to_vec()), + max_deciding: 1_000, + decision_deposit: 50 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_REFERENDUM_KILLER, + min_support: SUP_REFERENDUM_KILLER, + }, }, - }, - pallet_referenda::Track { - id: 30, - info: pallet_referenda::TrackInfo { - name: s("small_tipper"), - max_deciding: 200, - decision_deposit: 1 * 3 * CENTS, - prepare_period: 1 * MINUTES, - decision_period: 14 * MINUTES, - confirm_period: 4 * MINUTES, - min_enactment_period: 1 * MINUTES, - min_approval: APP_SMALL_TIPPER, - min_support: SUP_SMALL_TIPPER, + pallet_referenda::Track { + id: 30, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"small_tipper".to_vec()), + max_deciding: 200, + decision_deposit: 1 * 3 * CENTS, + prepare_period: 1 * MINUTES, + decision_period: 14 * MINUTES, + confirm_period: 4 * MINUTES, + min_enactment_period: 1 * MINUTES, + min_approval: APP_SMALL_TIPPER, + min_support: SUP_SMALL_TIPPER, + }, }, - }, - pallet_referenda::Track { - id: 31, - info: pallet_referenda::TrackInfo { - name: s("big_tipper"), - max_deciding: 100, - decision_deposit: 10 * 3 * CENTS, - prepare_period: 4 * MINUTES, - decision_period: 14 * MINUTES, - confirm_period: 12 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_BIG_TIPPER, - min_support: SUP_BIG_TIPPER, + pallet_referenda::Track { + id: 31, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"big_tipper".to_vec()), + max_deciding: 100, + decision_deposit: 10 * 3 * CENTS, + prepare_period: 4 * MINUTES, + decision_period: 14 * MINUTES, + confirm_period: 12 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_BIG_TIPPER, + min_support: SUP_BIG_TIPPER, + }, }, - }, - pallet_referenda::Track { - id: 32, - info: pallet_referenda::TrackInfo { - name: s("small_spender"), - max_deciding: 50, - decision_deposit: 100 * 3 * CENTS, - prepare_period: 10 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 10 * MINUTES, - min_enactment_period: 5 * MINUTES, - min_approval: APP_SMALL_SPENDER, - min_support: SUP_SMALL_SPENDER, + pallet_referenda::Track { + id: 32, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"small_spender".to_vec()), + max_deciding: 50, + decision_deposit: 100 * 3 * CENTS, + prepare_period: 10 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 10 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: APP_SMALL_SPENDER, + min_support: SUP_SMALL_SPENDER, + }, }, - }, - pallet_referenda::Track { - id: 33, - info: pallet_referenda::TrackInfo { - name: s("medium_spender"), - max_deciding: 50, - decision_deposit: 200 * 3 * CENTS, - prepare_period: 10 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 12 * MINUTES, - min_enactment_period: 5 * MINUTES, - min_approval: APP_MEDIUM_SPENDER, - min_support: SUP_MEDIUM_SPENDER, + pallet_referenda::Track { + id: 33, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"medium_spender".to_vec()), + max_deciding: 50, + decision_deposit: 200 * 3 * CENTS, + prepare_period: 10 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 12 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: APP_MEDIUM_SPENDER, + min_support: SUP_MEDIUM_SPENDER, + }, }, - }, - pallet_referenda::Track { - id: 34, - info: pallet_referenda::TrackInfo { - name: s("big_spender"), - max_deciding: 50, - decision_deposit: 400 * 3 * CENTS, - prepare_period: 10 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 14 * MINUTES, - min_enactment_period: 5 * MINUTES, - min_approval: APP_BIG_SPENDER, - min_support: SUP_BIG_SPENDER, + pallet_referenda::Track { + id: 34, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"big_spender".to_vec()), + max_deciding: 50, + decision_deposit: 400 * 3 * CENTS, + prepare_period: 10 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 14 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: APP_BIG_SPENDER, + min_support: SUP_BIG_SPENDER, + }, }, - }, -]; + ]; +} pub struct TracksInfo; impl pallet_referenda::TracksInfo for TracksInfo { diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index 3317484419a9a..7f64f1f7a6720 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -15,6 +15,7 @@ workspace = true [dependencies] bitvec = { features = ["alloc"], workspace = true } codec = { features = ["derive", "max-encoded-len"], workspace = true } +lazy_static = { workspace = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde = { workspace = true } diff --git a/polkadot/runtime/westend/src/governance/tracks.rs b/polkadot/runtime/westend/src/governance/tracks.rs index 62229ff5ef5c9..34d8166b25fac 100644 --- a/polkadot/runtime/westend/src/governance/tracks.rs +++ b/polkadot/runtime/westend/src/governance/tracks.rs @@ -19,7 +19,7 @@ use super::*; use alloc::borrow::Cow; -use sp_runtime::str_array as s; +use sp_runtime::BoundedVec; const fn percent(x: i32) -> sp_arithmetic::FixedI64 { sp_arithmetic::FixedI64::from_rational(x as u128, 100) @@ -68,218 +68,222 @@ const APP_WHITELISTED_CALLER: Curve = const SUP_WHITELISTED_CALLER: Curve = Curve::make_reciprocal(1, 28, percent(20), percent(5), percent(50)); -const TRACKS_DATA: [pallet_referenda::Track; 15] = [ - pallet_referenda::Track { - id: 0, - info: pallet_referenda::TrackInfo { - name: s("root"), - max_deciding: 1, - decision_deposit: 100 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 12 * MINUTES, - min_enactment_period: 5 * MINUTES, - min_approval: APP_ROOT, - min_support: SUP_ROOT, - }, - }, - pallet_referenda::Track { - id: 1, - info: pallet_referenda::TrackInfo { - name: s("whitelisted_caller"), - max_deciding: 100, - decision_deposit: 10 * GRAND, - prepare_period: 6 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 4 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_WHITELISTED_CALLER, - min_support: SUP_WHITELISTED_CALLER, - }, - }, - pallet_referenda::Track { - id: 10, - info: pallet_referenda::TrackInfo { - name: s("staking_admin"), - max_deciding: 10, - decision_deposit: 5 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_STAKING_ADMIN, - min_support: SUP_STAKING_ADMIN, - }, - }, - pallet_referenda::Track { - id: 11, - info: pallet_referenda::TrackInfo { - name: s("treasurer"), - max_deciding: 10, - decision_deposit: 1 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 5 * MINUTES, - min_approval: APP_TREASURER, - min_support: SUP_TREASURER, - }, - }, - pallet_referenda::Track { - id: 12, - info: pallet_referenda::TrackInfo { - name: s("lease_admin"), - max_deciding: 10, - decision_deposit: 5 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_LEASE_ADMIN, - min_support: SUP_LEASE_ADMIN, - }, - }, - pallet_referenda::Track { - id: 13, - info: pallet_referenda::TrackInfo { - name: s("fellowship_admin"), - max_deciding: 10, - decision_deposit: 5 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_FELLOWSHIP_ADMIN, - min_support: SUP_FELLOWSHIP_ADMIN, - }, - }, - pallet_referenda::Track { - id: 14, - info: pallet_referenda::TrackInfo { - name: s("general_admin"), - max_deciding: 10, - decision_deposit: 5 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_GENERAL_ADMIN, - min_support: SUP_GENERAL_ADMIN, - }, - }, - pallet_referenda::Track { - id: 15, - info: pallet_referenda::TrackInfo { - name: s("auction_admin"), - max_deciding: 10, - decision_deposit: 5 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_AUCTION_ADMIN, - min_support: SUP_AUCTION_ADMIN, - }, - }, - pallet_referenda::Track { - id: 20, - info: pallet_referenda::TrackInfo { - name: s("referendum_canceller"), - max_deciding: 1_000, - decision_deposit: 10 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 14 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_REFERENDUM_CANCELLER, - min_support: SUP_REFERENDUM_CANCELLER, - }, - }, - pallet_referenda::Track { - id: 21, - info: pallet_referenda::TrackInfo { - name: s("referendum_killer"), - max_deciding: 1_000, - decision_deposit: 50 * GRAND, - prepare_period: 8 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 8 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_REFERENDUM_KILLER, - min_support: SUP_REFERENDUM_KILLER, - }, - }, - pallet_referenda::Track { - id: 30, - info: pallet_referenda::TrackInfo { - name: s("small_tipper"), - max_deciding: 200, - decision_deposit: 1 * 3 * CENTS, - prepare_period: 1 * MINUTES, - decision_period: 14 * MINUTES, - confirm_period: 4 * MINUTES, - min_enactment_period: 1 * MINUTES, - min_approval: APP_SMALL_TIPPER, - min_support: SUP_SMALL_TIPPER, - }, - }, - pallet_referenda::Track { - id: 31, - info: pallet_referenda::TrackInfo { - name: s("big_tipper"), - max_deciding: 100, - decision_deposit: 10 * 3 * CENTS, - prepare_period: 4 * MINUTES, - decision_period: 14 * MINUTES, - confirm_period: 12 * MINUTES, - min_enactment_period: 3 * MINUTES, - min_approval: APP_BIG_TIPPER, - min_support: SUP_BIG_TIPPER, - }, - }, - pallet_referenda::Track { - id: 32, - info: pallet_referenda::TrackInfo { - name: s("small_spender"), - max_deciding: 50, - decision_deposit: 100 * 3 * CENTS, - prepare_period: 10 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 10 * MINUTES, - min_enactment_period: 5 * MINUTES, - min_approval: APP_SMALL_SPENDER, - min_support: SUP_SMALL_SPENDER, - }, - }, - pallet_referenda::Track { - id: 33, - info: pallet_referenda::TrackInfo { - name: s("medium_spender"), - max_deciding: 50, - decision_deposit: 200 * 3 * CENTS, - prepare_period: 10 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 12 * MINUTES, - min_enactment_period: 5 * MINUTES, - min_approval: APP_MEDIUM_SPENDER, - min_support: SUP_MEDIUM_SPENDER, - }, - }, - pallet_referenda::Track { - id: 34, - info: pallet_referenda::TrackInfo { - name: s("big_spender"), - max_deciding: 50, - decision_deposit: 400 * 3 * CENTS, - prepare_period: 10 * MINUTES, - decision_period: 20 * MINUTES, - confirm_period: 14 * MINUTES, - min_enactment_period: 5 * MINUTES, - min_approval: APP_BIG_SPENDER, - min_support: SUP_BIG_SPENDER, - }, - }, -]; +lazy_static::lazy_static! { + pub static ref TRACKS_DATA: [pallet_referenda::Track; 15] = { + [ + pallet_referenda::Track { + id: 0, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"root".to_vec()), + max_deciding: 1, + decision_deposit: 100 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 12 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: APP_ROOT, + min_support: SUP_ROOT, + }, + }, + pallet_referenda::Track { + id: 1, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"whitelisted_caller".to_vec()), + max_deciding: 100, + decision_deposit: 10 * GRAND, + prepare_period: 6 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 4 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_WHITELISTED_CALLER, + min_support: SUP_WHITELISTED_CALLER, + }, + }, + pallet_referenda::Track { + id: 10, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"staking_admin".to_vec()), + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_STAKING_ADMIN, + min_support: SUP_STAKING_ADMIN, + }, + }, + pallet_referenda::Track { + id: 11, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"treasurer".to_vec()), + max_deciding: 10, + decision_deposit: 1 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: APP_TREASURER, + min_support: SUP_TREASURER, + }, + }, + pallet_referenda::Track { + id: 12, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"lease_admin".to_vec()), + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_LEASE_ADMIN, + min_support: SUP_LEASE_ADMIN, + }, + }, + pallet_referenda::Track { + id: 13, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"fellowship_admin".to_vec()), + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_FELLOWSHIP_ADMIN, + min_support: SUP_FELLOWSHIP_ADMIN, + }, + }, + pallet_referenda::Track { + id: 14, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"general_admin".to_vec()), + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_GENERAL_ADMIN, + min_support: SUP_GENERAL_ADMIN, + }, + }, + pallet_referenda::Track { + id: 15, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"auction_admin".to_vec()), + max_deciding: 10, + decision_deposit: 5 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_AUCTION_ADMIN, + min_support: SUP_AUCTION_ADMIN, + }, + }, + pallet_referenda::Track { + id: 20, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"referendum_canceller".to_vec()), + max_deciding: 1_000, + decision_deposit: 10 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 14 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_REFERENDUM_CANCELLER, + min_support: SUP_REFERENDUM_CANCELLER, + }, + }, + pallet_referenda::Track { + id: 21, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"referendum_killer".to_vec()), + max_deciding: 1_000, + decision_deposit: 50 * GRAND, + prepare_period: 8 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 8 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_REFERENDUM_KILLER, + min_support: SUP_REFERENDUM_KILLER, + }, + }, + pallet_referenda::Track { + id: 30, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"small_tipper".to_vec()), + max_deciding: 200, + decision_deposit: 1 * 3 * CENTS, + prepare_period: 1 * MINUTES, + decision_period: 14 * MINUTES, + confirm_period: 4 * MINUTES, + min_enactment_period: 1 * MINUTES, + min_approval: APP_SMALL_TIPPER, + min_support: SUP_SMALL_TIPPER, + }, + }, + pallet_referenda::Track { + id: 31, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"big_tipper".to_vec()), + max_deciding: 100, + decision_deposit: 10 * 3 * CENTS, + prepare_period: 4 * MINUTES, + decision_period: 14 * MINUTES, + confirm_period: 12 * MINUTES, + min_enactment_period: 3 * MINUTES, + min_approval: APP_BIG_TIPPER, + min_support: SUP_BIG_TIPPER, + }, + }, + pallet_referenda::Track { + id: 32, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"small_spender".to_vec()), + max_deciding: 50, + decision_deposit: 100 * 3 * CENTS, + prepare_period: 10 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 10 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: APP_SMALL_SPENDER, + min_support: SUP_SMALL_SPENDER, + }, + }, + pallet_referenda::Track { + id: 33, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"medium_spender".to_vec()), + max_deciding: 50, + decision_deposit: 200 * 3 * CENTS, + prepare_period: 10 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 12 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: APP_MEDIUM_SPENDER, + min_support: SUP_MEDIUM_SPENDER, + }, + }, + pallet_referenda::Track { + id: 34, + info: pallet_referenda::TrackInfo { + name: BoundedVec::truncate_from(b"big_spender".to_vec()), + max_deciding: 50, + decision_deposit: 400 * 3 * CENTS, + prepare_period: 10 * MINUTES, + decision_period: 20 * MINUTES, + confirm_period: 14 * MINUTES, + min_enactment_period: 5 * MINUTES, + min_approval: APP_BIG_SPENDER, + min_support: SUP_BIG_SPENDER, + }, + }, + ] + }; +} pub struct TracksInfo; impl pallet_referenda::TracksInfo for TracksInfo { diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 0ea3c770733c5..68b5d37d5a71b 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -2645,7 +2645,7 @@ pub mod dynamic_params { > = BoundedVec::truncate_from(vec![pallet_referenda::Track { id: 0u16, info: pallet_referenda::TrackInfo { - name: s("root"), + name: BoundedVec::truncate_from(b"root".to_vec()), max_deciding: 1, decision_deposit: 10, prepare_period: 4, diff --git a/substrate/frame/referenda/src/mock.rs b/substrate/frame/referenda/src/mock.rs index 52a89d3f7cb7d..0e9b155df03ec 100644 --- a/substrate/frame/referenda/src/mock.rs +++ b/substrate/frame/referenda/src/mock.rs @@ -30,10 +30,10 @@ use frame_support::{ }; use frame_system::{EnsureRoot, EnsureSignedBy}; use sp_runtime::{ - str_array as s, traits::{BlakeTwo256, Hash}, BuildStorage, DispatchResult, Perbill, }; +use std::sync::LazyLock; type Block = frame_system::mocking::MockBlock; @@ -107,74 +107,76 @@ impl TracksInfo for TestTracksInfo { type RuntimeOrigin = ::PalletsOrigin; fn tracks() -> impl Iterator>> { - static DATA: [Track; 3] = [ - Track { - id: 0u8, - info: TrackInfo { - name: s("root"), - max_deciding: 1, - decision_deposit: 10, - prepare_period: 4, - decision_period: 4, - confirm_period: 2, - min_enactment_period: 4, - min_approval: Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(50), - ceil: Perbill::from_percent(100), - }, - min_support: Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(0), - ceil: Perbill::from_percent(100), + static DATA: LazyLock<[Track; 3]> = LazyLock::new(|| { + [ + Track { + id: 0u8, + info: TrackInfo { + name: BoundedVec::truncate_from(b"root".to_vec()), + max_deciding: 1, + decision_deposit: 10, + prepare_period: 4, + decision_period: 4, + confirm_period: 2, + min_enactment_period: 4, + min_approval: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(100), + }, }, }, - }, - Track { - id: 1u8, - info: TrackInfo { - name: s("none"), - max_deciding: 3, - decision_deposit: 1, - prepare_period: 2, - decision_period: 2, - confirm_period: 1, - min_enactment_period: 2, - min_approval: Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(95), - ceil: Perbill::from_percent(100), - }, - min_support: Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(90), - ceil: Perbill::from_percent(100), + Track { + id: 1u8, + info: TrackInfo { + name: BoundedVec::truncate_from(b"none".to_vec()), + max_deciding: 3, + decision_deposit: 1, + prepare_period: 2, + decision_period: 2, + confirm_period: 1, + min_enactment_period: 2, + min_approval: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(95), + ceil: Perbill::from_percent(100), + }, + min_support: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(90), + ceil: Perbill::from_percent(100), + }, }, }, - }, - Track { - id: 2u8, - info: TrackInfo { - name: s("none"), - max_deciding: 3, - decision_deposit: 1, - prepare_period: 2, - decision_period: 2, - confirm_period: 1, - min_enactment_period: 0, - min_approval: Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(95), - ceil: Perbill::from_percent(100), - }, - min_support: Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(90), - ceil: Perbill::from_percent(100), + Track { + id: 2u8, + info: TrackInfo { + name: BoundedVec::truncate_from(b"none".to_vec()), + max_deciding: 3, + decision_deposit: 1, + prepare_period: 2, + decision_period: 2, + confirm_period: 1, + min_enactment_period: 0, + min_approval: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(95), + ceil: Perbill::from_percent(100), + }, + min_support: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(90), + ceil: Perbill::from_percent(100), + }, }, }, - }, - ]; + ] + }); DATA.iter().map(Cow::Borrowed) } fn track_for(id: &Self::RuntimeOrigin) -> Result { diff --git a/substrate/frame/referenda/src/types.rs b/substrate/frame/referenda/src/types.rs index 6a1eb8e82e4e3..545b6e37e00ae 100644 --- a/substrate/frame/referenda/src/types.rs +++ b/substrate/frame/referenda/src/types.rs @@ -23,7 +23,7 @@ use codec::{Decode, Encode, EncodeLike, MaxEncodedLen}; use core::fmt::Debug; use frame_support::{ traits::{schedule::v3::Anon, Bounded}, - Parameter, + BoundedVec, Parameter, }; use scale_info::TypeInfo; use sp_arithmetic::{Rounding::*, SignedRounding::*}; @@ -118,11 +118,20 @@ pub struct Deposit { pub const DEFAULT_MAX_TRACK_NAME_LEN: usize = 25; +pub struct BoundedSize; + +impl Get for BoundedSize { + fn get() -> u32 { + N as u32 + } +} + /// Detailed information about the configuration of a referenda track #[derive(Clone, Encode, Decode, MaxEncodedLen, TypeInfo, Eq, PartialEq, Debug)] pub struct TrackInfo { /// Name of this track. - pub name: [u8; N], + // #[codec(encoded_as = "ArrayLikeVec")] + pub name: BoundedVec>, /// A limit for the number of referenda on this track that can be being decided at once. /// For Root origin this should generally be just one. pub max_deciding: u32, @@ -580,7 +589,8 @@ impl Debug for Curve { mod tests { use super::*; use frame_support::traits::ConstU32; - use sp_runtime::{str_array as s, PerThing}; + use sp_runtime::{traits::TrailingZeroInput, PerThing}; + use std::sync::LazyLock; const fn percent(x: u128) -> FixedI64 { FixedI64::from_rational(x, 100) @@ -733,52 +743,54 @@ mod tests { type Id = u8; type RuntimeOrigin = ::PalletsOrigin; fn tracks() -> impl Iterator>> { - static DATA: [Track; 2] = [ - Track { - id: 1u8, - info: TrackInfo { - name: s("root"), - max_deciding: 1, - decision_deposit: 10, - prepare_period: 4, - decision_period: 4, - confirm_period: 2, - min_enactment_period: 4, - min_approval: Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(50), - ceil: Perbill::from_percent(100), - }, - min_support: Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(0), - ceil: Perbill::from_percent(100), + static DATA: LazyLock<[Track; 2]> = LazyLock::new(|| { + [ + Track { + id: 1u8, + info: TrackInfo { + name: BoundedVec::truncate_from(b"root".to_vec()), + max_deciding: 1, + decision_deposit: 10, + prepare_period: 4, + decision_period: 4, + confirm_period: 2, + min_enactment_period: 4, + min_approval: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(50), + ceil: Perbill::from_percent(100), + }, + min_support: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(0), + ceil: Perbill::from_percent(100), + }, }, }, - }, - Track { - id: 0u8, - info: TrackInfo { - name: s("none"), - max_deciding: 3, - decision_deposit: 1, - prepare_period: 2, - decision_period: 2, - confirm_period: 1, - min_enactment_period: 2, - min_approval: Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(95), - ceil: Perbill::from_percent(100), - }, - min_support: Curve::LinearDecreasing { - length: Perbill::from_percent(100), - floor: Perbill::from_percent(90), - ceil: Perbill::from_percent(100), + Track { + id: 0u8, + info: TrackInfo { + name: BoundedVec::truncate_from(b"none".to_vec()), + max_deciding: 3, + decision_deposit: 1, + prepare_period: 2, + decision_period: 2, + confirm_period: 1, + min_enactment_period: 2, + min_approval: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(95), + ceil: Perbill::from_percent(100), + }, + min_support: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(90), + ceil: Perbill::from_percent(100), + }, }, }, - }, - ]; + ] + }); DATA.iter().map(Cow::Borrowed) } fn track_for(_: &Self::RuntimeOrigin) -> Result { @@ -791,4 +803,38 @@ mod tests { Err("The tracks that were returned by `tracks` were not sorted by `Id`") ); } + + #[test] + fn track_encoding_works() { + let track_info = TrackInfo:: { + name: BoundedVec::truncate_from(b"track name".to_vec()), + max_deciding: 3, + decision_deposit: 1, + prepare_period: 2, + decision_period: 2, + confirm_period: 1, + min_enactment_period: 2, + min_approval: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(95), + ceil: Perbill::from_percent(100), + }, + min_support: Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(90), + ceil: Perbill::from_percent(100), + }, + }; + + let encoded = track_info.encode(); + + let name: Vec = Decode::decode(&mut TrailingZeroInput::new(&encoded.clone())) + .expect("decoding to an array should be supported"); + assert_eq!(name, track_info.name.to_vec()); + + let decoded: TrackInfo = Decode::decode(&mut TrailingZeroInput::new(&encoded)) + .expect("decoding a track should be supported"); + + assert_eq!(decoded, track_info); + } }