Skip to content

Commit

Permalink
Update Pallet Referenda to support Block Number Provider (#6338)
Browse files Browse the repository at this point in the history
This PR introduces BlockNumberProvider config for the referenda pallet.
closes part of #6297

Polkadot address: 12GyGD3QhT4i2JJpNzvMf96sxxBLWymz4RdGCxRH5Rj5agKW

---------

Co-authored-by: muharem <[email protected]>
  • Loading branch information
dharjeezy and muharem authored Feb 7, 2025
1 parent 917052e commit f08bf1a
Show file tree
Hide file tree
Showing 12 changed files with 281 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl pallet_referenda::Config<AmbassadorReferendaInstance> for Runtime {
type AlarmInterval = AlarmInterval;
type Tracks = tracks::TracksInfo;
type Preimages = Preimage;
type BlockNumberProvider = System;
}

parameter_types! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl pallet_referenda::Config<FellowshipReferendaInstance> for Runtime {
type AlarmInterval = ConstU32<1>;
type Tracks = tracks::TracksInfo;
type Preimages = Preimage;
type BlockNumberProvider = crate::System;
}

pub type FellowshipCollectiveInstance = pallet_ranked_collective::Instance1;
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/rococo/src/governance/fellowship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ impl pallet_referenda::Config<FellowshipReferendaInstance> for Runtime {
type AlarmInterval = AlarmInterval;
type Tracks = TracksInfo;
type Preimages = Preimage;
type BlockNumberProvider = System;
}

pub type FellowshipCollectiveInstance = pallet_ranked_collective::Instance1;
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/rococo/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ impl pallet_referenda::Config for Runtime {
type AlarmInterval = AlarmInterval;
type Tracks = TracksInfo;
type Preimages = Preimage;
type BlockNumberProvider = System;
}
1 change: 1 addition & 0 deletions polkadot/runtime/westend/src/governance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ impl pallet_referenda::Config for Runtime {
type AlarmInterval = AlarmInterval;
type Tracks = TracksInfo;
type Preimages = Preimage;
type BlockNumberProvider = System;
}
14 changes: 14 additions & 0 deletions prdoc/pr_6338.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Update Referenda to Support Block Number Provider

doc:
- audience: Runtime Dev
description: |
This PR makes the referenda pallet uses the relay chain as a block provider for a parachain on a regular schedule.
To migrate existing referenda implementations, simply add `type BlockNumberProvider = System` to have the same behavior as before.

crates:
- name: pallet-referenda
bump: major
2 changes: 2 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ impl pallet_referenda::Config for Runtime {
type AlarmInterval = AlarmInterval;
type Tracks = TracksInfo;
type Preimages = Preimage;
type BlockNumberProvider = System;
}

impl pallet_referenda::Config<pallet_referenda::Instance2> for Runtime {
Expand All @@ -1093,6 +1094,7 @@ impl pallet_referenda::Config<pallet_referenda::Instance2> for Runtime {
type AlarmInterval = AlarmInterval;
type Tracks = TracksInfo;
type Preimages = Preimage;
type BlockNumberProvider = System;
}

impl pallet_ranked_collective::Config for Runtime {
Expand Down
16 changes: 9 additions & 7 deletions substrate/frame/referenda/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ use sp_runtime::traits::Bounded as ArithBounded;

const SEED: u32 = 0;

fn set_block_number<T: Config<I>, I: 'static>(n: BlockNumberFor<T, I>) {
<T as Config<I>>::BlockNumberProvider::set_block_number(n);
}

fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::RuntimeEvent) {
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}
Expand Down Expand Up @@ -151,30 +155,28 @@ fn make_failing<T: Config<I>, I: 'static>(index: ReferendumIndex) {
fn skip_prepare_period<T: Config<I>, I: 'static>(index: ReferendumIndex) {
let status = Referenda::<T, I>::ensure_ongoing(index).unwrap();
let prepare_period_over = status.submitted + info::<T, I>(index).prepare_period;
frame_system::Pallet::<T>::set_block_number(prepare_period_over);
set_block_number::<T, I>(prepare_period_over);
}

fn skip_decision_period<T: Config<I>, I: 'static>(index: ReferendumIndex) {
let status = Referenda::<T, I>::ensure_ongoing(index).unwrap();
let decision_period_over = status.deciding.unwrap().since + info::<T, I>(index).decision_period;
frame_system::Pallet::<T>::set_block_number(decision_period_over);
set_block_number::<T, I>(decision_period_over);
}

fn skip_confirm_period<T: Config<I>, I: 'static>(index: ReferendumIndex) {
let status = Referenda::<T, I>::ensure_ongoing(index).unwrap();
let confirm_period_over = status.deciding.unwrap().confirming.unwrap();
frame_system::Pallet::<T>::set_block_number(confirm_period_over);
set_block_number::<T, I>(confirm_period_over);
}

fn skip_timeout_period<T: Config<I>, I: 'static>(index: ReferendumIndex) {
let status = Referenda::<T, I>::ensure_ongoing(index).unwrap();
let timeout_period_over = status.submitted + T::UndecidingTimeout::get();
frame_system::Pallet::<T>::set_block_number(timeout_period_over);
set_block_number::<T, I>(timeout_period_over);
}

fn alarm_time<T: Config<I>, I: 'static>(
index: ReferendumIndex,
) -> frame_system::pallet_prelude::BlockNumberFor<T> {
fn alarm_time<T: Config<I>, I: 'static>(index: ReferendumIndex) -> BlockNumberFor<T, I> {
let status = Referenda::<T, I>::ensure_ongoing(index).unwrap();
status.alarm.unwrap().0
}
Expand Down
Loading

0 comments on commit f08bf1a

Please sign in to comment.