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

Adds BlockNumberProvider in multisig, proxy and nft pallets #5723

Merged
merged 11 commits into from
Nov 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = MaxSignatories;
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down Expand Up @@ -652,6 +653,7 @@ impl pallet_proxy::Config for Runtime {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -918,6 +920,7 @@ impl pallet_nfts::Config for Runtime {
type WeightInfo = weights::pallet_nfts::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

/// XCM router instance to BridgeHub with bridging capabilities for `Westend` global
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = MaxSignatories;
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down Expand Up @@ -651,6 +652,7 @@ impl pallet_proxy::Config for Runtime {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -912,6 +914,7 @@ impl pallet_nfts::Config for Runtime {
type WeightInfo = weights::pallet_nfts::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

/// XCM router instance to BridgeHub with bridging capabilities for `Rococo` global
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = ConstU32<100>;
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = ConstU32<100>;
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = ConstU32<100>;
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down Expand Up @@ -382,6 +383,7 @@ impl pallet_proxy::Config for Runtime {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

parameter_types! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = ConstU32<100>;
type WeightInfo = pallet_multisig::weights::SubstrateWeight<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = ConstU32<100>;
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

/// The type used to represent the kinds of proxying allowed.
Expand Down Expand Up @@ -576,6 +577,7 @@ impl pallet_proxy::Config for Runtime {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = ConstU32<100>;
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

/// The type used to represent the kinds of proxying allowed.
Expand Down Expand Up @@ -577,6 +578,7 @@ impl pallet_proxy::Config for Runtime {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down
2 changes: 2 additions & 0 deletions cumulus/parachains/runtimes/people/people-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = ConstU32<100>;
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

/// The type used to represent the kinds of proxying allowed.
Expand Down Expand Up @@ -519,6 +520,7 @@ impl pallet_proxy::Config for Runtime {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down
2 changes: 2 additions & 0 deletions cumulus/parachains/runtimes/people/people-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = ConstU32<100>;
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

/// The type used to represent the kinds of proxying allowed.
Expand Down Expand Up @@ -518,6 +519,7 @@ impl pallet_proxy::Config for Runtime {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down
2 changes: 2 additions & 0 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = MaxSignatories;
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -966,6 +967,7 @@ impl pallet_proxy::Config for Runtime {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl parachains_origin::Config for Runtime {}
Expand Down
2 changes: 2 additions & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = MaxSignatories;
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -1198,6 +1199,7 @@ impl pallet_proxy::Config for Runtime {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl parachains_origin::Config for Runtime {}
Expand Down
15 changes: 15 additions & 0 deletions prdoc/pr_5723.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
title: Adds `BlockNumberProvider` in multisig, proxy and nft pallets

doc:
- audience: Runtime Dev
description: |
This would allow these pallets to use the relay chain block number when deployed on a parachain.
gupnik marked this conversation as resolved.
Show resolved Hide resolved
However, we would need migrations if the deployed pallets are upgraded on an existing parachain.

crates:
- name: pallet-multisig
bump: major
- name: pallet-proxy
bump: major
- name: pallet-nfts
bump: major
3 changes: 3 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ impl pallet_multisig::Config for Runtime {
type DepositFactor = DepositFactor;
type MaxSignatories = ConstU32<100>;
type WeightInfo = pallet_multisig::weights::SubstrateWeight<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -441,6 +442,7 @@ impl pallet_proxy::Config for Runtime {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

parameter_types! {
Expand Down Expand Up @@ -2005,6 +2007,7 @@ impl pallet_nfts::Config for Runtime {
type Helper = ();
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type Locker = ();
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_transaction_storage::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ impl pallet_proxy::Config for Test {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = ConstU64<1>;
type AnnouncementDepositFactor = ConstU64<1>;
type BlockNumberProvider = frame_system::Pallet<Test>;
}

impl pallet_dummy::Config for Test {}
Expand Down
7 changes: 5 additions & 2 deletions substrate/frame/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use frame_system::{self as system, pallet_prelude::BlockNumberFor, RawOrigin};
use scale_info::TypeInfo;
use sp_io::hashing::blake2_256;
use sp_runtime::{
traits::{Dispatchable, TrailingZeroInput, Zero},
traits::{BlockNumberProvider, Dispatchable, TrailingZeroInput, Zero},
DispatchError, RuntimeDebug,
};
pub use weights::WeightInfo;
Expand Down Expand Up @@ -168,6 +168,9 @@ pub mod pallet {

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;

/// Provider for the block number. Normally this is the `frame_system` pallet.
gupnik marked this conversation as resolved.
Show resolved Hide resolved
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
}

/// The in-code storage version.
Expand Down Expand Up @@ -641,7 +644,7 @@ impl<T: Config> Pallet<T> {
/// The current `Timepoint`.
pub fn timepoint() -> Timepoint<BlockNumberFor<T>> {
Timepoint {
height: <system::Pallet<T>>::block_number(),
height: T::BlockNumberProvider::current_block_number(),
index: <system::Pallet<T>>::extrinsic_index().unwrap_or_default(),
}
}
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/multisig/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl Config for Test {
type DepositFactor = ConstU64<1>;
type MaxSignatories = ConstU32<3>;
type WeightInfo = ();
type BlockNumberProvider = frame_system::Pallet<Test>;
}

use pallet_balances::Call as BalancesCall;
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/nft-fractionalization/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl pallet_nfts::Config for Test {
type OffchainSignature = Signature;
type OffchainPublic = AccountPublic;
type WeightInfo = ();
type BlockNumberProvider = frame_system::Pallet<Test>;
pallet_nfts::runtime_benchmarks_enabled! {
type Helper = ();
}
Expand Down
9 changes: 6 additions & 3 deletions substrate/frame/nfts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use frame_support::traits::{
};
use frame_system::Config as SystemConfig;
use sp_runtime::{
traits::{IdentifyAccount, Saturating, StaticLookup, Verify, Zero},
traits::{BlockNumberProvider, IdentifyAccount, Saturating, StaticLookup, Verify, Zero},
RuntimeDebug,
};

Expand Down Expand Up @@ -242,6 +242,9 @@ pub mod pallet {

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;

/// Provider for the block number. Normally this is the `frame_system` pallet.
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
}

/// Details of a collection.
Expand Down Expand Up @@ -857,7 +860,7 @@ pub mod pallet {
item_config,
|collection_details, collection_config| {
let mint_settings = collection_config.mint_settings;
let now = frame_system::Pallet::<T>::block_number();
let now = T::BlockNumberProvider::current_block_number();

if let Some(start_block) = mint_settings.start_block {
ensure!(start_block <= now, Error::<T, I>::MintNotStarted);
Expand Down Expand Up @@ -1029,7 +1032,7 @@ pub mod pallet {
let deadline =
details.approvals.get(&origin).ok_or(Error::<T, I>::NoPermission)?;
if let Some(d) = deadline {
let block_number = frame_system::Pallet::<T>::block_number();
let block_number = T::BlockNumberProvider::current_block_number();
ensure!(block_number <= *d, Error::<T, I>::ApprovalExpired);
}
}
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/nfts/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl Config for Test {
type WeightInfo = ();
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type BlockNumberProvider = frame_system::Pallet<Test>;
}

pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
Expand Down
13 changes: 9 additions & 4 deletions substrate/frame/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ pub use pallet::*;
use scale_info::TypeInfo;
use sp_io::hashing::blake2_256;
use sp_runtime::{
traits::{Dispatchable, Hash, Saturating, StaticLookup, TrailingZeroInput, Zero},
traits::{
BlockNumberProvider, Dispatchable, Hash, Saturating, StaticLookup, TrailingZeroInput, Zero,
},
DispatchError, DispatchResult, RuntimeDebug,
};
pub use weights::WeightInfo;
Expand Down Expand Up @@ -176,6 +178,9 @@ pub mod pallet {
/// into a pre-existing storage value.
#[pallet::constant]
type AnnouncementDepositFactor: Get<BalanceOf<Self>>;

/// Provider for the block number. Normally this is the `frame_system` pallet.
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
gupnik marked this conversation as resolved.
Show resolved Hide resolved
}

#[pallet::call]
Expand Down Expand Up @@ -392,7 +397,7 @@ pub mod pallet {
let announcement = Announcement {
real: real.clone(),
call_hash,
height: system::Pallet::<T>::block_number(),
height: T::BlockNumberProvider::current_block_number(),
gupnik marked this conversation as resolved.
Show resolved Hide resolved
};

Announcements::<T>::try_mutate(&who, |(ref mut pending, ref mut deposit)| {
Expand Down Expand Up @@ -503,7 +508,7 @@ pub mod pallet {
let def = Self::find_proxy(&real, &delegate, force_proxy_type)?;

let call_hash = T::CallHasher::hash_of(&call);
let now = system::Pallet::<T>::block_number();
let now = T::BlockNumberProvider::current_block_number();
Self::edit_announcements(&delegate, |ann| {
ann.real != real ||
ann.call_hash != call_hash ||
Expand Down Expand Up @@ -639,7 +644,7 @@ impl<T: Config> Pallet<T> {
) -> T::AccountId {
let (height, ext_index) = maybe_when.unwrap_or_else(|| {
(
system::Pallet::<T>::block_number(),
T::BlockNumberProvider::current_block_number(),
system::Pallet::<T>::extrinsic_index().unwrap_or_default(),
)
});
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/proxy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl Config for Test {
type MaxPending = ConstU32<2>;
type AnnouncementDepositBase = ConstU64<1>;
type AnnouncementDepositFactor = ConstU64<1>;
type BlockNumberProvider = frame_system::Pallet<Test>;
}

use super::{Call as ProxyCall, Event as ProxyEvent};
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/revive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ impl pallet_proxy::Config for Test {
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = ConstU64<1>;
type AnnouncementDepositFactor = ConstU64<1>;
type BlockNumberProvider = frame_system::Pallet<Test>;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/safe-mode/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl pallet_proxy::Config for Test {
type MaxPending = ConstU32<2>;
type AnnouncementDepositBase = ConstU64<1>;
type AnnouncementDepositFactor = ConstU64<1>;
type BlockNumberProvider = frame_system::Pallet<Test>;
}

/// The calls that can always bypass safe-mode.
Expand Down
Loading
Loading