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

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
@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.

substrate/frame/referenda/src/lib.rs Outdated Show resolved Hide resolved
@acatangiu
Copy link
Contributor

@dharjeezy this is nearly done, will you take it over the finish line?

@dharjeezy
Copy link
Contributor Author

dharjeezy commented Jan 14, 2025

@dharjeezy this is nearly done, will you take it over the finish line?

i have updated the PR with the migration written. @acatangiu @bkchr

RuntimeOrigin = <Self::RuntimeOrigin as OriginTrait>::PalletsOrigin,
>;

/// The preimage provider.
type Preimages: QueryPreimage<H = Self::Hashing> + StorePreimage;

/// Provider for the block number. Normally this is the `frame_system` pallet.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Provider for the block number. Normally this is the `frame_system` pallet.
/// Provider for the block number.
///
/// Normally this is the `frame_system` pallet.

@@ -161,6 +178,98 @@ pub mod v1 {
}
}

pub mod v2 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub mod v2 {
/// Migration for when changing the block number provider.
pub mod switch_block_number_provider {

use super::*;

/// The log target.
const TARGET: &'static str = "runtime::referenda::migration::v2";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const TARGET: &'static str = "runtime::referenda::migration::v2";
const TARGET: &'static str = "runtime::referenda::migration::change_block_number_provider";

Comment on lines 187 to 191
pub trait BlockToRelayHeightConversion<T: Config<I>, I: 'static> {
fn convert_block_number_to_relay_height(
block_number: SystemBlockNumberFor<T>,
) -> BlockNumberFor<T, I>;
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub trait BlockToRelayHeightConversion<T: Config<I>, I: 'static> {
fn convert_block_number_to_relay_height(
block_number: SystemBlockNumberFor<T>,
) -> BlockNumberFor<T, I>;
}
/// Convert from one to another block number provider/type.
pub trait BlockNumberConversion<Old, New> {
/// Convert the `old` block number type to the new block number type.
///
/// Any changes in the rate of blocks need to be taken into account.
fn convert_block_number(
block_number: Old,
) -> New;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not addressed. @bkchr

Comment on lines 222 to 225
if on_chain_version != 1 {
log::warn!(target: TARGET, "skipping migration from v1 to v2.");
return weight
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if on_chain_version != 1 {
log::warn!(target: TARGET, "skipping migration from v1 to v2.");
return weight
}

Please add a comment to the migration that this is not guarded.

}

/// Transforms SystemBlockNumberFor<T> to BlockNumberFor<T,I>
pub struct MigrateV1ToV2<BlockConversion, T, I = ()>(
Copy link
Member

Choose a reason for hiding this comment

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

IMO this should probably just be a standalone function. Downstream people need to write their own migration with some custom guarding or whatever to ensure that they don't apply it multiple times.

@dharjeezy dharjeezy requested a review from bkchr January 16, 2025 14:32
@gui1117 gui1117 self-requested a review January 25, 2025 10:26
@gui1117
Copy link
Contributor

gui1117 commented Jan 25, 2025

you can see the failing jobs on the top with the new github merge experience, see at the bottom of the page.

Then you can see rustdoc build is failing.

substrate/frame/referenda/src/migration.rs Outdated Show resolved Hide resolved
substrate/frame/referenda/src/migration.rs Outdated Show resolved Hide resolved
Comment on lines +98 to +111
pub(crate) type ReferendumInfoOf<T, I> = ReferendumInfo<
TrackIdOf<T, I>,
PalletsOriginOf<T>,
SystemBlockNumberFor<T>,
BoundedCallOf<T, I>,
BalanceOf<T, I>,
TallyOf<T, I>,
<T as frame_system::Config>::AccountId,
ScheduleAddressOf<T, I>,
>;

#[storage_alias]
pub type ReferendumInfoFor<T: Config<I>, I: 'static> =
StorageMap<Pallet<T, I>, Blake2_128Concat, ReferendumIndex, ReferendumInfoOf<T, I>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I would move it to the other module. And consider the V1 storage to be with the provided block number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But why? isn't the reason why this was declared here is to tell that this Type and Storage was supported in v1?

Copy link
Contributor

Choose a reason for hiding this comment

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

let's consider we implement this as storage version 2.

I have my pallet in my chain in storage version 1.
I update the version of my pallet without changing the block number provider, the migration executes don't change the storage and write storage version 2.
Then I want to change the BlockNumberProvider.
I can't reuse the logic, the pallet is already in version 2.

Copy link
Contributor

@gui1117 gui1117 Feb 1, 2025

Choose a reason for hiding this comment

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

but maybe it is better to keep this storage here.

If the type BlockNumber is changing, they would want to do the migration v0 -> v1 -> migrate_block_number_provider
If we change the type here to the provided block number then they will have to write a manual migration.

Maybe you were right when implementing with v2. And we should have both a v1 to v2 migration and a migrate_block_number_provider standalone migration.
But because everybody use u32 for block number I think having v0 -> v1 -> migrate_block_number_provider is ok.

In conclusion: I think it is good as it is.

substrate/frame/referenda/src/migration.rs Show resolved Hide resolved
substrate/frame/referenda/src/migration.rs Outdated Show resolved Hide resolved
substrate/frame/referenda/src/migration.rs Show resolved Hide resolved
substrate/frame/referenda/src/migration.rs Show resolved Hide resolved
substrate/frame/referenda/src/migration.rs Show resolved Hide resolved
@muharem muharem self-requested a review January 27, 2025 03:59
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.

Looks good, modulo the comments from Gui around the migration.


impl BlockNumberConversion<SystemBlockNumberFor<T>, BlockNumberFor<T, ()>> for MockBlockConverter {
fn convert_block_number(block_number: SystemBlockNumberFor<T>) -> BlockNumberFor<T, ()> {
block_number as u64
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to make it not constant ? add a delay like block_number + 10

pub struct MockBlockConverter;

impl BlockNumberConversion<SystemBlockNumberFor<T>, BlockNumberFor<T, ()>> for MockBlockConverter {
fn convert_block_number(block_number: SystemBlockNumberFor<T>) -> BlockNumberFor<T, ()> {
Copy link
Contributor

Choose a reason for hiding this comment

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

In the mock both are System but I think it is ok.

@gui1117
Copy link
Contributor

gui1117 commented Feb 1, 2025

CI is failing because some unused variable

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

@muharem
Copy link
Contributor

muharem commented Feb 3, 2025

@dharjeezy please check this comment - #6297 (comment)

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: Audited
Development

Successfully merging this pull request may close these issues.

6 participants