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 8 commits into
base: master
Choose a base branch
from

Conversation

dharjeezy
Copy link
Contributor

@dharjeezy dharjeezy commented Nov 2, 2024

This PR introduces BlockNumberProvider config for the referenda pallet.
closes part of #6297

Polkadot address: 12GyGD3QhT4i2JJpNzvMf96sxxBLWymz4RdGCxRH5Rj5agKW

@dharjeezy dharjeezy requested a review from a team as a code owner November 2, 2024 11:19
@@ -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.
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we force the block number to be the one in system?
If the block number provider is RelayChainDataProvider, then the block number can be different.

It would be more clean to keep it generic here.
Then we should use a new type:

type BlockNumberFor<T> = <<Self as Config>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;
Suggested change
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
type BlockNumberProvider: BlockNumberProvider;

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we should not require the same block number type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gui1117 shouldn't it be

pub type BlockNumberFor<T, I> = <<T as Config<I>>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;

since the referenda pallet is an Instantiable one?

Copy link
Contributor

@gui1117 gui1117 Nov 18, 2024

Choose a reason for hiding this comment

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

Yes, also we can name it ProvidedBlockNumberFor to avoid conflict with system type alias.

@gui1117 gui1117 added the T2-pallets This PR/Issue is related to a particular pallet. label Nov 4, 2024
@paritytech-review-bot paritytech-review-bot bot requested a review from a team November 18, 2024 14:53
@dharjeezy dharjeezy requested a review from gui1117 November 18, 2024 15:19
@dharjeezy
Copy link
Contributor Author

can you help review this again @gui1117

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Could you also provide a migration that migrates from one block number type to another? Especially take into account the different block times.

Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

looks good to me.

Comment on lines 145 to 147
use super::*;
use frame_support::{pallet_prelude::*, traits::EnsureOriginWithArg};
use frame_system::pallet_prelude::*;
use frame_system::pallet_prelude::{OriginFor, BlockNumberFor as SystemBlockNumberFor, ensure_root, ensure_signed_or_root, ensure_signed};
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this could be replaced with:

	use super::{*, BlockNumberFor};
	use frame_support::{pallet_prelude::*, traits::EnsureOriginWithArg};
	use frame_system::pallet_prelude::{*, BlockNumberFor as SystemBlockNumberFor};

But as you prefer.

Comment on lines +9 to +10
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't force the referenda pallet to use the relay chain block provider.

Suggested change
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.
This PR makes the block number provider used in the referenda pallet configurable. Before this PR, referenda pallet always used the system block number, with this PR some runtime can opt to use the relay chain block number instead.
To migrate existing referenda implementations, simply add `type BlockNumberProvider = System` to have the same behavior as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet.
Projects
Status: Scheduled
Development

Successfully merging this pull request may close these issues.

3 participants