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 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fmt
  • Loading branch information
PolkadotDom committed Dec 23, 2024
commit 77741b30d690167902a345c4a60d2c72ba95b1d9
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ pub use ambassador::pallet_ambassador_origins;
use alloc::{vec, vec::Vec};
use ambassador::{AmbassadorCoreInstance, AmbassadorSalaryInstance};
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
use fellowship::{pallet_fellowship_origins, Fellows, FellowshipCoreInstance, FellowshipSalaryInstance};
use fellowship::{
pallet_fellowship_origins, Fellows, FellowshipCoreInstance, FellowshipSalaryInstance,
};
use impls::{AllianceProposalProvider, EqualOrGreatestRootCmp};
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
Expand Down Expand Up @@ -763,21 +765,26 @@ type Migrations = (
// unreleased
pallet_core_fellowship::migration::MigrateV0ToV1<Runtime, AmbassadorCoreInstance>,
// unreleased
pallet_salary::migration::MigrateV0ToV1<Runtime, SalaryBlockNumberConverter, FellowshipSalaryInstance>,
pallet_salary::migration::MigrateV0ToV1<Runtime, SalaryBlockNumberConverter, AmbassadorSalaryInstance>,
pallet_salary::migration::MigrateV0ToV1<
Runtime,
SalaryBlockNumberConverter,
FellowshipSalaryInstance,
>,
pallet_salary::migration::MigrateV0ToV1<
Runtime,
SalaryBlockNumberConverter,
AmbassadorSalaryInstance,
>,
);

// Helpers for the salary pallet v0->v1 storage migration.
use sp_runtime::traits::BlockNumberProvider;
type SalaryLocalBlockNumber = <System as BlockNumberProvider>::BlockNumber;
type SalaryNewBlockNumber = <cumulus_pallet_parachain_system::RelaychainDataProvider<Runtime>
type SalaryNewBlockNumber = <cumulus_pallet_parachain_system::RelaychainDataProvider<Runtime>
as BlockNumberProvider>::BlockNumber;
pub struct SalaryBlockNumberConverter;
impl
pallet_salary::migration::v1::ConvertBlockNumber<
SalaryLocalBlockNumber,
SalaryNewBlockNumber,
> for SalaryBlockNumberConverter
impl pallet_salary::migration::v1::ConvertBlockNumber<SalaryLocalBlockNumber, SalaryNewBlockNumber>
for SalaryBlockNumberConverter
{
/// Simply convert the types. Cycle index storage item uses block number but is agnostic to the
/// time that denotes for instance
Expand All @@ -787,9 +794,7 @@ impl

/// The equivalent moment in time from the perspective of the relay chain, starting from a
/// local moment in time (system block number)
fn equivalent_moment_in_time(
local: SalaryLocalBlockNumber,
) -> SalaryNewBlockNumber {
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.

let relay_duration = Self::equivalent_block_duration(local_duration); //6s to 6s
Expand All @@ -800,9 +805,7 @@ impl
/// The equivalent duration from the perspective of the relay chain, starting from
/// a local duration (number of block). Identity function for Westend, since both
/// relay and collectives chain run 6s block times
fn equivalent_block_duration(
local: SalaryLocalBlockNumber,
) -> SalaryNewBlockNumber {
fn equivalent_block_duration(local: SalaryLocalBlockNumber) -> SalaryNewBlockNumber {
local
}
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/salary/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#![cfg(feature = "runtime-benchmarks")]

use super::*;
use crate::{Pallet as Salary, BlockNumberFor as SalaryBlockNumberFor};
use crate::{BlockNumberFor as SalaryBlockNumberFor, Pallet as Salary};

use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
Expand Down
12 changes: 7 additions & 5 deletions substrate/frame/salary/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ mod tests;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod weights;
pub mod migration;
pub mod weights;

pub use pallet::*;
pub use weights::WeightInfo;
Expand Down Expand Up @@ -90,9 +90,9 @@ pub struct ClaimantStatus<CycleIndex, Balance, Id> {
pub mod pallet {
use super::*;
use frame_support::{dispatch::Pays, pallet_prelude::*};
use frame_system::pallet_prelude::{OriginFor, ensure_signed};
use frame_system::pallet_prelude::{ensure_signed, OriginFor};
use sp_runtime::traits::BlockNumberProvider;

/// The in-code storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

Expand Down Expand Up @@ -153,12 +153,14 @@ pub mod pallet {
type BlockNumberProvider: BlockNumberProvider;
}

pub type BlockNumberFor<T, I> = <<T as Config<I>>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;
pub type BlockNumberFor<T, I> =
<<T as Config<I>>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;
pub type CycleIndexOf<T, I> = BlockNumberFor<T, I>;
pub type BalanceOf<T, I> = <<T as Config<I>>::Paymaster as Pay>::Balance;
pub type IdOf<T, I> = <<T as Config<I>>::Paymaster as Pay>::Id;
pub type StatusOf<T, I> = StatusType<CycleIndexOf<T, I>, BlockNumberFor<T, I>, BalanceOf<T, I>>;
pub type ClaimantStatusOf<T, I> = ClaimantStatus<CycleIndexOf<T, I>, BalanceOf<T, I>, IdOf<T, I>>;
pub type ClaimantStatusOf<T, I> =
ClaimantStatus<CycleIndexOf<T, I>, BalanceOf<T, I>, IdOf<T, I>>;

/// The overall status of the system.
#[pallet::storage]
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/salary/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub mod v1 {
/// 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


/// Returns the equivalent time duration as the previous type when represented as the new
/// Returns the equivalent time duration as the previous type when represented as the new
/// type
///
/// For instance - If you previously had 12s blocks and are now following the relay chain's
Expand Down Expand Up @@ -118,7 +118,7 @@ pub mod v1 {
},
);

T::DbWeight::get().reads_writes(transactions, transactions)
T::DbWeight::get().reads_writes(transactions, transactions)
}

#[cfg(feature = "try-runtime")]
Expand Down