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

Add BlockNumberProvider to salary pallet config #7000

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

PolkadotDom
Copy link
Contributor

@PolkadotDom PolkadotDom commented Dec 25, 2024

Following #3617, salary pallet is to be made async backing friendly. This PR adds the block number provider config parameter to pallet-salary.

In addition it

  • Adds the migration code for those teams who want to transition and need it
  • Applies the migration on Westend

TODO:
Once Westend is updated I will write the migration for polkadot collectives.

@xlc
@gupnik Tracking list

@PolkadotDom PolkadotDom requested a review from a team as a code owner December 25, 2024 16:22
@PolkadotDom PolkadotDom changed the title Dom/salary block provider Add BlockNumberProvider to salary pallet config Dec 25, 2024
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, with the pre and post upgrade implementation

/// local moment in time (system block number)
fn equivalent_moment_in_time(local: SalaryLocalBlockNumber) -> SalaryNewBlockNumber {
let block_number = System::block_number();
let local_duration = block_number.saturating_sub(local);
Copy link
Contributor

Choose a reason for hiding this comment

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

same maybe better to make it general if local > block_number, to be safe if this code gets copied and pasted.

where
BC: ConvertBlockNumber<LocalBlockNumberFor<T>, NewBlockNumberFor<T, I>>,
{
fn on_runtime_upgrade() -> frame_support::weights::Weight {
Copy link
Contributor

Choose a reason for hiding this comment

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

could be better to implement some pre_upgrade and post_upgrade ensuring that Status value is some if it was some, and claimant count is same before and after the migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. Though out of curiosity, is it possible for this not to be the case given the on_runtime_upgrade code? May be missing something about rust or substrate here.

@gui1117 gui1117 added the T2-pallets This PR/Issue is related to a particular pallet. label Dec 30, 2024
Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

Looks very clean, thanks. Only had some minor comments, going to take a closer look after that.

@@ -177,7 +177,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 268,
impl_version: 0,
impl_version: 1,
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
impl_version: 1,
impl_version: 0,

The kitchensink runtime needs to bumping.

Copy link
Contributor Author

@PolkadotDom PolkadotDom Jan 6, 2025

Choose a reason for hiding this comment

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

The kitchensink runtime needs to bumping.

Assuming 'no' bumping was meant - is this because its also bumped automatically on release like the spec_version or because the change to the runtime was sufficient to warrant a bump?

In any case, will revert. Just curious!

Copy link
Contributor

Choose a reason for hiding this comment

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

impl_version is when it is a change in the code without a change in the specification in the runtime.

I guess, both spec_version and impl_version will be bumped automatically using the prdoc information, but I can't confirm

substrate/frame/salary/src/lib.rs Outdated Show resolved Hide resolved
substrate/frame/salary/src/migration.rs Show resolved Hide resolved
use super::{BlockNumberFor as NewBlockNumberFor, *};
use frame_system::pallet_prelude::BlockNumberFor as LocalBlockNumberFor;

/// Converts previous (local) block number into the new one. May just be identity functions
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
/// Converts previous (local) block number into the new one. May just be identity functions
/// Converts old block number into the new one. May just be identity functions

Is there an inherent local/remote duality, or is it just old/new?

Copy link
Contributor Author

@PolkadotDom PolkadotDom Jan 6, 2025

Choose a reason for hiding this comment

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

Inherent local -> whatever you've now decided (new)

In the context of this migration because the salary pallet previously did not allow selection of a block provider, it defaulted to frame_system's, which is always local I believe. However, @gui1117 did point out this code may be copy pasted so if you think generalizing it is best, I can make the change 👍 Just let me know.

///
/// For instance - if your new version uses the relay chain number, you'll want to
/// use relay current - ((current local - local) * equivalent_block_duration)
fn equivalent_moment_in_time(local: L) -> N;
Copy link
Member

Choose a reason for hiding this comment

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

Can you put some example in the doc of this please? Just some pseudo code of how it is supposed to be called.
I can imagine it is easy to call it the other way around of how its meant to be 🙈

Copy link
Contributor Author

@PolkadotDom PolkadotDom Jan 6, 2025

Choose a reason for hiding this comment

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

Have updated the docs for each function. Let me know if sufficient

@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 6, 2025 22:17
@PolkadotDom PolkadotDom requested review from gui1117 and ggwpez January 7, 2025 17:33
@PolkadotDom PolkadotDom requested a review from a team as a code owner January 9, 2025 00:33
@PolkadotDom
Copy link
Contributor Author

Looks like there's still some issues to fix. Hold off on re-review 🙏

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
None yet
Development

Successfully merging this pull request may close these issues.

3 participants