Skip to content

Commit f08bf1a

Browse files
dharjeezymuharem
andauthored
Update Pallet Referenda to support Block Number Provider (#6338)
This PR introduces BlockNumberProvider config for the referenda pallet. closes part of #6297 Polkadot address: 12GyGD3QhT4i2JJpNzvMf96sxxBLWymz4RdGCxRH5Rj5agKW --------- Co-authored-by: muharem <[email protected]>
1 parent 917052e commit f08bf1a

File tree

12 files changed

+281
-68
lines changed

12 files changed

+281
-68
lines changed

cumulus/parachains/runtimes/collectives/collectives-westend/src/ambassador/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl pallet_referenda::Config<AmbassadorReferendaInstance> for Runtime {
154154
type AlarmInterval = AlarmInterval;
155155
type Tracks = tracks::TracksInfo;
156156
type Preimages = Preimage;
157+
type BlockNumberProvider = System;
157158
}
158159

159160
parameter_types! {

cumulus/parachains/runtimes/collectives/collectives-westend/src/fellowship/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl pallet_referenda::Config<FellowshipReferendaInstance> for Runtime {
106106
type AlarmInterval = ConstU32<1>;
107107
type Tracks = tracks::TracksInfo;
108108
type Preimages = Preimage;
109+
type BlockNumberProvider = crate::System;
109110
}
110111

111112
pub type FellowshipCollectiveInstance = pallet_ranked_collective::Instance1;

polkadot/runtime/rococo/src/governance/fellowship.rs

+1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ impl pallet_referenda::Config<FellowshipReferendaInstance> for Runtime {
308308
type AlarmInterval = AlarmInterval;
309309
type Tracks = TracksInfo;
310310
type Preimages = Preimage;
311+
type BlockNumberProvider = System;
311312
}
312313

313314
pub type FellowshipCollectiveInstance = pallet_ranked_collective::Instance1;

polkadot/runtime/rococo/src/governance/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,5 @@ impl pallet_referenda::Config for Runtime {
9090
type AlarmInterval = AlarmInterval;
9191
type Tracks = TracksInfo;
9292
type Preimages = Preimage;
93+
type BlockNumberProvider = System;
9394
}

polkadot/runtime/westend/src/governance/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,5 @@ impl pallet_referenda::Config for Runtime {
9494
type AlarmInterval = AlarmInterval;
9595
type Tracks = TracksInfo;
9696
type Preimages = Preimage;
97+
type BlockNumberProvider = System;
9798
}

prdoc/pr_6338.prdoc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: Update Referenda to Support Block Number Provider
5+
6+
doc:
7+
- audience: Runtime Dev
8+
description: |
9+
This PR makes the referenda pallet uses the relay chain as a block provider for a parachain on a regular schedule.
10+
To migrate existing referenda implementations, simply add `type BlockNumberProvider = System` to have the same behavior as before.
11+
12+
crates:
13+
- name: pallet-referenda
14+
bump: major

substrate/bin/node/runtime/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ impl pallet_referenda::Config for Runtime {
10731073
type AlarmInterval = AlarmInterval;
10741074
type Tracks = TracksInfo;
10751075
type Preimages = Preimage;
1076+
type BlockNumberProvider = System;
10761077
}
10771078

10781079
impl pallet_referenda::Config<pallet_referenda::Instance2> for Runtime {
@@ -1093,6 +1094,7 @@ impl pallet_referenda::Config<pallet_referenda::Instance2> for Runtime {
10931094
type AlarmInterval = AlarmInterval;
10941095
type Tracks = TracksInfo;
10951096
type Preimages = Preimage;
1097+
type BlockNumberProvider = System;
10961098
}
10971099

10981100
impl pallet_ranked_collective::Config for Runtime {

substrate/frame/referenda/src/benchmarking.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ use sp_runtime::traits::Bounded as ArithBounded;
3333

3434
const SEED: u32 = 0;
3535

36+
fn set_block_number<T: Config<I>, I: 'static>(n: BlockNumberFor<T, I>) {
37+
<T as Config<I>>::BlockNumberProvider::set_block_number(n);
38+
}
39+
3640
fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::RuntimeEvent) {
3741
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
3842
}
@@ -151,30 +155,28 @@ fn make_failing<T: Config<I>, I: 'static>(index: ReferendumIndex) {
151155
fn skip_prepare_period<T: Config<I>, I: 'static>(index: ReferendumIndex) {
152156
let status = Referenda::<T, I>::ensure_ongoing(index).unwrap();
153157
let prepare_period_over = status.submitted + info::<T, I>(index).prepare_period;
154-
frame_system::Pallet::<T>::set_block_number(prepare_period_over);
158+
set_block_number::<T, I>(prepare_period_over);
155159
}
156160

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

163167
fn skip_confirm_period<T: Config<I>, I: 'static>(index: ReferendumIndex) {
164168
let status = Referenda::<T, I>::ensure_ongoing(index).unwrap();
165169
let confirm_period_over = status.deciding.unwrap().confirming.unwrap();
166-
frame_system::Pallet::<T>::set_block_number(confirm_period_over);
170+
set_block_number::<T, I>(confirm_period_over);
167171
}
168172

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

175-
fn alarm_time<T: Config<I>, I: 'static>(
176-
index: ReferendumIndex,
177-
) -> frame_system::pallet_prelude::BlockNumberFor<T> {
179+
fn alarm_time<T: Config<I>, I: 'static>(index: ReferendumIndex) -> BlockNumberFor<T, I> {
178180
let status = Referenda::<T, I>::ensure_ongoing(index).unwrap();
179181
status.alarm.unwrap().0
180182
}

0 commit comments

Comments
 (0)