-
Notifications
You must be signed in to change notification settings - Fork 810
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
Merged
muharem
merged 20 commits into
paritytech:master
from
dharjeezy:dami/pallet_referenda_block_number_provider
Feb 7, 2025
Merged
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
46abe42
Update Pallet Referenda to support relay chain Block Number Provider
dharjeezy fd92baa
Include BlockNumberProvider for all runtime configs
dharjeezy 57be43c
introduce custom BlockProvider type
dharjeezy e62fe61
fmt
dharjeezy da6dbe1
fix benchmarks
dharjeezy a25aa88
Merge remote-tracking branch 'origin/master' into dami/pallet_referen…
dharjeezy 059e1bd
Merge remote-tracking branch 'origin/master' into dami/pallet_referen…
dharjeezy 0cd84f0
fmt benchmarks
dharjeezy 975c50c
Merge remote-tracking branch 'origin/master' into dami/pallet_referen…
dharjeezy 76e5f94
migration
dharjeezy 3214f28
doc
dharjeezy c905dcf
conversation nits
dharjeezy f488c51
change trait for conversion in migration
dharjeezy 12c1476
standalone function for migration
dharjeezy 678991b
standalone function for migration
dharjeezy 77ab73d
test to migrate from v1 to block number provider
dharjeezy f79afd8
nit on conversation
dharjeezy b95e228
nit based on conversation
dharjeezy 0f9749a
revert
dharjeezy 41c7300
Merge branch 'master' into dami/pallet_referenda_block_number_provider
muharem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
dharjeezy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
crates: | ||
- name: pallet-referenda | ||
bump: minor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -105,6 +105,7 @@ pub use self::{ | |||||||||
}, | ||||||||||
weights::WeightInfo, | ||||||||||
}; | ||||||||||
use sp_runtime::traits::BlockNumberProvider; | ||||||||||
pub use alloc::vec::Vec; | ||||||||||
|
||||||||||
#[cfg(test)] | ||||||||||
|
@@ -239,6 +240,9 @@ pub mod pallet { | |||||||||
|
||||||||||
/// The preimage provider. | ||||||||||
type Preimages: QueryPreimage<H = Self::Hashing> + StorePreimage; | ||||||||||
|
||||||||||
/// Provider for the block number. Normally this is the `frame_system` pallet. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>; | ||||||||||
dharjeezy marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
} | ||||||||||
|
||||||||||
/// The next free referendum index, aka the number of referenda started so far. | ||||||||||
|
@@ -485,7 +489,7 @@ pub mod pallet { | |||||||||
*x += 1; | ||||||||||
r | ||||||||||
}); | ||||||||||
let now = frame_system::Pallet::<T>::block_number(); | ||||||||||
let now = T::BlockNumberProvider::current_block_number(); | ||||||||||
let nudge_call = | ||||||||||
T::Preimages::bound(CallOf::<T, I>::from(Call::nudge_referendum { index }))?; | ||||||||||
let status = ReferendumStatus { | ||||||||||
|
@@ -527,7 +531,7 @@ pub mod pallet { | |||||||||
let track = Self::track(status.track).ok_or(Error::<T, I>::NoTrack)?; | ||||||||||
status.decision_deposit = | ||||||||||
Some(Self::take_deposit(who.clone(), track.decision_deposit)?); | ||||||||||
let now = frame_system::Pallet::<T>::block_number(); | ||||||||||
let now = T::BlockNumberProvider::current_block_number(); | ||||||||||
let (info, _, branch) = Self::service_referendum(now, index, status); | ||||||||||
ReferendumInfoFor::<T, I>::insert(index, info); | ||||||||||
let e = | ||||||||||
|
@@ -584,7 +588,7 @@ pub mod pallet { | |||||||||
Self::note_one_fewer_deciding(status.track); | ||||||||||
Self::deposit_event(Event::<T, I>::Cancelled { index, tally: status.tally }); | ||||||||||
let info = ReferendumInfo::Cancelled( | ||||||||||
frame_system::Pallet::<T>::block_number(), | ||||||||||
T::BlockNumberProvider::current_block_number(), | ||||||||||
Some(status.submission_deposit), | ||||||||||
status.decision_deposit, | ||||||||||
); | ||||||||||
|
@@ -611,7 +615,7 @@ pub mod pallet { | |||||||||
Self::slash_deposit(Some(status.submission_deposit.clone())); | ||||||||||
Self::slash_deposit(status.decision_deposit.clone()); | ||||||||||
Self::do_clear_metadata(index); | ||||||||||
let info = ReferendumInfo::Killed(frame_system::Pallet::<T>::block_number()); | ||||||||||
let info = ReferendumInfo::Killed(T::BlockNumberProvider::current_block_number()); | ||||||||||
ReferendumInfoFor::<T, I>::insert(index, info); | ||||||||||
Ok(()) | ||||||||||
} | ||||||||||
|
@@ -627,7 +631,7 @@ pub mod pallet { | |||||||||
index: ReferendumIndex, | ||||||||||
) -> DispatchResultWithPostInfo { | ||||||||||
ensure_root(origin)?; | ||||||||||
let now = frame_system::Pallet::<T>::block_number(); | ||||||||||
let now = T::BlockNumberProvider::current_block_number(); | ||||||||||
let mut status = Self::ensure_ongoing(index)?; | ||||||||||
// This is our wake-up, so we can disregard the alarm. | ||||||||||
status.alarm = None; | ||||||||||
|
@@ -658,7 +662,7 @@ pub mod pallet { | |||||||||
let mut track_queue = TrackQueue::<T, I>::get(track); | ||||||||||
let branch = | ||||||||||
if let Some((index, mut status)) = Self::next_for_deciding(&mut track_queue) { | ||||||||||
let now = frame_system::Pallet::<T>::block_number(); | ||||||||||
let now = T::BlockNumberProvider::current_block_number(); | ||||||||||
let (maybe_alarm, branch) = | ||||||||||
Self::begin_deciding(&mut status, index, now, track_info); | ||||||||||
if let Some(set_alarm) = maybe_alarm { | ||||||||||
|
@@ -758,7 +762,7 @@ impl<T: Config<I>, I: 'static> Polling<T::Tally> for Pallet<T, I> { | |||||||||
match ReferendumInfoFor::<T, I>::get(index) { | ||||||||||
Some(ReferendumInfo::Ongoing(mut status)) => { | ||||||||||
let result = f(PollStatus::Ongoing(&mut status.tally, status.track)); | ||||||||||
let now = frame_system::Pallet::<T>::block_number(); | ||||||||||
let now = T::BlockNumberProvider::current_block_number(); | ||||||||||
Self::ensure_alarm_at(&mut status, index, now + One::one()); | ||||||||||
ReferendumInfoFor::<T, I>::insert(index, ReferendumInfo::Ongoing(status)); | ||||||||||
result | ||||||||||
|
@@ -778,7 +782,7 @@ impl<T: Config<I>, I: 'static> Polling<T::Tally> for Pallet<T, I> { | |||||||||
match ReferendumInfoFor::<T, I>::get(index) { | ||||||||||
Some(ReferendumInfo::Ongoing(mut status)) => { | ||||||||||
let result = f(PollStatus::Ongoing(&mut status.tally, status.track))?; | ||||||||||
let now = frame_system::Pallet::<T>::block_number(); | ||||||||||
let now = T::BlockNumberProvider::current_block_number(); | ||||||||||
Self::ensure_alarm_at(&mut status, index, now + One::one()); | ||||||||||
ReferendumInfoFor::<T, I>::insert(index, ReferendumInfo::Ongoing(status)); | ||||||||||
Ok(result) | ||||||||||
|
@@ -800,7 +804,7 @@ impl<T: Config<I>, I: 'static> Polling<T::Tally> for Pallet<T, I> { | |||||||||
*x += 1; | ||||||||||
r | ||||||||||
}); | ||||||||||
let now = frame_system::Pallet::<T>::block_number(); | ||||||||||
let now = T::BlockNumberProvider::current_block_number(); | ||||||||||
let dummy_account_id = | ||||||||||
codec::Decode::decode(&mut sp_runtime::traits::TrailingZeroInput::new(&b"dummy"[..])) | ||||||||||
.expect("infinite length input; no invalid inputs for type; qed"); | ||||||||||
|
@@ -828,7 +832,7 @@ impl<T: Config<I>, I: 'static> Polling<T::Tally> for Pallet<T, I> { | |||||||||
let mut status = Self::ensure_ongoing(index).map_err(|_| ())?; | ||||||||||
Self::ensure_no_alarm(&mut status); | ||||||||||
Self::note_one_fewer_deciding(status.track); | ||||||||||
let now = frame_system::Pallet::<T>::block_number(); | ||||||||||
let now = T::BlockNumberProvider::current_block_number(); | ||||||||||
let info = if approved { | ||||||||||
ReferendumInfo::Approved(now, Some(status.submission_deposit), status.decision_deposit) | ||||||||||
} else { | ||||||||||
|
@@ -868,7 +872,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> { | |||||||||
ReferendumInfo::Ongoing(status) => { | ||||||||||
let track = Self::track(status.track).ok_or(Error::<T, I>::NoTrack)?; | ||||||||||
let elapsed = if let Some(deciding) = status.deciding { | ||||||||||
frame_system::Pallet::<T>::block_number().saturating_sub(deciding.since) | ||||||||||
T::BlockNumberProvider::current_block_number().saturating_sub(deciding.since) | ||||||||||
} else { | ||||||||||
Zero::zero() | ||||||||||
}; | ||||||||||
|
@@ -893,7 +897,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> { | |||||||||
origin: PalletsOriginOf<T>, | ||||||||||
call: BoundedCallOf<T, I>, | ||||||||||
) { | ||||||||||
let now = frame_system::Pallet::<T>::block_number(); | ||||||||||
let now = T::BlockNumberProvider::current_block_number(); | ||||||||||
// Earliest allowed block is always at minimum the next block. | ||||||||||
let earliest_allowed = now.saturating_add(track.min_enactment_period.max(One::one())); | ||||||||||
let desired = desired.evaluate(now); | ||||||||||
|
@@ -931,7 +935,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> { | |||||||||
result.is_ok(), | ||||||||||
"Unable to schedule a new alarm at #{:?} (now: #{:?}), scheduler error: `{:?}`", | ||||||||||
when, | ||||||||||
frame_system::Pallet::<T>::block_number(), | ||||||||||
T::BlockNumberProvider::current_block_number(), | ||||||||||
result.unwrap_err(), | ||||||||||
); | ||||||||||
result.ok().map(|x| (when, x)) | ||||||||||
|
@@ -1023,7 +1027,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> { | |||||||||
/// overall more efficient), however the weights become rather less easy to measure. | ||||||||||
fn note_one_fewer_deciding(track: TrackIdOf<T, I>) { | ||||||||||
// Set an alarm call for the next block to nudge the track along. | ||||||||||
let now = frame_system::Pallet::<T>::block_number(); | ||||||||||
let now = T::BlockNumberProvider::current_block_number(); | ||||||||||
let next_block = now + One::one(); | ||||||||||
let call = match T::Preimages::bound(CallOf::<T, I>::from(Call::one_fewer_deciding { | ||||||||||
track, | ||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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