Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pallet Referenda to support Block Number Provider #6338

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what you mean with this sentence. the PR provides a new configuration

To migrate existing referenda implementations, simply add `type BlockNumberProvider = System` to have the same behavior as before.
dharjeezy marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -1045,6 +1045,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 @@ -1065,6 +1066,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
Loading