Skip to content

Commit

Permalink
Change TracksInfo::tracks to return an iterator
Browse files Browse the repository at this point in the history
Using an iterator instead of a static slice allows for more flexible
implementations of `TracksInfo` that can use the chain storage without
compromising a lot on the performance/memory penalty if we were to return
an owned `Vec` instead.
  • Loading branch information
olanod committed Oct 30, 2023
1 parent a706171 commit 4bc9edc
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 295 deletions.
109 changes: 56 additions & 53 deletions polkadot/runtime/rococo/src/governance/fellowship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
//! Elements of governance concerning the Rococo Fellowship.
use frame_support::traits::{MapSuccess, TryMapSuccess};
use pallet_referenda::{Track, TrackInfo};
use sp_runtime::traits::{CheckedReduceBy, ConstU16, Replace};
use sp_std::borrow::Cow::{self, Borrowed};

use super::*;
use crate::{CENTS, DAYS};
Expand All @@ -32,12 +34,13 @@ pub struct TracksInfo;
impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
type Id = u16;
type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {
static DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 10] = [
(
0u16,
pallet_referenda::TrackInfo {
name: "candidates",

fn tracks() -> impl Iterator<Item = Cow<'static, Track<Self::Id, Balance, BlockNumber>>> {
static DATA: [Track<u16, Balance, BlockNumber>; 10] = [
Track {
id: 0u16,
info: TrackInfo {
name: Borrowed("candidates"),
max_deciding: 10,
decision_deposit: 100 * 3 * CENTS,
prepare_period: 30 * MINUTES,
Expand All @@ -55,11 +58,11 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
ceil: Perbill::from_percent(50),
},
},
),
(
1u16,
pallet_referenda::TrackInfo {
name: "members",
},
Track {
id: 1u16,
info: TrackInfo {
name: Borrowed("members"),
max_deciding: 10,
decision_deposit: 10 * 3 * CENTS,
prepare_period: 30 * MINUTES,
Expand All @@ -77,11 +80,11 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
ceil: Perbill::from_percent(50),
},
},
),
(
2u16,
pallet_referenda::TrackInfo {
name: "proficients",
},
Track {
id: 2u16,
info: TrackInfo {
name: Borrowed("proficients"),
max_deciding: 10,
decision_deposit: 10 * 3 * CENTS,
prepare_period: 30 * MINUTES,
Expand All @@ -99,11 +102,11 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
ceil: Perbill::from_percent(50),
},
},
),
(
3u16,
pallet_referenda::TrackInfo {
name: "fellows",
},
Track {
id: 3u16,
info: TrackInfo {
name: Borrowed("fellows"),
max_deciding: 10,
decision_deposit: 10 * 3 * CENTS,
prepare_period: 30 * MINUTES,
Expand All @@ -121,11 +124,11 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
ceil: Perbill::from_percent(50),
},
},
),
(
4u16,
pallet_referenda::TrackInfo {
name: "senior fellows",
},
Track {
id: 4u16,
info: TrackInfo {
name: Borrowed("senior fellows"),
max_deciding: 10,
decision_deposit: 10 * 3 * CENTS,
prepare_period: 30 * MINUTES,
Expand All @@ -143,11 +146,11 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
ceil: Perbill::from_percent(50),
},
},
),
(
5u16,
pallet_referenda::TrackInfo {
name: "experts",
},
Track {
id: 5u16,
info: TrackInfo {
name: Borrowed("experts"),
max_deciding: 10,
decision_deposit: 1 * 3 * CENTS,
prepare_period: 30 * MINUTES,
Expand All @@ -165,11 +168,11 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
ceil: Perbill::from_percent(50),
},
},
),
(
6u16,
pallet_referenda::TrackInfo {
name: "senior experts",
},
Track {
id: 6u16,
info: TrackInfo {
name: Borrowed("senior experts"),
max_deciding: 10,
decision_deposit: 1 * 3 * CENTS,
prepare_period: 30 * MINUTES,
Expand All @@ -187,11 +190,11 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
ceil: Perbill::from_percent(50),
},
},
),
(
7u16,
pallet_referenda::TrackInfo {
name: "masters",
},
Track {
id: 7u16,
info: TrackInfo {
name: Borrowed("masters"),
max_deciding: 10,
decision_deposit: 1 * 3 * CENTS,
prepare_period: 30 * MINUTES,
Expand All @@ -209,11 +212,11 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
ceil: Perbill::from_percent(50),
},
},
),
(
8u16,
pallet_referenda::TrackInfo {
name: "senior masters",
},
Track {
id: 8u16,
info: TrackInfo {
name: Borrowed("senior masters"),
max_deciding: 10,
decision_deposit: 1 * 3 * CENTS,
prepare_period: 30 * MINUTES,
Expand All @@ -231,11 +234,11 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
ceil: Perbill::from_percent(50),
},
},
),
(
9u16,
pallet_referenda::TrackInfo {
name: "grand masters",
},
Track {
id: 9u16,
info: TrackInfo {
name: Borrowed("grand masters"),
max_deciding: 10,
decision_deposit: 1 * 3 * CENTS,
prepare_period: 30 * MINUTES,
Expand All @@ -253,9 +256,9 @@ impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
ceil: Perbill::from_percent(50),
},
},
),
},
];
&DATA[..]
DATA.iter().map(Borrowed)
}
fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
use super::origins::Origin;
Expand Down
Loading

0 comments on commit 4bc9edc

Please sign in to comment.