Moves Block to frame_system instead of construct_runtime and removes Header and BlockNumber (#14437)

* Initial setup

* Adds node block

* Uses UncheckedExtrinsic and removes Where section

* Updates frame_system to use Block

* Adds deprecation warning

* Fixes pallet-timestamp

* Removes Header and BlockNumber

* Addresses review comments

* Addresses review comments

* Adds comment about compiler bug

* Removes where clause

* Refactors code

* Fixes errors in cargo check

* Fixes errors in cargo check

* Fixes warnings in cargo check

* Formatting

* Fixes construct_runtime tests

* Uses import instead of full path for BlockNumber

* Uses import instead of full path for Header

* Formatting

* Fixes construct_runtime tests

* Fixes imports in benchmarks

* Formatting

* Fixes construct_runtime tests

* Formatting

* Minor updates

* Fixes construct_runtime ui tests

* Fixes construct_runtime ui tests with 1.70

* Fixes docs

* Fixes docs

* Adds u128 mock block type

* Fixes split example

* fixes for cumulus

* ".git/.scripts/commands/fmt/fmt.sh"

* Updates new tests

* Fixes fully-qualified path in few places

* Formatting

* Update frame/examples/default-config/src/lib.rs

Co-authored-by: Juan <juangirini@gmail.com>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Juan <juangirini@gmail.com>

* ".git/.scripts/commands/fmt/fmt.sh"

* Addresses some review comments

* Fixes build

* ".git/.scripts/commands/fmt/fmt.sh"

* Update frame/democracy/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/democracy/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Addresses review comments

* Updates trait bounds

* Minor fix

* ".git/.scripts/commands/fmt/fmt.sh"

* Removes unnecessary bound

* ".git/.scripts/commands/fmt/fmt.sh"

* Updates test

* Fixes build

* Adds a bound for header

* ".git/.scripts/commands/fmt/fmt.sh"

* Removes where block

* Minor fix

* Minor fix

* Fixes tests

* ".git/.scripts/commands/update-ui/update-ui.sh" 1.70

* Updates test

* Update primitives/runtime/src/traits.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update primitives/runtime/src/traits.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Updates doc

* Updates doc

---------

Co-authored-by: command-bot <>
Co-authored-by: Juan <juangirini@gmail.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
gupnik
2023-07-13 17:31:34 +05:30
committed by GitHub
parent e42a669c50
commit 5e7b27e98c
277 changed files with 2017 additions and 2450 deletions
@@ -2,20 +2,15 @@ use crate as pallet_template;
use frame_support::traits::{ConstU16, ConstU64};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
TemplateModule: pallet_template,
@@ -30,12 +25,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+3 -10
View File
@@ -155,6 +155,8 @@ parameter_types! {
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = frame_support::traits::Everything;
/// The block type for the runtime.
type Block = Block;
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/// The maximum length of a block (in bytes).
@@ -167,14 +169,10 @@ impl frame_system::Config for Runtime {
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The index type for blocks.
type BlockNumber = BlockNumber;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The hashing algorithm used.
type Hashing = BlakeTwo256;
/// The header type.
type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
/// The ubiquitous origin type.
@@ -278,12 +276,7 @@ impl pallet_template::Config for Runtime {
// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub struct Runtime
where
Block = Block,
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
pub struct Runtime {
System: frame_system,
Timestamp: pallet_timestamp,
Aura: pallet_aura,
+2 -6
View File
@@ -227,12 +227,11 @@ impl frame_system::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = Index;
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = Indices;
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = Version;
@@ -1868,10 +1867,7 @@ impl pallet_statement::Config for Runtime {
}
construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = node_primitives::Block,
UncheckedExtrinsic = UncheckedExtrinsic
pub struct Runtime
{
System: frame_system,
Utility: pallet_utility,
+3 -3
View File
@@ -27,7 +27,7 @@ use sp_std::{
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, BenchmarkError};
use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable};
use frame_system::{Pallet as System, RawOrigin as SystemOrigin};
use frame_system::{pallet_prelude::BlockNumberFor, Pallet as System, RawOrigin as SystemOrigin};
use super::{Call as AllianceCall, Pallet as Alliance, *};
@@ -432,7 +432,7 @@ benchmarks_instance_pallet! {
false,
)?;
System::<T>::set_block_number(T::BlockNumber::max_value());
System::<T>::set_block_number(BlockNumberFor::<T>::max_value());
}: close(SystemOrigin::Signed(voter), last_hash.clone(), index, Weight::MAX, bytes_in_storage)
verify {
@@ -504,7 +504,7 @@ benchmarks_instance_pallet! {
}
// caller is prime, prime already votes aye by creating the proposal
System::<T>::set_block_number(T::BlockNumber::max_value());
System::<T>::set_block_number(BlockNumberFor::<T>::max_value());
}: close(SystemOrigin::Signed(voter), last_hash.clone(), index, Weight::MAX, bytes_in_storage)
verify {
+2 -2
View File
@@ -309,7 +309,7 @@ pub mod pallet {
/// The number of blocks a member must wait between giving a retirement notice and retiring.
/// Supposed to be greater than time required to `kick_member`.
type RetirementPeriod: Get<Self::BlockNumber>;
type RetirementPeriod: Get<BlockNumberFor<Self>>;
}
#[pallet::error]
@@ -477,7 +477,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn retiring_members)]
pub type RetiringMembers<T: Config<I>, I: 'static = ()> =
StorageMap<_, Blake2_128Concat, T::AccountId, T::BlockNumber, OptionQuery>;
StorageMap<_, Blake2_128Concat, T::AccountId, BlockNumberFor<T>, OptionQuery>;
/// The current list of accounts deemed unscrupulous. These accounts non grata cannot submit
/// candidacy.
+2 -8
View File
@@ -20,7 +20,6 @@
pub use sp_core::H256;
use sp_runtime::traits::Hash;
pub use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
@@ -53,12 +52,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = BlockNumber;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
@@ -238,14 +236,10 @@ impl Config for Test {
type RetirementPeriod = RetirementPeriod;
}
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
Balances: pallet_balances,
+5 -2
View File
@@ -72,7 +72,10 @@ use frame_support::{
ensure,
traits::tokens::{AssetId, Balance},
};
use frame_system::{ensure_signed, pallet_prelude::OriginFor};
use frame_system::{
ensure_signed,
pallet_prelude::{BlockNumberFor, OriginFor},
};
pub use pallet::*;
use sp_arithmetic::traits::Unsigned;
use sp_runtime::{
@@ -357,7 +360,7 @@ pub mod pallet {
}
#[pallet::hooks]
impl<T: Config> Hooks<T::BlockNumber> for Pallet<T> {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn integrity_test() {
assert!(
T::MaxSwapPathLength::get() > 1,
+2 -8
View File
@@ -31,18 +31,13 @@ use frame_system::{EnsureSigned, EnsureSignedBy};
use sp_arithmetic::Permill;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{AccountIdConversion, BlakeTwo256, IdentityLookup},
BuildStorage,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
Balances: pallet_balances,
@@ -59,12 +54,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u128;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
+2 -8
View File
@@ -21,19 +21,14 @@ use crate as pallet_asset_rate;
use frame_support::traits::{ConstU16, ConstU64};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
AssetRate: pallet_asset_rate,
@@ -49,12 +44,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+2 -8
View File
@@ -28,19 +28,14 @@ use frame_support::{
use sp_core::H256;
use sp_io::storage;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -58,12 +53,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
+3 -2
View File
@@ -50,6 +50,7 @@ use frame_support::{
weights::Weight,
RuntimeDebugNoBound,
};
use frame_system::pallet_prelude::BlockNumberFor;
use scale_info::TypeInfo;
use sp_io::hashing::blake2_256;
use sp_runtime::RuntimeDebug;
@@ -69,7 +70,7 @@ pub struct PendingSwap<T: Config> {
/// Action of this swap.
pub action: T::SwapAction,
/// End block of the lock.
pub end_block: T::BlockNumber,
pub end_block: BlockNumberFor<T>,
}
/// Hashed proof type.
@@ -249,7 +250,7 @@ pub mod pallet {
target: T::AccountId,
hashed_proof: HashedProof,
action: T::SwapAction,
duration: T::BlockNumber,
duration: BlockNumberFor<T>,
) -> DispatchResult {
let source = ensure_signed(origin)?;
ensure!(
+2 -8
View File
@@ -6,19 +6,14 @@ use crate as pallet_atomic_swap;
use frame_support::traits::{ConstU32, ConstU64};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -33,13 +28,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+2 -2
View File
@@ -102,7 +102,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: T::BlockNumber) -> Weight {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
if let Some(new_slot) = Self::current_slot_from_digests() {
let current_slot = CurrentSlot::<T>::get();
@@ -134,7 +134,7 @@ pub mod pallet {
}
#[cfg(feature = "try-runtime")]
fn try_state(_: T::BlockNumber) -> Result<(), sp_runtime::TryRuntimeError> {
fn try_state(_: BlockNumberFor<T>) -> Result<(), sp_runtime::TryRuntimeError> {
Self::do_try_state()
}
}
+3 -12
View File
@@ -26,20 +26,12 @@ use frame_support::{
};
use sp_consensus_aura::{ed25519::AuthorityId, AuthorityIndex};
use sp_core::H256;
use sp_runtime::{
testing::{Header, UintAuthorityId},
traits::IdentityLookup,
BuildStorage,
};
use sp_runtime::{testing::UintAuthorityId, traits::IdentityLookup, BuildStorage};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
@@ -54,13 +46,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -177,19 +177,15 @@ mod tests {
use sp_core::{crypto::key_types, H256};
use sp_io::TestExternalities;
use sp_runtime::{
testing::{Header, UintAuthorityId},
testing::UintAuthorityId,
traits::{ConvertInto, IdentityLookup, OpaqueKeys},
BuildStorage, KeyTypeId, Perbill,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
@@ -236,13 +232,12 @@ mod tests {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = BlockNumber;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = AuthorityId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+5 -10
View File
@@ -45,7 +45,7 @@ pub mod pallet {
/// Find the author of a block.
type FindAuthor: FindAuthor<Self::AccountId>;
/// An event handler for authored blocks.
type EventHandler: EventHandler<Self::AccountId, Self::BlockNumber>;
type EventHandler: EventHandler<Self::AccountId, BlockNumberFor<Self>>;
}
#[pallet::pallet]
@@ -53,7 +53,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(_: T::BlockNumber) -> Weight {
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
if let Some(author) = Self::author() {
T::EventHandler::note_author(author);
}
@@ -61,7 +61,7 @@ pub mod pallet {
Weight::zero()
}
fn on_finalize(_: T::BlockNumber) {
fn on_finalize(_: BlockNumberFor<T>) {
// ensure we never go to trie with these values.
<Author<T>>::kill();
}
@@ -109,14 +109,10 @@ mod tests {
BuildStorage,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Authorship: pallet_authorship::{Pallet, Storage},
@@ -130,13 +126,12 @@ mod tests {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+5 -4
View File
@@ -34,6 +34,7 @@
//! definition.
use frame_support::traits::{Get, KeyOwnerProofSystem};
use frame_system::pallet_prelude::HeaderFor;
use log::{error, info};
use sp_consensus_babe::{AuthorityId, EquivocationProof, Slot, KEY_TYPE};
@@ -106,7 +107,7 @@ impl<Offender: Clone> Offence<Offender> for EquivocationOffence<Offender> {
pub struct EquivocationReportSystem<T, R, P, L>(sp_std::marker::PhantomData<(T, R, P, L)>);
impl<T, R, P, L>
OffenceReportSystem<Option<T::AccountId>, (EquivocationProof<T::Header>, T::KeyOwnerProof)>
OffenceReportSystem<Option<T::AccountId>, (EquivocationProof<HeaderFor<T>>, T::KeyOwnerProof)>
for EquivocationReportSystem<T, R, P, L>
where
T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
@@ -122,7 +123,7 @@ where
type Longevity = L;
fn publish_evidence(
evidence: (EquivocationProof<T::Header>, T::KeyOwnerProof),
evidence: (EquivocationProof<HeaderFor<T>>, T::KeyOwnerProof),
) -> Result<(), ()> {
use frame_system::offchain::SubmitTransaction;
let (equivocation_proof, key_owner_proof) = evidence;
@@ -140,7 +141,7 @@ where
}
fn check_evidence(
evidence: (EquivocationProof<T::Header>, T::KeyOwnerProof),
evidence: (EquivocationProof<HeaderFor<T>>, T::KeyOwnerProof),
) -> Result<(), TransactionValidityError> {
let (equivocation_proof, key_owner_proof) = evidence;
@@ -159,7 +160,7 @@ where
fn process_evidence(
reporter: Option<T::AccountId>,
evidence: (EquivocationProof<T::Header>, T::KeyOwnerProof),
evidence: (EquivocationProof<HeaderFor<T>>, T::KeyOwnerProof),
) -> Result<(), DispatchError> {
let (equivocation_proof, key_owner_proof) = evidence;
let reporter = reporter.or_else(|| <pallet_authorship::Pallet<T>>::author());
+27 -22
View File
@@ -29,6 +29,7 @@ use frame_support::{
weights::Weight,
BoundedVec, WeakBoundedVec,
};
use frame_system::pallet_prelude::{BlockNumberFor, HeaderFor};
use sp_consensus_babe::{
digests::{NextConfigDescriptor, NextEpochDescriptor, PreDigest},
AllowedSlots, BabeAuthorityWeight, BabeEpochConfiguration, ConsensusLog, Epoch,
@@ -78,7 +79,7 @@ pub trait WeightInfo {
pub trait EpochChangeTrigger {
/// Trigger an epoch change, if any should take place. This should be called
/// during every block, after initialization is done.
fn trigger<T: Config>(now: T::BlockNumber);
fn trigger<T: Config>(now: BlockNumberFor<T>);
}
/// A type signifying to BABE that an external trigger
@@ -86,7 +87,7 @@ pub trait EpochChangeTrigger {
pub struct ExternalTrigger;
impl EpochChangeTrigger for ExternalTrigger {
fn trigger<T: Config>(_: T::BlockNumber) {} // nothing - trigger is external.
fn trigger<T: Config>(_: BlockNumberFor<T>) {} // nothing - trigger is external.
}
/// A type signifying to BABE that it should perform epoch changes
@@ -94,7 +95,7 @@ impl EpochChangeTrigger for ExternalTrigger {
pub struct SameAuthoritiesForever;
impl EpochChangeTrigger for SameAuthoritiesForever {
fn trigger<T: Config>(now: T::BlockNumber) {
fn trigger<T: Config>(now: BlockNumberFor<T>) {
if <Pallet<T>>::should_epoch_change(now) {
let authorities = <Pallet<T>>::authorities();
let next_authorities = authorities.clone();
@@ -162,7 +163,7 @@ pub mod pallet {
/// (from an offchain context).
type EquivocationReportSystem: OffenceReportSystem<
Option<Self::AccountId>,
(EquivocationProof<Self::Header>, Self::KeyOwnerProof),
(EquivocationProof<HeaderFor<Self>>, Self::KeyOwnerProof),
>;
}
@@ -279,7 +280,7 @@ pub mod pallet {
/// slots, which may be skipped, the block numbers may not line up with the slot numbers.
#[pallet::storage]
pub(super) type EpochStart<T: Config> =
StorageValue<_, (T::BlockNumber, T::BlockNumber), ValueQuery>;
StorageValue<_, (BlockNumberFor<T>, BlockNumberFor<T>), ValueQuery>;
/// How late the current block is compared to its parent.
///
@@ -288,7 +289,7 @@ pub mod pallet {
/// execution context should always yield zero.
#[pallet::storage]
#[pallet::getter(fn lateness)]
pub(super) type Lateness<T: Config> = StorageValue<_, T::BlockNumber, ValueQuery>;
pub(super) type Lateness<T: Config> = StorageValue<_, BlockNumberFor<T>, ValueQuery>;
/// The configuration for the current epoch. Should never be `None` as it is initialized in
/// genesis.
@@ -409,7 +410,7 @@ pub mod pallet {
))]
pub fn report_equivocation(
origin: OriginFor<T>,
equivocation_proof: Box<EquivocationProof<T::Header>>,
equivocation_proof: Box<EquivocationProof<HeaderFor<T>>>,
key_owner_proof: T::KeyOwnerProof,
) -> DispatchResultWithPostInfo {
let reporter = ensure_signed(origin)?;
@@ -435,7 +436,7 @@ pub mod pallet {
))]
pub fn report_equivocation_unsigned(
origin: OriginFor<T>,
equivocation_proof: Box<EquivocationProof<T::Header>>,
equivocation_proof: Box<EquivocationProof<HeaderFor<T>>>,
key_owner_proof: T::KeyOwnerProof,
) -> DispatchResultWithPostInfo {
ensure_none(origin)?;
@@ -505,8 +506,8 @@ impl<T: Config> IsMember<AuthorityId> for Pallet<T> {
}
}
impl<T: Config> pallet_session::ShouldEndSession<T::BlockNumber> for Pallet<T> {
fn should_end_session(now: T::BlockNumber) -> bool {
impl<T: Config> pallet_session::ShouldEndSession<BlockNumberFor<T>> for Pallet<T> {
fn should_end_session(now: BlockNumberFor<T>) -> bool {
// it might be (and it is in current implementation) that session module is calling
// `should_end_session` from it's own `on_initialize` handler, in which case it's
// possible that babe's own `on_initialize` has not run yet, so let's ensure that we
@@ -526,7 +527,7 @@ impl<T: Config> Pallet<T> {
/// Determine whether an epoch change should take place at this block.
/// Assumes that initialization has already taken place.
pub fn should_epoch_change(now: T::BlockNumber) -> bool {
pub fn should_epoch_change(now: BlockNumberFor<T>) -> bool {
// The epoch has technically ended during the passage of time
// between this block and the last, but we have to "end" the epoch now,
// since there is no earlier possible block we could have done it.
@@ -556,11 +557,11 @@ impl<T: Config> Pallet<T> {
//
// WEIGHT NOTE: This function is tied to the weight of `EstimateNextSessionRotation`. If you
// update this function, you must also update the corresponding weight.
pub fn next_expected_epoch_change(now: T::BlockNumber) -> Option<T::BlockNumber> {
pub fn next_expected_epoch_change(now: BlockNumberFor<T>) -> Option<BlockNumberFor<T>> {
let next_slot = Self::current_epoch_start().saturating_add(T::EpochDuration::get());
next_slot.checked_sub(*CurrentSlot::<T>::get()).map(|slots_remaining| {
// This is a best effort guess. Drifts in the slot/block ratio will cause errors here.
let blocks_remaining: T::BlockNumber = slots_remaining.saturated_into();
let blocks_remaining: BlockNumberFor<T> = slots_remaining.saturated_into();
now.saturating_add(blocks_remaining)
})
}
@@ -778,7 +779,7 @@ impl<T: Config> Pallet<T> {
Self::deposit_consensus(ConsensusLog::NextEpochData(next));
}
fn initialize(now: T::BlockNumber) {
fn initialize(now: BlockNumberFor<T>) {
// since `initialize` can be called twice (e.g. if session module is present)
// let's ensure that we only do the initialization once per block
let initialized = Self::initialized().is_some();
@@ -813,7 +814,7 @@ impl<T: Config> Pallet<T> {
// how many slots were skipped between current and last block
let lateness = current_slot.saturating_sub(CurrentSlot::<T>::get() + 1);
let lateness = T::BlockNumber::from(*lateness as u32);
let lateness = BlockNumberFor::<T>::from(*lateness as u32);
Lateness::<T>::put(lateness);
CurrentSlot::<T>::put(current_slot);
@@ -879,7 +880,7 @@ impl<T: Config> Pallet<T> {
/// will push the transaction to the pool. Only useful in an offchain
/// context.
pub fn submit_unsigned_equivocation_report(
equivocation_proof: EquivocationProof<T::Header>,
equivocation_proof: EquivocationProof<HeaderFor<T>>,
key_owner_proof: T::KeyOwnerProof,
) -> Option<()> {
T::EquivocationReportSystem::publish_evidence((equivocation_proof, key_owner_proof)).ok()
@@ -901,12 +902,14 @@ impl<T: Config> OnTimestampSet<T::Moment> for Pallet<T> {
}
}
impl<T: Config> frame_support::traits::EstimateNextSessionRotation<T::BlockNumber> for Pallet<T> {
fn average_session_length() -> T::BlockNumber {
impl<T: Config> frame_support::traits::EstimateNextSessionRotation<BlockNumberFor<T>>
for Pallet<T>
{
fn average_session_length() -> BlockNumberFor<T> {
T::EpochDuration::get().saturated_into()
}
fn estimate_current_session_progress(_now: T::BlockNumber) -> (Option<Permill>, Weight) {
fn estimate_current_session_progress(_now: BlockNumberFor<T>) -> (Option<Permill>, Weight) {
let elapsed = CurrentSlot::<T>::get().saturating_sub(Self::current_epoch_start()) + 1;
(
@@ -916,7 +919,9 @@ impl<T: Config> frame_support::traits::EstimateNextSessionRotation<T::BlockNumbe
)
}
fn estimate_next_session_rotation(now: T::BlockNumber) -> (Option<T::BlockNumber>, Weight) {
fn estimate_next_session_rotation(
now: BlockNumberFor<T>,
) -> (Option<BlockNumberFor<T>>, Weight) {
(
Self::next_expected_epoch_change(now),
// Read: Current Slot, Epoch Index, Genesis Slot
@@ -925,8 +930,8 @@ impl<T: Config> frame_support::traits::EstimateNextSessionRotation<T::BlockNumbe
}
}
impl<T: Config> frame_support::traits::Lateness<T::BlockNumber> for Pallet<T> {
fn lateness(&self) -> T::BlockNumber {
impl<T: Config> frame_support::traits::Lateness<BlockNumberFor<T>> for Pallet<T> {
fn lateness(&self) -> BlockNumberFor<T> {
Self::lateness()
}
}
+2 -7
View File
@@ -42,14 +42,10 @@ use sp_staking::{EraIndex, SessionIndex};
type DummyValidatorId = u64;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
Authorship: pallet_authorship,
@@ -70,14 +66,13 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Version = ();
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = DummyValidatorId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type PalletInfo = PalletInfo;
+9 -8
View File
@@ -22,6 +22,7 @@ use super::{
AuthorVrfRandomness, Config, EpochStart, NextRandomness, Randomness, RANDOMNESS_LENGTH,
};
use frame_support::traits::Randomness as RandomnessT;
use frame_system::pallet_prelude::BlockNumberFor;
use sp_runtime::traits::{Hash, One, Saturating};
/// Randomness usable by consensus protocols that **depend** upon finality and take action
@@ -129,8 +130,8 @@ pub struct ParentBlockRandomness<T>(sp_std::marker::PhantomData<T>);
Please use `ParentBlockRandomness` instead.")]
pub struct CurrentBlockRandomness<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> RandomnessT<T::Hash, T::BlockNumber> for RandomnessFromTwoEpochsAgo<T> {
fn random(subject: &[u8]) -> (T::Hash, T::BlockNumber) {
impl<T: Config> RandomnessT<T::Hash, BlockNumberFor<T>> for RandomnessFromTwoEpochsAgo<T> {
fn random(subject: &[u8]) -> (T::Hash, BlockNumberFor<T>) {
let mut subject = subject.to_vec();
subject.reserve(RANDOMNESS_LENGTH);
subject.extend_from_slice(&Randomness::<T>::get()[..]);
@@ -139,8 +140,8 @@ impl<T: Config> RandomnessT<T::Hash, T::BlockNumber> for RandomnessFromTwoEpochs
}
}
impl<T: Config> RandomnessT<T::Hash, T::BlockNumber> for RandomnessFromOneEpochAgo<T> {
fn random(subject: &[u8]) -> (T::Hash, T::BlockNumber) {
impl<T: Config> RandomnessT<T::Hash, BlockNumberFor<T>> for RandomnessFromOneEpochAgo<T> {
fn random(subject: &[u8]) -> (T::Hash, BlockNumberFor<T>) {
let mut subject = subject.to_vec();
subject.reserve(RANDOMNESS_LENGTH);
subject.extend_from_slice(&NextRandomness::<T>::get()[..]);
@@ -149,8 +150,8 @@ impl<T: Config> RandomnessT<T::Hash, T::BlockNumber> for RandomnessFromOneEpochA
}
}
impl<T: Config> RandomnessT<Option<T::Hash>, T::BlockNumber> for ParentBlockRandomness<T> {
fn random(subject: &[u8]) -> (Option<T::Hash>, T::BlockNumber) {
impl<T: Config> RandomnessT<Option<T::Hash>, BlockNumberFor<T>> for ParentBlockRandomness<T> {
fn random(subject: &[u8]) -> (Option<T::Hash>, BlockNumberFor<T>) {
let random = AuthorVrfRandomness::<T>::get().map(|random| {
let mut subject = subject.to_vec();
subject.reserve(RANDOMNESS_LENGTH);
@@ -164,8 +165,8 @@ impl<T: Config> RandomnessT<Option<T::Hash>, T::BlockNumber> for ParentBlockRand
}
#[allow(deprecated)]
impl<T: Config> RandomnessT<Option<T::Hash>, T::BlockNumber> for CurrentBlockRandomness<T> {
fn random(subject: &[u8]) -> (Option<T::Hash>, T::BlockNumber) {
impl<T: Config> RandomnessT<Option<T::Hash>, BlockNumberFor<T>> for CurrentBlockRandomness<T> {
fn random(subject: &[u8]) -> (Option<T::Hash>, BlockNumberFor<T>) {
let (random, _) = ParentBlockRandomness::<T>::random(subject);
(random, <frame_system::Pallet<T>>::block_number())
}
+2 -7
View File
@@ -53,13 +53,12 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = sp_runtime::testing::Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type DbWeight = ();
@@ -87,13 +86,9 @@ impl bags_list::Config for Runtime {
type Score = VoteWeight;
}
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;
frame_support::construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub struct Runtime
{
System: frame_system::{Pallet, Call, Storage, Event<T>, Config<T>},
BagsList: bags_list::{Pallet, Call, Storage, Event<T>},
+1 -1
View File
@@ -94,7 +94,7 @@ The Staking module uses the `LockableCurrency` trait to lock a stash account's f
use frame_support::traits::{WithdrawReasons, LockableCurrency};
use sp_runtime::traits::Bounded;
pub trait Config: frame_system::Config {
type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
type Currency: LockableCurrency<Self::AccountId, Moment=frame_system::pallet_prelude::BlockNumberFor<Self>>;
}
fn update_ledger<T: Config>(
@@ -32,6 +32,7 @@ use frame_support::{
ReservableCurrency, SignedImbalance, TryDrop, WithdrawReasons,
},
};
use frame_system::pallet_prelude::BlockNumberFor;
pub use imbalances::{NegativeImbalance, PositiveImbalance};
// wrapping these imbalances in a private module is necessary to ensure absolute privacy
@@ -842,7 +843,7 @@ impl<T: Config<I>, I: 'static> LockableCurrency<T::AccountId> for Pallet<T, I>
where
T::Balance: MaybeSerializeDeserialize + Debug,
{
type Moment = T::BlockNumber;
type Moment = BlockNumberFor<T>;
type MaxLocks = T::MaxLocks;
+2 -2
View File
@@ -120,7 +120,7 @@
//! use frame_support::traits::{WithdrawReasons, LockableCurrency};
//! use sp_runtime::traits::Bounded;
//! pub trait Config: frame_system::Config {
//! type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
//! type Currency: LockableCurrency<Self::AccountId, Moment=frame_system::pallet_prelude::BlockNumberFor<Self>>;
//! }
//! # struct StakingLedger<T: Config> {
//! # stash: <T as frame_system::Config>::AccountId,
@@ -498,7 +498,7 @@ pub mod pallet {
}
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<T::BlockNumber> for Pallet<T, I> {
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
#[cfg(not(feature = "insecure_zero_ed"))]
fn integrity_test() {
assert!(
+2 -8
View File
@@ -38,7 +38,6 @@ use scale_info::TypeInfo;
use sp_core::{hexdisplay::HexDisplay, H256};
use sp_io;
use sp_runtime::{
testing::Header,
traits::{BadOrigin, IdentityLookup, SignedExtension, Zero},
ArithmeticError, BuildStorage, DispatchError, DispatchResult, FixedPointNumber, TokenError,
};
@@ -50,7 +49,6 @@ mod fungible_conformance_tests;
mod fungible_tests;
mod reentrancy_tests;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
#[derive(
@@ -73,10 +71,7 @@ pub enum TestId {
}
frame_support::construct_runtime!(
pub struct Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub struct Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -98,13 +93,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+2 -1
View File
@@ -43,6 +43,7 @@ use sp_consensus_beefy::{
};
use frame_support::{crypto::ecdsa::ECDSAExt, traits::Get};
use frame_system::pallet_prelude::BlockNumberFor;
pub use pallet::*;
@@ -139,7 +140,7 @@ pub mod pallet {
impl<T: Config> LeafDataProvider for Pallet<T> {
type LeafData = MmrLeaf<
<T as frame_system::Config>::BlockNumber,
BlockNumberFor<T>,
<T as frame_system::Config>::Hash,
MerkleRootOf<T>,
T::LeafExtra,
+3 -9
View File
@@ -29,7 +29,6 @@ use sp_core::H256;
use sp_runtime::{
app_crypto::ecdsa::Public,
impl_opaque_keys,
testing::Header,
traits::{BlakeTwo256, ConvertInto, IdentityLookup, Keccak256, OpaqueKeys},
BuildStorage,
};
@@ -46,14 +45,10 @@ impl_opaque_keys! {
}
}
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
@@ -70,13 +65,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -103,7 +97,7 @@ impl pallet_session::Config for Test {
}
pub type MmrLeaf = sp_consensus_beefy::mmr::MmrLeaf<
<Test as frame_system::Config>::BlockNumber,
frame_system::pallet_prelude::BlockNumberFor<Test>,
<Test as frame_system::Config>::Hash,
crate::MerkleRootOf<Test>,
Vec<u8>,
+3 -2
View File
@@ -39,6 +39,7 @@ use frame_support::{
log,
traits::{Get, KeyOwnerProofSystem},
};
use frame_system::pallet_prelude::BlockNumberFor;
use log::{error, info};
use sp_consensus_beefy::{EquivocationProof, ValidatorSetId, KEY_TYPE};
use sp_runtime::{
@@ -126,7 +127,7 @@ pub struct EquivocationReportSystem<T, R, P, L>(sp_std::marker::PhantomData<(T,
/// Equivocation evidence convenience alias.
pub type EquivocationEvidenceFor<T> = (
EquivocationProof<
<T as frame_system::Config>::BlockNumber,
BlockNumberFor<T>,
<T as Config>::BeefyId,
<<T as Config>::BeefyId as RuntimeAppPublic>::Signature,
>,
@@ -140,7 +141,7 @@ where
R: ReportOffence<
T::AccountId,
P::IdentificationTuple,
EquivocationOffence<P::IdentificationTuple, T::BlockNumber>,
EquivocationOffence<P::IdentificationTuple, BlockNumberFor<T>>,
>,
P: KeyOwnerProofSystem<(KeyTypeId, T::BeefyId), Proof = T::KeyOwnerProof>,
P::IdentificationTuple: Clone,
+3 -8
View File
@@ -30,7 +30,7 @@ use sp_runtime::{
app_crypto::ecdsa::Public,
curve::PiecewiseLinear,
impl_opaque_keys,
testing::{Header, TestXt},
testing::TestXt,
traits::{BlakeTwo256, IdentityLookup, OpaqueKeys},
BuildStorage, Perbill,
};
@@ -49,14 +49,10 @@ impl_opaque_keys! {
}
}
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
Authorship: pallet_authorship,
@@ -77,13 +73,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -343,16 +343,11 @@ mod mock {
type AccountId = u64;
type AccountIndex = u32;
type BlockNumber = u64;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Baseline: crate::{Pallet, Call, Storage, Event<T>},
@@ -366,13 +361,12 @@ mod mock {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = AccountIndex;
type BlockNumber = BlockNumber;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = sp_runtime::testing::Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type Version = ();
@@ -164,14 +164,10 @@ fn noop_is_free() {
mod mock {
use sp_runtime::testing::H256;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Baseline: crate::{Pallet, Call, Storage, Event<T>},
@@ -185,13 +181,12 @@ mod mock {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u32;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = u32;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = sp_runtime::testing::Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type Version = ();
+2 -8
View File
@@ -115,16 +115,11 @@ pub mod mock {
type AccountId = u64;
type AccountIndex = u32;
type BlockNumber = u64;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
}
@@ -137,13 +132,12 @@ pub mod mock {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = AccountIndex;
type BlockNumber = BlockNumber;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = sp_runtime::testing::Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type Version = ();
+3 -8
View File
@@ -22,7 +22,7 @@
use super::*;
use frame_support::{parameter_types, traits::ConstU32};
use sp_runtime::{
testing::{Header, H256},
testing::H256,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
@@ -66,14 +66,10 @@ mod pallet_test {
}
}
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
TestPallet: pallet_test::{Pallet, Call, Storage},
@@ -87,13 +83,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type Version = ();
@@ -22,7 +22,7 @@
use super::*;
use frame_support::traits::ConstU32;
use sp_runtime::{
testing::{Header, H256},
testing::H256,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
@@ -76,14 +76,10 @@ mod pallet_test {
}
}
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
TestPallet: pallet_test::{Pallet, Call, Storage, Event<T>},
@@ -97,12 +93,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type DbWeight = ();
+9 -9
View File
@@ -24,7 +24,7 @@ use super::*;
use frame_benchmarking::v1::{
account, benchmarks_instance_pallet, whitelisted_caller, BenchmarkError,
};
use frame_system::RawOrigin;
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use sp_runtime::traits::Bounded;
use crate::Pallet as Bounties;
@@ -77,7 +77,7 @@ fn create_bounty<T: Config<I>, I: 'static>(
let approve_origin =
T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
Bounties::<T, I>::approve_bounty(approve_origin.clone(), bounty_id)?;
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
Treasury::<T, I>::on_initialize(BlockNumberFor::<T>::zero());
Bounties::<T, I>::propose_curator(approve_origin, bounty_id, curator_lookup.clone(), fee)?;
Bounties::<T, I>::accept_curator(RawOrigin::Signed(curator).into(), bounty_id)?;
Ok((curator_lookup, bounty_id))
@@ -115,14 +115,14 @@ benchmarks_instance_pallet! {
let bounty_id = BountyCount::<T, I>::get() - 1;
let approve_origin = T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
Bounties::<T, I>::approve_bounty(approve_origin.clone(), bounty_id)?;
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
Treasury::<T, I>::on_initialize(BlockNumberFor::<T>::zero());
}: _<T::RuntimeOrigin>(approve_origin, bounty_id, curator_lookup, fee)
// Worst case when curator is inactive and any sender unassigns the curator.
unassign_curator {
setup_pot_account::<T, I>();
let (curator_lookup, bounty_id) = create_bounty::<T, I>()?;
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
Treasury::<T, I>::on_initialize(BlockNumberFor::<T>::zero());
let bounty_id = BountyCount::<T, I>::get() - 1;
frame_system::Pallet::<T>::set_block_number(T::BountyUpdatePeriod::get() + 2u32.into());
let caller = whitelisted_caller();
@@ -136,14 +136,14 @@ benchmarks_instance_pallet! {
let bounty_id = BountyCount::<T, I>::get() - 1;
let approve_origin = T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
Bounties::<T, I>::approve_bounty(approve_origin.clone(), bounty_id)?;
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
Treasury::<T, I>::on_initialize(BlockNumberFor::<T>::zero());
Bounties::<T, I>::propose_curator(approve_origin, bounty_id, curator_lookup, fee)?;
}: _(RawOrigin::Signed(curator), bounty_id)
award_bounty {
setup_pot_account::<T, I>();
let (curator_lookup, bounty_id) = create_bounty::<T, I>()?;
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
Treasury::<T, I>::on_initialize(BlockNumberFor::<T>::zero());
let bounty_id = BountyCount::<T, I>::get() - 1;
let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?;
@@ -154,7 +154,7 @@ benchmarks_instance_pallet! {
claim_bounty {
setup_pot_account::<T, I>();
let (curator_lookup, bounty_id) = create_bounty::<T, I>()?;
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
Treasury::<T, I>::on_initialize(BlockNumberFor::<T>::zero());
let bounty_id = BountyCount::<T, I>::get() - 1;
let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?;
@@ -183,7 +183,7 @@ benchmarks_instance_pallet! {
close_bounty_active {
setup_pot_account::<T, I>();
let (curator_lookup, bounty_id) = create_bounty::<T, I>()?;
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
Treasury::<T, I>::on_initialize(BlockNumberFor::<T>::zero());
let bounty_id = BountyCount::<T, I>::get() - 1;
let approve_origin =
T::ApproveOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
@@ -195,7 +195,7 @@ benchmarks_instance_pallet! {
extend_bounty_expiry {
setup_pot_account::<T, I>();
let (curator_lookup, bounty_id) = create_bounty::<T, I>()?;
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
Treasury::<T, I>::on_initialize(BlockNumberFor::<T>::zero());
let bounty_id = BountyCount::<T, I>::get() - 1;
let curator = T::Lookup::lookup(curator_lookup).map_err(<&str>::from)?;
+3 -3
View File
@@ -201,11 +201,11 @@ pub mod pallet {
/// The delay period for which a bounty beneficiary need to wait before claim the payout.
#[pallet::constant]
type BountyDepositPayoutDelay: Get<Self::BlockNumber>;
type BountyDepositPayoutDelay: Get<BlockNumberFor<Self>>;
/// Bounty duration in blocks.
#[pallet::constant]
type BountyUpdatePeriod: Get<Self::BlockNumber>;
type BountyUpdatePeriod: Get<BlockNumberFor<Self>>;
/// The curator deposit is calculated as a percentage of the curator fee.
///
@@ -305,7 +305,7 @@ pub mod pallet {
_,
Twox64Concat,
BountyIndex,
Bounty<T::AccountId, BalanceOf<T, I>, T::BlockNumber>,
Bounty<T::AccountId, BalanceOf<T, I>, BlockNumberFor<T>>,
>;
/// The description of each bounty.
+2 -8
View File
@@ -30,21 +30,16 @@ use frame_support::{
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
BuildStorage, Perbill, Storage,
};
use super::Event as BountiesEvent;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -68,13 +63,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u128; // u64 is not enough to hold bytes used to generate bounty account
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -22,7 +22,7 @@
use super::*;
use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller, BenchmarkError};
use frame_system::RawOrigin;
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use crate::Pallet as ChildBounties;
use pallet_bounties::Pallet as Bounties;
@@ -114,7 +114,7 @@ fn activate_bounty<T: Config>(
let approve_origin =
T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
Bounties::<T>::approve_bounty(approve_origin, child_bounty_setup.bounty_id)?;
Treasury::<T>::on_initialize(T::BlockNumber::zero());
Treasury::<T>::on_initialize(BlockNumberFor::<T>::zero());
Bounties::<T>::propose_curator(
RawOrigin::Root.into(),
child_bounty_setup.bounty_id,
@@ -229,7 +229,7 @@ benchmarks! {
unassign_curator {
setup_pot_account::<T>();
let bounty_setup = activate_child_bounty::<T>(0, T::MaximumReasonLength::get())?;
Treasury::<T>::on_initialize(T::BlockNumber::zero());
Treasury::<T>::on_initialize(BlockNumberFor::<T>::zero());
frame_system::Pallet::<T>::set_block_number(T::BountyUpdatePeriod::get() + 1u32.into());
let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller), bounty_setup.bounty_id,
@@ -303,7 +303,7 @@ benchmarks! {
close_child_bounty_active {
setup_pot_account::<T>();
let bounty_setup = activate_child_bounty::<T>(0, T::MaximumReasonLength::get())?;
Treasury::<T>::on_initialize(T::BlockNumber::zero());
Treasury::<T>::on_initialize(BlockNumberFor::<T>::zero());
}: close_child_bounty(RawOrigin::Root, bounty_setup.bounty_id, bounty_setup.child_bounty_id)
verify {
assert_last_event::<T>(Event::Canceled {
+2 -2
View File
@@ -200,7 +200,7 @@ pub mod pallet {
BountyIndex,
Twox64Concat,
BountyIndex,
ChildBounty<T::AccountId, BalanceOf<T>, T::BlockNumber>,
ChildBounty<T::AccountId, BalanceOf<T>, BlockNumberFor<T>>,
>;
/// The description of each child-bounty.
@@ -816,7 +816,7 @@ impl<T: Config> Pallet<T> {
fn ensure_bounty_active(
bounty_id: BountyIndex,
) -> Result<(T::AccountId, T::BlockNumber), DispatchError> {
) -> Result<(T::AccountId, BlockNumberFor<T>), DispatchError> {
let parent_bounty = pallet_bounties::Pallet::<T>::bounties(bounty_id)
.ok_or(BountiesError::<T>::InvalidIndex)?;
if let BountyStatus::Active { curator, update_due } = parent_bounty.get_status() {
+2 -8
View File
@@ -31,22 +31,17 @@ use frame_support::{
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
BuildStorage, Perbill, Permill, TokenError,
};
use super::Event as ChildBountiesEvent;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type BountiesError = pallet_bounties::Error<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -71,13 +66,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u128;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -24,7 +24,9 @@ use sp_runtime::traits::Bounded;
use sp_std::mem::size_of;
use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelisted_caller};
use frame_system::{Call as SystemCall, Pallet as System, RawOrigin as SystemOrigin};
use frame_system::{
pallet_prelude::BlockNumberFor, Call as SystemCall, Pallet as System, RawOrigin as SystemOrigin,
};
const SEED: u32 = 0;
@@ -516,7 +518,7 @@ benchmarks_instance_pallet! {
false,
)?;
System::<T>::set_block_number(T::BlockNumber::max_value());
System::<T>::set_block_number(BlockNumberFor::<T>::max_value());
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
// Prime nay will close it as disapproved
@@ -588,7 +590,7 @@ benchmarks_instance_pallet! {
}
// caller is prime, prime already votes aye by creating the proposal
System::<T>::set_block_number(T::BlockNumber::max_value());
System::<T>::set_block_number(BlockNumberFor::<T>::max_value());
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
// Prime aye will close it as approved
@@ -637,7 +639,7 @@ benchmarks_instance_pallet! {
last_hash = T::Hashing::hash_of(&proposal);
}
System::<T>::set_block_number(T::BlockNumber::max_value());
System::<T>::set_block_number(BlockNumberFor::<T>::max_value());
assert_eq!(Collective::<T, I>::proposals().len(), p as usize);
}: _(SystemOrigin::Root, last_hash)
+2 -2
View File
@@ -201,7 +201,7 @@ pub mod pallet {
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The time-out for council motions.
type MotionDuration: Get<Self::BlockNumber>;
type MotionDuration: Get<BlockNumberFor<Self>>;
/// Maximum number of proposals allowed to be active in parallel.
type MaxProposals: Get<ProposalIndex>;
@@ -274,7 +274,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn voting)]
pub type Voting<T: Config<I>, I: 'static = ()> =
StorageMap<_, Identity, T::Hash, Votes<T::AccountId, T::BlockNumber>, OptionQuery>;
StorageMap<_, Identity, T::Hash, Votes<T::AccountId, BlockNumberFor<T>>, OptionQuery>;
/// Proposals so far.
#[pallet::storage]
+2 -6
View File
@@ -36,10 +36,7 @@ pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, u64, RuntimeCall, ()>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
pub enum Test
{
System: frame_system::{Pallet, Call, Event<T>},
Collective: pallet_collective::<Instance1>::{Pallet, Call, Event<T>, Origin<T>, Config<T>},
@@ -100,13 +97,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+6 -7
View File
@@ -34,7 +34,7 @@ use frame_support::{
weights::Weight,
Blake2_128Concat, BoundedVec, StorageHasher,
};
use frame_system::RawOrigin;
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use pallet_contracts_primitives::ExecReturnValue;
use smallvec::{Array, SmallVec};
use sp_core::{
@@ -48,7 +48,6 @@ use sp_std::{marker::PhantomData, mem, prelude::*, vec::Vec};
pub type AccountIdOf<T> = <T as frame_system::Config>::AccountId;
pub type MomentOf<T> = <<T as Config>::Time as Time>::Moment;
pub type SeedOf<T> = <T as frame_system::Config>::Hash;
pub type BlockNumberOf<T> = <T as frame_system::Config>::BlockNumber;
pub type ExecResult = Result<ExecReturnValue, ExecError>;
/// A type that represents a topic of an event. At the moment a hash is used.
@@ -244,7 +243,7 @@ pub trait Ext: sealing::Sealed {
fn minimum_balance(&self) -> BalanceOf<Self::T>;
/// Returns a random number for the current block with the given subject.
fn random(&self, subject: &[u8]) -> (SeedOf<Self::T>, BlockNumberOf<Self::T>);
fn random(&self, subject: &[u8]) -> (SeedOf<Self::T>, BlockNumberFor<Self::T>);
/// Deposit an event with the given topics.
///
@@ -252,7 +251,7 @@ pub trait Ext: sealing::Sealed {
fn deposit_event(&mut self, topics: Vec<TopicOf<Self::T>>, data: Vec<u8>);
/// Returns the current block number.
fn block_number(&self) -> BlockNumberOf<Self::T>;
fn block_number(&self) -> BlockNumberFor<Self::T>;
/// Returns the maximum allowed size of a storage item.
fn max_value_size(&self) -> u32;
@@ -400,7 +399,7 @@ pub struct Stack<'a, T: Config, E> {
/// The timestamp at the point of call stack instantiation.
timestamp: MomentOf<T>,
/// The block number at the time of call stack instantiation.
block_number: T::BlockNumber,
block_number: BlockNumberFor<T>,
/// The nonce is cached here when accessed. It is written back when the call stack
/// finishes executing. Please refer to [`Nonce`] to a description of
/// the nonce itself.
@@ -1341,7 +1340,7 @@ where
self.top_frame().value_transferred
}
fn random(&self, subject: &[u8]) -> (SeedOf<T>, BlockNumberOf<T>) {
fn random(&self, subject: &[u8]) -> (SeedOf<T>, BlockNumberFor<T>) {
T::Randomness::random(subject)
}
@@ -1360,7 +1359,7 @@ where
);
}
fn block_number(&self) -> T::BlockNumber {
fn block_number(&self) -> BlockNumberFor<T> {
self.block_number
}
+2 -2
View File
@@ -209,7 +209,7 @@ pub mod pallet {
/// be instantiated from existing codes that use this deprecated functionality. It will
/// be removed eventually. Hence for new `pallet-contracts` deployments it is okay
/// to supply a dummy implementation for this type (because it is never used).
type Randomness: Randomness<Self::Hash, Self::BlockNumber>;
type Randomness: Randomness<Self::Hash, BlockNumberFor<Self>>;
/// The currency in which fees are paid and contract balances are held.
type Currency: ReservableCurrency<Self::AccountId> // TODO: Move to fungible traits
@@ -341,7 +341,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_idle(_block: T::BlockNumber, mut remaining_weight: Weight) -> Weight {
fn on_idle(_block: BlockNumberFor<T>, mut remaining_weight: Weight) -> Weight {
use migration::MigrateResult::*;
loop {
+3 -8
View File
@@ -50,20 +50,16 @@ use sp_core::ByteArray;
use sp_io::hashing::blake2_256;
use sp_keystore::{testing::MemoryKeystore, KeystoreExt};
use sp_runtime::{
testing::{Header, H256},
testing::H256,
traits::{BlakeTwo256, Convert, Hash, IdentityLookup},
AccountId32, BuildStorage, TokenError,
};
use std::ops::Deref;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -314,13 +310,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = AccountId32;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+3 -2
View File
@@ -417,7 +417,7 @@ impl<T: Config> Executable<T> for WasmBlob<T> {
mod tests {
use super::*;
use crate::{
exec::{AccountIdOf, BlockNumberOf, ErrorOrigin, ExecError, Executable, Ext, Key, SeedOf},
exec::{AccountIdOf, ErrorOrigin, ExecError, Executable, Ext, Key, SeedOf},
gas::GasMeter,
storage::WriteOutcome,
tests::{RuntimeCall, Test, ALICE, BOB},
@@ -427,6 +427,7 @@ mod tests {
use frame_support::{
assert_err, assert_ok, dispatch::DispatchResultWithPostInfo, weights::Weight,
};
use frame_system::pallet_prelude::BlockNumberFor;
use pallet_contracts_primitives::{ExecReturnValue, ReturnFlags};
use pretty_assertions::assert_eq;
use sp_core::H256;
@@ -632,7 +633,7 @@ mod tests {
fn minimum_balance(&self) -> u64 {
666
}
fn random(&self, subject: &[u8]) -> (SeedOf<Self::T>, BlockNumberOf<Self::T>) {
fn random(&self, subject: &[u8]) -> (SeedOf<Self::T>, BlockNumberFor<Self::T>) {
(H256::from_slice(subject), 42)
}
fn deposit_event(&mut self, topics: Vec<H256>, data: Vec<u8>) {
@@ -2091,7 +2091,7 @@ pub mod env {
/// `out_ptr`. This call overwrites it with the size of the value. If the available
/// space at `out_ptr` is less than the size of the value a trap is triggered.
///
/// The data is encoded as (T::Hash, T::BlockNumber).
/// The data is encoded as (T::Hash, frame_system::pallet_prelude::BlockNumberFor::<T>).
///
/// # Changes from v0
///
+7 -9
View File
@@ -35,6 +35,7 @@ use frame_support::{
ReservableCurrency, WithdrawReasons,
},
};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_runtime::{
traits::{AtLeast32BitUnsigned, Saturating, StaticLookup, Zero},
ArithmeticError, Perbill,
@@ -68,16 +69,13 @@ type BalanceOf<T, I = ()> =
type VotingOf<T, I = ()> = Voting<
BalanceOf<T, I>,
<T as frame_system::Config>::AccountId,
<T as frame_system::Config>::BlockNumber,
BlockNumberFor<T>,
PollIndexOf<T, I>,
<T as Config<I>>::MaxVotes,
>;
#[allow(dead_code)]
type DelegatingOf<T, I = ()> = Delegating<
BalanceOf<T, I>,
<T as frame_system::Config>::AccountId,
<T as frame_system::Config>::BlockNumber,
>;
type DelegatingOf<T, I = ()> =
Delegating<BalanceOf<T, I>, <T as frame_system::Config>::AccountId, BlockNumberFor<T>>;
pub type TallyOf<T, I = ()> = Tally<BalanceOf<T, I>, <T as Config<I>>::MaxTurnout>;
pub type VotesOf<T, I = ()> = BalanceOf<T, I>;
type PollIndexOf<T, I = ()> = <<T as Config<I>>::Polls as Polling<TallyOf<T, I>>>::Index;
@@ -103,14 +101,14 @@ pub mod pallet {
type WeightInfo: WeightInfo;
/// Currency type with which voting happens.
type Currency: ReservableCurrency<Self::AccountId>
+ LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>
+ LockableCurrency<Self::AccountId, Moment = BlockNumberFor<Self>>
+ fungible::Inspect<Self::AccountId>;
/// The implementation of the logic which conducts polls.
type Polls: Polling<
TallyOf<Self, I>,
Votes = BalanceOf<Self, I>,
Moment = Self::BlockNumber,
Moment = BlockNumberFor<Self>,
>;
/// The maximum amount of tokens which may be used for voting. May just be
@@ -130,7 +128,7 @@ pub mod pallet {
/// It should be no shorter than enactment period to ensure that in the case of an approval,
/// those successful voters are locked into the consequences that their votes entail.
#[pallet::constant]
type VoteLockingPeriod: Get<Self::BlockNumber>;
type VoteLockingPeriod: Get<BlockNumberFor<Self>>;
}
/// All voting for a particular voter in a particular voting class. We store the balance for the
@@ -25,7 +25,6 @@ use frame_support::{
};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
@@ -33,14 +32,10 @@ use sp_runtime::{
use super::*;
use crate as pallet_conviction_voting;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -63,13 +58,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -23,7 +23,7 @@ use super::*;
use crate::Pallet as CoreFellowship;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use sp_arithmetic::traits::Bounded;
const SEED: u32 = 0;
@@ -75,7 +75,7 @@ mod benchmarks {
let member = make_member::<T, I>(0)?;
// Set it to the max value to ensure that any possible auto-demotion period has passed.
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
frame_system::Pallet::<T>::set_block_number(BlockNumberFor::<T>::max_value());
ensure_evidence::<T, I>(&member)?;
assert!(Member::<T, I>::contains_key(&member));
@@ -92,7 +92,7 @@ mod benchmarks {
let member = make_member::<T, I>(2)?;
// Set it to the max value to ensure that any possible auto-demotion period has passed.
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
frame_system::Pallet::<T>::set_block_number(BlockNumberFor::<T>::max_value());
ensure_evidence::<T, I>(&member)?;
assert!(Member::<T, I>::contains_key(&member));
assert_eq!(T::Members::rank_of(&member), Some(2));
+2 -3
View File
@@ -193,9 +193,8 @@ pub mod pallet {
type EvidenceSize: Get<u32>;
}
pub type ParamsOf<T, I> =
ParamsType<<T as Config<I>>::Balance, <T as frame_system::Config>::BlockNumber, RANK_COUNT>;
pub type MemberStatusOf<T> = MemberStatus<<T as frame_system::Config>::BlockNumber>;
pub type ParamsOf<T, I> = ParamsType<<T as Config<I>>::Balance, BlockNumberFor<T>, RANK_COUNT>;
pub type MemberStatusOf<T> = MemberStatus<BlockNumberFor<T>>;
pub type RankOf<T, I> = <<T as Config<I>>::Members as RankedMembers>::Rank;
/// The overall status of the system.
+2 -8
View File
@@ -28,7 +28,6 @@ use frame_support::{
use frame_system::EnsureSignedBy;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup, TryMorphInto},
BuildStorage, DispatchError, DispatchResult,
};
@@ -37,14 +36,10 @@ use sp_std::cell::RefCell;
use super::*;
use crate as pallet_core_fellowship;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
CoreFellowship: pallet_core_fellowship::{Pallet, Call, Storage, Event<T>},
@@ -62,13 +57,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -24,7 +24,7 @@ use frame_support::{
assert_noop, assert_ok,
traits::{Currency, EnsureOrigin, Get, OnInitialize, UnfilteredDispatchable},
};
use frame_system::RawOrigin;
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use sp_core::H256;
use sp_runtime::{traits::Bounded, BoundedVec};
@@ -258,7 +258,7 @@ benchmarks! {
.collect::<Vec<_>>()
.try_into()
.unwrap();
Blacklist::<T>::insert(proposal.hash(), (T::BlockNumber::zero(), addresses));
Blacklist::<T>::insert(proposal.hash(), (BlockNumberFor::<T>::zero(), addresses));
}: _<T::RuntimeOrigin>(origin, proposal)
verify {
// External proposal created
@@ -332,7 +332,7 @@ benchmarks! {
vetoers.try_push(account::<T::AccountId>("vetoer", i, SEED)).unwrap();
}
vetoers.sort();
Blacklist::<T>::insert(proposal_hash, (T::BlockNumber::zero(), vetoers));
Blacklist::<T>::insert(proposal_hash, (BlockNumberFor::<T>::zero(), vetoers));
let origin = T::VetoOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
ensure!(NextExternal::<T>::get().is_some(), "no external proposal");
@@ -816,7 +816,7 @@ benchmarks! {
// create not ongoing referendum.
ReferendumInfoOf::<T>::insert(
0,
ReferendumInfo::Finished { end: T::BlockNumber::zero(), approved: true },
ReferendumInfo::Finished { end: BlockNumberFor::<T>::zero(), approved: true },
);
let owner = MetadataOwner::Referendum(0);
let caller = funded_account::<T>("caller", 0);
@@ -833,7 +833,7 @@ benchmarks! {
// create not ongoing referendum.
ReferendumInfoOf::<T>::insert(
0,
ReferendumInfo::Finished { end: T::BlockNumber::zero(), approved: true },
ReferendumInfo::Finished { end: BlockNumberFor::<T>::zero(), approved: true },
);
let owner = MetadataOwner::Referendum(0);
let hash = note_preimage::<T>();
+39 -34
View File
@@ -165,7 +165,7 @@ use frame_support::{
},
weights::Weight,
};
use frame_system::pallet_prelude::OriginFor;
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
use sp_runtime::{
traits::{Bounded as ArithBounded, One, Saturating, StaticLookup, Zero},
ArithmeticError, DispatchError, DispatchResult,
@@ -226,14 +226,14 @@ pub mod pallet {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// The Scheduler.
type Scheduler: ScheduleNamed<Self::BlockNumber, CallOf<Self>, Self::PalletsOrigin>;
type Scheduler: ScheduleNamed<BlockNumberFor<Self>, CallOf<Self>, Self::PalletsOrigin>;
/// The Preimage provider.
type Preimages: QueryPreimage + StorePreimage;
/// Currency type for this pallet.
type Currency: ReservableCurrency<Self::AccountId>
+ LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>;
+ LockableCurrency<Self::AccountId, Moment = BlockNumberFor<Self>>;
/// The period between a proposal being approved and enacted.
///
@@ -241,22 +241,22 @@ pub mod pallet {
/// voting stakers have an opportunity to remove themselves from the system in the case
/// where they are on the losing side of a vote.
#[pallet::constant]
type EnactmentPeriod: Get<Self::BlockNumber>;
type EnactmentPeriod: Get<BlockNumberFor<Self>>;
/// How often (in blocks) new public referenda are launched.
#[pallet::constant]
type LaunchPeriod: Get<Self::BlockNumber>;
type LaunchPeriod: Get<BlockNumberFor<Self>>;
/// How often (in blocks) to check for new votes.
#[pallet::constant]
type VotingPeriod: Get<Self::BlockNumber>;
type VotingPeriod: Get<BlockNumberFor<Self>>;
/// The minimum period of vote locking.
///
/// It should be no shorter than enactment period to ensure that in the case of an approval,
/// those successful voters are locked into the consequences that their votes entail.
#[pallet::constant]
type VoteLockingPeriod: Get<Self::BlockNumber>;
type VoteLockingPeriod: Get<BlockNumberFor<Self>>;
/// The minimum amount to be used as a deposit for a public referendum proposal.
#[pallet::constant]
@@ -270,11 +270,11 @@ pub mod pallet {
/// Minimum voting period allowed for a fast-track referendum.
#[pallet::constant]
type FastTrackVotingPeriod: Get<Self::BlockNumber>;
type FastTrackVotingPeriod: Get<BlockNumberFor<Self>>;
/// Period in blocks where an external proposal may not be re-submitted after being vetoed.
#[pallet::constant]
type CooloffPeriod: Get<Self::BlockNumber>;
type CooloffPeriod: Get<BlockNumberFor<Self>>;
/// The maximum number of votes for an account.
///
@@ -387,7 +387,7 @@ pub mod pallet {
_,
Twox64Concat,
ReferendumIndex,
ReferendumInfo<T::BlockNumber, BoundedCallOf<T>, BalanceOf<T>>,
ReferendumInfo<BlockNumberFor<T>, BoundedCallOf<T>, BalanceOf<T>>,
>;
/// All votes for a particular voter. We store the balance for the number of votes that we
@@ -399,7 +399,7 @@ pub mod pallet {
_,
Twox64Concat,
T::AccountId,
Voting<BalanceOf<T>, T::AccountId, T::BlockNumber, T::MaxVotes>,
Voting<BalanceOf<T>, T::AccountId, BlockNumberFor<T>, T::MaxVotes>,
ValueQuery,
>;
@@ -422,7 +422,7 @@ pub mod pallet {
_,
Identity,
H256,
(T::BlockNumber, BoundedVec<T::AccountId, T::MaxBlacklisted>),
(BlockNumberFor<T>, BoundedVec<T::AccountId, T::MaxBlacklisted>),
>;
/// Record of all proposals that have been subject to emergency cancellation.
@@ -476,7 +476,7 @@ pub mod pallet {
/// An account has cancelled a previous delegation operation.
Undelegated { account: T::AccountId },
/// An external proposal has been vetoed.
Vetoed { who: T::AccountId, proposal_hash: H256, until: T::BlockNumber },
Vetoed { who: T::AccountId, proposal_hash: H256, until: BlockNumberFor<T> },
/// A proposal_hash has been blacklisted permanently.
Blacklisted { proposal_hash: H256 },
/// An account has voted in a referendum
@@ -566,7 +566,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
/// Weight: see `begin_block`
fn on_initialize(n: T::BlockNumber) -> Weight {
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
Self::begin_block(n)
}
}
@@ -776,8 +776,8 @@ pub mod pallet {
pub fn fast_track(
origin: OriginFor<T>,
proposal_hash: H256,
voting_period: T::BlockNumber,
delay: T::BlockNumber,
voting_period: BlockNumberFor<T>,
delay: BlockNumberFor<T>,
) -> DispatchResult {
// Rather complicated bit of code to ensure that either:
// - `voting_period` is at least `FastTrackVotingPeriod` and `origin` is
@@ -795,7 +795,7 @@ pub mod pallet {
ensure!(T::InstantAllowed::get(), Error::<T>::InstantNotAllowed);
}
ensure!(voting_period > T::BlockNumber::zero(), Error::<T>::VotingPeriodLow);
ensure!(voting_period > Zero::zero(), Error::<T>::VotingPeriodLow);
let (ext_proposal, threshold) =
<NextExternal<T>>::get().ok_or(Error::<T>::ProposalMissing)?;
ensure!(
@@ -1048,7 +1048,8 @@ pub mod pallet {
T::BlacklistOrigin::ensure_origin(origin)?;
// Insert the proposal into the blacklist.
let permanent = (T::BlockNumber::max_value(), BoundedVec::<T::AccountId, _>::default());
let permanent =
(BlockNumberFor::<T>::max_value(), BoundedVec::<T::AccountId, _>::default());
Blacklist::<T>::insert(&proposal_hash, permanent);
// Remove the queued proposal, if it's there.
@@ -1201,17 +1202,19 @@ impl<T: Config> Pallet<T> {
/// Get all referenda ready for tally at block `n`.
pub fn maturing_referenda_at(
n: T::BlockNumber,
) -> Vec<(ReferendumIndex, ReferendumStatus<T::BlockNumber, BoundedCallOf<T>, BalanceOf<T>>)> {
n: BlockNumberFor<T>,
) -> Vec<(ReferendumIndex, ReferendumStatus<BlockNumberFor<T>, BoundedCallOf<T>, BalanceOf<T>>)>
{
let next = Self::lowest_unbaked();
let last = Self::referendum_count();
Self::maturing_referenda_at_inner(n, next..last)
}
fn maturing_referenda_at_inner(
n: T::BlockNumber,
n: BlockNumberFor<T>,
range: core::ops::Range<PropIndex>,
) -> Vec<(ReferendumIndex, ReferendumStatus<T::BlockNumber, BoundedCallOf<T>, BalanceOf<T>>)> {
) -> Vec<(ReferendumIndex, ReferendumStatus<BlockNumberFor<T>, BoundedCallOf<T>, BalanceOf<T>>)>
{
range
.into_iter()
.map(|i| (i, Self::referendum_info(i)))
@@ -1229,7 +1232,7 @@ impl<T: Config> Pallet<T> {
pub fn internal_start_referendum(
proposal: BoundedCallOf<T>,
threshold: VoteThreshold,
delay: T::BlockNumber,
delay: BlockNumberFor<T>,
) -> ReferendumIndex {
<Pallet<T>>::inject_referendum(
<frame_system::Pallet<T>>::block_number().saturating_add(T::VotingPeriod::get()),
@@ -1250,8 +1253,9 @@ impl<T: Config> Pallet<T> {
/// Ok if the given referendum is active, Err otherwise
fn ensure_ongoing(
r: ReferendumInfo<T::BlockNumber, BoundedCallOf<T>, BalanceOf<T>>,
) -> Result<ReferendumStatus<T::BlockNumber, BoundedCallOf<T>, BalanceOf<T>>, DispatchError> {
r: ReferendumInfo<BlockNumberFor<T>, BoundedCallOf<T>, BalanceOf<T>>,
) -> Result<ReferendumStatus<BlockNumberFor<T>, BoundedCallOf<T>, BalanceOf<T>>, DispatchError>
{
match r {
ReferendumInfo::Ongoing(s) => Ok(s),
_ => Err(Error::<T>::ReferendumInvalid.into()),
@@ -1260,7 +1264,8 @@ impl<T: Config> Pallet<T> {
fn referendum_status(
ref_index: ReferendumIndex,
) -> Result<ReferendumStatus<T::BlockNumber, BoundedCallOf<T>, BalanceOf<T>>, DispatchError> {
) -> Result<ReferendumStatus<BlockNumberFor<T>, BoundedCallOf<T>, BalanceOf<T>>, DispatchError>
{
let info = ReferendumInfoOf::<T>::get(ref_index).ok_or(Error::<T>::ReferendumInvalid)?;
Self::ensure_ongoing(info)
}
@@ -1515,10 +1520,10 @@ impl<T: Config> Pallet<T> {
/// Start a referendum
fn inject_referendum(
end: T::BlockNumber,
end: BlockNumberFor<T>,
proposal: BoundedCallOf<T>,
threshold: VoteThreshold,
delay: T::BlockNumber,
delay: BlockNumberFor<T>,
) -> ReferendumIndex {
let ref_index = Self::referendum_count();
ReferendumCount::<T>::put(ref_index + 1);
@@ -1531,7 +1536,7 @@ impl<T: Config> Pallet<T> {
}
/// Table the next waiting proposal for a vote.
fn launch_next(now: T::BlockNumber) -> DispatchResult {
fn launch_next(now: BlockNumberFor<T>) -> DispatchResult {
if LastTabledWasExternal::<T>::take() {
Self::launch_public(now).or_else(|_| Self::launch_external(now))
} else {
@@ -1541,7 +1546,7 @@ impl<T: Config> Pallet<T> {
}
/// Table the waiting external proposal for a vote, if there is one.
fn launch_external(now: T::BlockNumber) -> DispatchResult {
fn launch_external(now: BlockNumberFor<T>) -> DispatchResult {
if let Some((proposal, threshold)) = <NextExternal<T>>::take() {
LastTabledWasExternal::<T>::put(true);
Self::deposit_event(Event::<T>::ExternalTabled);
@@ -1559,7 +1564,7 @@ impl<T: Config> Pallet<T> {
}
/// Table the waiting public proposal with the highest backing for a vote.
fn launch_public(now: T::BlockNumber) -> DispatchResult {
fn launch_public(now: BlockNumberFor<T>) -> DispatchResult {
let mut public_props = Self::public_props();
if let Some((winner_index, _)) = public_props.iter().enumerate().max_by_key(
// defensive only: All current public proposals have an amount locked
@@ -1592,9 +1597,9 @@ impl<T: Config> Pallet<T> {
}
fn bake_referendum(
now: T::BlockNumber,
now: BlockNumberFor<T>,
index: ReferendumIndex,
status: ReferendumStatus<T::BlockNumber, BoundedCallOf<T>, BalanceOf<T>>,
status: ReferendumStatus<BlockNumberFor<T>, BoundedCallOf<T>, BalanceOf<T>>,
) -> bool {
let total_issuance = T::Currency::total_issuance();
let approved = status.threshold.approved(status.tally, total_issuance);
@@ -1629,7 +1634,7 @@ impl<T: Config> Pallet<T> {
/// ## Complexity:
/// If a referendum is launched or maturing, this will take full block weight if queue is not
/// empty. Otherwise, `O(R)` where `R` is the number of unbaked referenda.
fn begin_block(now: T::BlockNumber) -> Weight {
fn begin_block(now: BlockNumberFor<T>) -> Weight {
let max_block_weight = T::BlockWeights::get().max_block;
let mut weight = Weight::zero();
@@ -19,6 +19,7 @@
use crate::*;
use frame_support::{pallet_prelude::*, storage_alias, traits::OnRuntimeUpgrade, BoundedVec};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_core::H256;
/// The log target.
@@ -45,11 +46,7 @@ mod v0 {
Pallet<T>,
frame_support::Twox64Concat,
ReferendumIndex,
ReferendumInfo<
<T as frame_system::Config>::BlockNumber,
<T as frame_system::Config>::Hash,
BalanceOf<T>,
>,
ReferendumInfo<BlockNumberFor<T>, <T as frame_system::Config>::Hash, BalanceOf<T>>,
>;
}
@@ -87,7 +84,7 @@ pub mod v1 {
}
ReferendumInfoOf::<T>::translate(
|index, old: ReferendumInfo<T::BlockNumber, T::Hash, BalanceOf<T>>| {
|index, old: ReferendumInfo<BlockNumberFor<T>, T::Hash, BalanceOf<T>>| {
weight.saturating_accrue(T::DbWeight::get().reads_writes(1, 1));
log::info!(target: TARGET, "migrating referendum #{:?}", &index);
Some(match old {
+2 -8
View File
@@ -31,7 +31,6 @@ use frame_system::{EnsureRoot, EnsureSigned, EnsureSignedBy};
use pallet_balances::{BalanceLock, Error as BalancesError};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BadOrigin, BlakeTwo256, Hash, IdentityLookup},
BuildStorage, Perbill,
};
@@ -51,14 +50,10 @@ const NAY: Vote = Vote { aye: false, conviction: Conviction::None };
const BIG_AYE: Vote = Vote { aye: true, conviction: Conviction::Locked1x };
const BIG_NAY: Vote = Vote { aye: false, conviction: Conviction::Locked1x };
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -89,13 +84,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -313,7 +313,7 @@ frame_benchmarking::benchmarks! {
assert!(<DesiredTargets<T>>::get().is_none());
assert!(<Snapshot<T>>::get().is_none());
assert!(<SnapshotMetadata<T>>::get().is_none());
assert_eq!(<CurrentPhase<T>>::get(), <Phase<T::BlockNumber>>::Off);
assert_eq!(<CurrentPhase<T>>::get(), <Phase<frame_system::pallet_prelude::BlockNumberFor::<T>>>::Off);
}
submit {
@@ -241,7 +241,7 @@ use frame_support::{
weights::Weight,
DefaultNoBound, EqNoBound, PartialEqNoBound,
};
use frame_system::{ensure_none, offchain::SendTransactionTypes};
use frame_system::{ensure_none, offchain::SendTransactionTypes, pallet_prelude::BlockNumberFor};
use scale_info::TypeInfo;
use sp_arithmetic::{
traits::{CheckedAdd, Zero},
@@ -585,10 +585,10 @@ pub mod pallet {
/// Duration of the unsigned phase.
#[pallet::constant]
type UnsignedPhase: Get<Self::BlockNumber>;
type UnsignedPhase: Get<BlockNumberFor<Self>>;
/// Duration of the signed phase.
#[pallet::constant]
type SignedPhase: Get<Self::BlockNumber>;
type SignedPhase: Get<BlockNumberFor<Self>>;
/// The minimum amount of improvement to the solution score that defines a solution as
/// "better" in the Signed phase.
@@ -605,7 +605,7 @@ pub mod pallet {
/// For example, if it is 5, that means that at least 5 blocks will elapse between attempts
/// to submit the worker's solution.
#[pallet::constant]
type OffchainRepeat: Get<Self::BlockNumber>;
type OffchainRepeat: Get<BlockNumberFor<Self>>;
/// The priority of the unsigned transaction submitted in the unsigned-phase
#[pallet::constant]
@@ -685,13 +685,13 @@ pub mod pallet {
/// Something that will provide the election data.
type DataProvider: ElectionDataProvider<
AccountId = Self::AccountId,
BlockNumber = Self::BlockNumber,
BlockNumber = BlockNumberFor<Self>,
>;
/// Configuration for the fallback.
type Fallback: InstantElectionProvider<
AccountId = Self::AccountId,
BlockNumber = Self::BlockNumber,
BlockNumber = BlockNumberFor<Self>,
DataProvider = Self::DataProvider,
MaxWinners = Self::MaxWinners,
>;
@@ -702,7 +702,7 @@ pub mod pallet {
/// BoundedExecution<_>` if the test-net is not expected to have thousands of nominators.
type GovernanceFallback: InstantElectionProvider<
AccountId = Self::AccountId,
BlockNumber = Self::BlockNumber,
BlockNumber = BlockNumberFor<Self>,
DataProvider = Self::DataProvider,
MaxWinners = Self::MaxWinners,
>;
@@ -747,7 +747,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(now: T::BlockNumber) -> Weight {
fn on_initialize(now: BlockNumberFor<T>) -> Weight {
let next_election = T::DataProvider::next_election_prediction(now).max(now);
let signed_deadline = T::SignedPhase::get() + T::UnsignedPhase::get();
@@ -824,7 +824,7 @@ pub mod pallet {
}
}
fn offchain_worker(now: T::BlockNumber) {
fn offchain_worker(now: BlockNumberFor<T>) {
use sp_runtime::offchain::storage_lock::{BlockAndTime, StorageLock};
// Create a lock with the maximum deadline of number of blocks in the unsigned phase.
@@ -886,7 +886,7 @@ pub mod pallet {
}
#[cfg(feature = "try-runtime")]
fn try_state(_n: T::BlockNumber) -> Result<(), TryRuntimeError> {
fn try_state(_n: BlockNumberFor<T>) -> Result<(), TryRuntimeError> {
Self::do_try_state()
}
}
@@ -1155,7 +1155,11 @@ pub mod pallet {
/// An account has been slashed for submitting an invalid signed submission.
Slashed { account: <T as frame_system::Config>::AccountId, value: BalanceOf<T> },
/// There was a phase transition in a given round.
PhaseTransitioned { from: Phase<T::BlockNumber>, to: Phase<T::BlockNumber>, round: u32 },
PhaseTransitioned {
from: Phase<BlockNumberFor<T>>,
to: Phase<BlockNumberFor<T>>,
round: u32,
},
}
/// Error of the pallet that can be returned in response to dispatches.
@@ -1257,7 +1261,7 @@ pub mod pallet {
/// Current phase.
#[pallet::storage]
#[pallet::getter(fn current_phase)]
pub type CurrentPhase<T: Config> = StorageValue<_, Phase<T::BlockNumber>, ValueQuery>;
pub type CurrentPhase<T: Config> = StorageValue<_, Phase<BlockNumberFor<T>>, ValueQuery>;
/// Current best solution, signed or unsigned, queued to be returned upon `elect`.
///
@@ -1349,7 +1353,7 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
/// Internal logic of the offchain worker, to be executed only when the offchain lock is
/// acquired with success.
fn do_synchronized_offchain_worker(now: T::BlockNumber) {
fn do_synchronized_offchain_worker(now: BlockNumberFor<T>) {
let current_phase = Self::current_phase();
log!(trace, "lock for offchain worker acquired. Phase = {:?}", current_phase);
match current_phase {
@@ -1375,7 +1379,7 @@ impl<T: Config> Pallet<T> {
}
/// Phase transition helper.
pub(crate) fn phase_transition(to: Phase<T::BlockNumber>) {
pub(crate) fn phase_transition(to: Phase<BlockNumberFor<T>>) {
log!(info, "Starting phase {:?}, round {}.", to, Self::round());
Self::deposit_event(Event::PhaseTransitioned {
from: <CurrentPhase<T>>::get(),
@@ -1672,7 +1676,7 @@ impl<T: Config> Pallet<T> {
impl<T: Config> ElectionProviderBase for Pallet<T> {
type AccountId = T::AccountId;
type BlockNumber = T::BlockNumber;
type BlockNumber = BlockNumberFor<T>;
type Error = ElectionError<T>;
type MaxWinners = T::MaxWinners;
type DataProvider = T::DataProvider;
@@ -54,10 +54,7 @@ pub type UncheckedExtrinsic =
sp_runtime::generic::UncheckedExtrinsic<AccountId, RuntimeCall, (), ()>;
frame_support::construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
pub struct Runtime
{
System: frame_system::{Pallet, Call, Event<T>, Config<T>},
Balances: pallet_balances::{Pallet, Call, Event<T>, Config<T>},
@@ -212,13 +209,12 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = BlockNumber;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type DbWeight = ();
@@ -322,8 +318,8 @@ impl onchain::Config for OnChainSeqPhragmen {
pub struct MockFallback;
impl ElectionProviderBase for MockFallback {
type BlockNumber = BlockNumber;
type AccountId = AccountId;
type BlockNumber = u64;
type Error = &'static str;
type DataProvider = StakingMock;
type MaxWinners = MaxWinners;
@@ -436,8 +432,8 @@ pub struct ExtBuilder {}
pub struct StakingMock;
impl ElectionDataProvider for StakingMock {
type BlockNumber = BlockNumber;
type AccountId = AccountId;
type BlockNumber = u64;
type MaxVotesPerVoter = MaxNominations;
fn electable_targets(maybe_max_len: Option<usize>) -> data_provider::Result<Vec<AccountId>> {
@@ -27,6 +27,7 @@ use frame_election_provider_support::NposSolution;
use frame_support::traits::{
defensive_prelude::*, Currency, Get, OnUnbalanced, ReservableCurrency,
};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_arithmetic::traits::SaturatedConversion;
use sp_core::bounded::BoundedVec;
use sp_npos_elections::ElectionScore;
@@ -100,10 +101,8 @@ pub type SignedSubmissionOf<T> = SignedSubmission<
/// Always sorted vector of a score, submitted at the given block number, which can be found at the
/// given index (`u32`) of the `SignedSubmissionsMap`.
pub type SubmissionIndicesOf<T> = BoundedVec<
(ElectionScore, <T as frame_system::Config>::BlockNumber, u32),
<T as Config>::SignedMaxSubmissions,
>;
pub type SubmissionIndicesOf<T> =
BoundedVec<(ElectionScore, BlockNumberFor<T>, u32), <T as Config>::SignedMaxSubmissions>;
/// Outcome of [`SignedSubmissions::insert`].
pub enum InsertResult<T: Config> {
@@ -216,7 +215,7 @@ impl<T: Config> SignedSubmissions<T> {
fn swap_out_submission(
&mut self,
remove_pos: usize,
insert: Option<(ElectionScore, T::BlockNumber, u32)>,
insert: Option<(ElectionScore, BlockNumberFor<T>, u32)>,
) -> Option<SignedSubmissionOf<T>> {
if remove_pos >= self.indices.len() {
return None
@@ -29,7 +29,7 @@ use frame_support::{
traits::{DefensiveResult, Get},
BoundedVec,
};
use frame_system::offchain::SubmitTransaction;
use frame_system::{offchain::SubmitTransaction, pallet_prelude::BlockNumberFor};
use scale_info::TypeInfo;
use sp_npos_elections::{
assignment_ratio_to_staked_normalized, assignment_staked_to_ratio_normalized, ElectionResult,
@@ -298,12 +298,12 @@ impl<T: Config> Pallet<T> {
///
/// Returns `Ok(())` if offchain worker limit is respected, `Err(reason)` otherwise. If `Ok()`
/// is returned, `now` is written in storage and will be used in further calls as the baseline.
pub fn ensure_offchain_repeat_frequency(now: T::BlockNumber) -> Result<(), MinerError> {
pub fn ensure_offchain_repeat_frequency(now: BlockNumberFor<T>) -> Result<(), MinerError> {
let threshold = T::OffchainRepeat::get();
let last_block = StorageValueRef::persistent(OFFCHAIN_LAST_BLOCK);
let mutate_stat = last_block.mutate::<_, &'static str, _>(
|maybe_head: Result<Option<T::BlockNumber>, _>| {
|maybe_head: Result<Option<BlockNumberFor<T>>, _>| {
match maybe_head {
Ok(Some(head)) if now < head => Err("fork."),
Ok(Some(head)) if now >= head && now <= head + threshold =>
@@ -46,14 +46,11 @@ pub const INIT_TIMESTAMP: u64 = 30_000;
pub const BLOCK_TIME: u64 = 1000;
type Block = frame_system::mocking::MockBlock<Runtime>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Extrinsic = testing::TestXt<RuntimeCall, ()>;
frame_support::construct_runtime!(
pub enum Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
pub enum Runtime
{
System: frame_system,
ElectionProviderMultiPhase: pallet_election_provider_multi_phase,
@@ -81,13 +78,12 @@ impl frame_system::Config for Runtime {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = AccountIndex;
type BlockNumber = BlockNumber;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = sp_runtime::testing::Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type Version = ();
@@ -73,7 +73,7 @@ pub trait Config {
/// Something that provides the data for election.
type DataProvider: ElectionDataProvider<
AccountId = <Self::System as frame_system::Config>::AccountId,
BlockNumber = <Self::System as frame_system::Config>::BlockNumber,
BlockNumber = frame_system::pallet_prelude::BlockNumberFor<Self::System>,
>;
/// Weight information for extrinsics in this pallet.
@@ -151,7 +151,7 @@ fn elect_with_input_bounds<T: Config>(
impl<T: Config> ElectionProviderBase for OnChainExecution<T> {
type AccountId = <T::System as frame_system::Config>::AccountId;
type BlockNumber = <T::System as frame_system::Config>::BlockNumber;
type BlockNumber = frame_system::pallet_prelude::BlockNumberFor<T::System>;
type Error = Error;
type MaxWinners = T::MaxWinners;
type DataProvider = T::DataProvider;
@@ -197,10 +197,7 @@ mod tests {
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
frame_support::construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
pub struct Runtime
{
System: frame_system::{Pallet, Call, Event<T>},
}
@@ -211,13 +208,12 @@ mod tests {
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type Index = AccountId;
type BlockNumber = BlockNumber;
type RuntimeCall = RuntimeCall;
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = sp_runtime::traits::IdentityLookup<Self::AccountId>;
type Header = sp_runtime::testing::Header;
type Block = Block;
type RuntimeEvent = ();
type BlockHashCount = ();
type DbWeight = ();
+6 -10
View File
@@ -204,7 +204,7 @@ pub mod pallet {
type PalletId: Get<LockIdentifier>;
/// The currency that people are electing with.
type Currency: LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>
type Currency: LockableCurrency<Self::AccountId, Moment = BlockNumberFor<Self>>
+ ReservableCurrency<Self::AccountId>;
/// What to do when the members change.
@@ -250,7 +250,7 @@ pub mod pallet {
/// round will happen. If set to zero, no elections are ever triggered and the module will
/// be in passive mode.
#[pallet::constant]
type TermDuration: Get<Self::BlockNumber>;
type TermDuration: Get<BlockNumberFor<Self>>;
/// The maximum number of candidates in a phragmen election.
///
@@ -286,7 +286,7 @@ pub mod pallet {
/// What to do at the end of each block.
///
/// Checks if an election needs to happen or not.
fn on_initialize(n: T::BlockNumber) -> Weight {
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
let term_duration = T::TermDuration::get();
if !term_duration.is_zero() && (n % term_duration).is_zero() {
Self::do_phragmen()
@@ -331,7 +331,7 @@ pub mod pallet {
}
#[cfg(feature = "try-runtime")]
fn try_state(_n: T::BlockNumber) -> Result<(), TryRuntimeError> {
fn try_state(_n: BlockNumberFor<T>) -> Result<(), TryRuntimeError> {
Self::do_try_state()
}
}
@@ -1324,13 +1324,12 @@ mod tests {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -1447,10 +1446,7 @@ mod tests {
sp_runtime::generic::UncheckedExtrinsic<u32, u64, RuntimeCall, ()>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
pub enum Test
{
System: frame_system::{Pallet, Call, Event<T>},
Balances: pallet_balances::{Pallet, Call, Event<T>, Config<T>},
+3 -3
View File
@@ -388,21 +388,21 @@ pub mod pallet {
// dispatched.
//
// This function must return the weight consumed by `on_initialize` and `on_finalize`.
fn on_initialize(_n: T::BlockNumber) -> Weight {
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
// Anything that needs to be done at the start of the block.
// We don't do anything here.
Weight::zero()
}
// `on_finalize` is executed at the end of block after all extrinsic are dispatched.
fn on_finalize(_n: T::BlockNumber) {
fn on_finalize(_n: BlockNumberFor<T>) {
// Perform necessary data/state clean up here.
}
// A runtime code run after every block and have access to extended set of APIs.
//
// For instance you can generate extrinsics for the upcoming produced block.
fn offchain_worker(_n: T::BlockNumber) {
fn offchain_worker(_n: BlockNumberFor<T>) {
// We don't do anything here.
// but we could dispatch extrinsic (transaction/unsigned/inherent) using
// sp_io::submit_extrinsic.
+2 -8
View File
@@ -27,22 +27,17 @@ use sp_core::H256;
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
// Reexport crate as its pallet name for construct_runtime.
use crate as pallet_example_basic;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
// For testing the pallet, we construct a mock runtime.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -57,13 +52,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -107,17 +107,14 @@ pub mod pallet {
pub mod tests {
use super::*;
use frame_support::derive_impl;
use sp_runtime::traits::ConstU64;
use super::pallet as pallet_default_config_example;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
DefaultPallet: pallet_default_config_example,
@@ -129,6 +126,8 @@ pub mod tests {
// these items are defined by frame-system as `no_default`, so we must specify them here.
// Note that these are types that actually rely on the outer runtime, and can't sensibly
// have an _independent_ default.
type Block = Block;
type BlockHashCount = ConstU64<10>;
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
@@ -140,7 +139,9 @@ pub mod tests {
// type Index = u32;
// type BlockNumber = u32;
// type Header = sp_runtime::generic::Header<Self::BlockNumber, Self::Hashing>;
// type Header =
// sp_runtime::generic::Header<frame_system::pallet_prelude::BlockNumberFor<Self>,
// Self::Hashing>;
// type Hash = sp_core::hash::H256;
// type Hashing = sp_runtime::traits::BlakeTwo256;
// type AccountId = u64;
@@ -21,22 +21,17 @@ use crate::*;
use frame_support::{assert_ok, traits::ConstU64};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
// Reexport crate as its pallet name for construct_runtime.
use crate as pallet_dev_mode;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
// For testing the pallet, we construct a mock runtime.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -51,13 +46,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -183,7 +183,7 @@ pub mod pallet {
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
pub foo: u32,
pub bar: T::BlockNumber,
pub bar: BlockNumberFor<T>,
}
impl<T: Config> Default for GenesisConfig<T> {
@@ -249,22 +249,22 @@ pub mod pallet {
/// All the possible hooks that a pallet can have. See [`frame_support::traits::Hooks`] for more
/// info.
#[pallet::hooks]
impl<T: Config> Hooks<T::BlockNumber> for Pallet<T> {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn integrity_test() {}
fn offchain_worker(_n: T::BlockNumber) {
fn offchain_worker(_n: BlockNumberFor<T>) {
unimplemented!()
}
fn on_initialize(_n: T::BlockNumber) -> Weight {
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
unimplemented!()
}
fn on_finalize(_n: T::BlockNumber) {
fn on_finalize(_n: BlockNumberFor<T>) {
unimplemented!()
}
fn on_idle(_n: T::BlockNumber, _remaining_weight: Weight) -> Weight {
fn on_idle(_n: BlockNumberFor<T>, _remaining_weight: Weight) -> Weight {
unimplemented!()
}
@@ -283,7 +283,7 @@ pub mod pallet {
}
#[cfg(feature = "try-runtime")]
fn try_state(_n: T::BlockNumber) -> Result<(), TryRuntimeError> {
fn try_state(_n: BlockNumberFor<T>) -> Result<(), TryRuntimeError> {
unimplemented!()
}
}
@@ -23,15 +23,11 @@ use sp_runtime::BuildStorage;
// Reexport crate as its pallet name for construct_runtime.
use crate as pallet_example_kitchensink;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
// For testing the pallet, we construct a mock runtime.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -44,6 +40,8 @@ frame_support::construct_runtime!(
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type Block = Block;
type BlockHashCount = ConstU64<10>;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
@@ -53,6 +53,7 @@ use frame_system::{
AppCrypto, CreateSignedTransaction, SendSignedTransaction, SendUnsignedTransaction,
SignedPayload, Signer, SigningTypes, SubmitTransaction,
},
pallet_prelude::BlockNumberFor,
};
use lite_json::json::JsonValue;
use sp_core::crypto::KeyTypeId;
@@ -136,14 +137,14 @@ pub mod pallet {
/// every `GRACE_PERIOD` blocks. We use Local Storage to coordinate
/// sending between distinct runs of this offchain worker.
#[pallet::constant]
type GracePeriod: Get<Self::BlockNumber>;
type GracePeriod: Get<BlockNumberFor<Self>>;
/// Number of blocks of cooldown after unsigned transaction is included.
///
/// This ensures that we only accept unsigned transactions once, every `UnsignedInterval`
/// blocks.
#[pallet::constant]
type UnsignedInterval: Get<Self::BlockNumber>;
type UnsignedInterval: Get<BlockNumberFor<Self>>;
/// A configuration for base priority of unsigned transactions.
///
@@ -171,7 +172,7 @@ pub mod pallet {
/// be cases where some blocks are skipped, or for some the worker runs twice (re-orgs),
/// so the code should be able to handle that.
/// You can use `Local Storage` API to coordinate runs of the worker.
fn offchain_worker(block_number: T::BlockNumber) {
fn offchain_worker(block_number: BlockNumberFor<T>) {
// Note that having logs compiled to WASM may cause the size of the blob to increase
// significantly. You can use `RuntimeDebug` custom derive to hide details of the types
// in WASM. The `sp-api` crate also provides a feature `disable-logging` to disable
@@ -258,7 +259,7 @@ pub mod pallet {
#[pallet::weight({0})]
pub fn submit_price_unsigned(
origin: OriginFor<T>,
_block_number: T::BlockNumber,
_block_number: BlockNumberFor<T>,
price: u32,
) -> DispatchResultWithPostInfo {
// This ensures that the function can only be called via unsigned transaction.
@@ -275,7 +276,7 @@ pub mod pallet {
#[pallet::weight({0})]
pub fn submit_price_unsigned_with_signed_payload(
origin: OriginFor<T>,
price_payload: PricePayload<T::Public, T::BlockNumber>,
price_payload: PricePayload<T::Public, BlockNumberFor<T>>,
_signature: T::Signature,
) -> DispatchResultWithPostInfo {
// This ensures that the function can only be called via unsigned transaction.
@@ -341,7 +342,7 @@ pub mod pallet {
/// This storage entry defines when new transaction is going to be accepted.
#[pallet::storage]
#[pallet::getter(fn next_unsigned_at)]
pub(super) type NextUnsignedAt<T: Config> = StorageValue<_, T::BlockNumber, ValueQuery>;
pub(super) type NextUnsignedAt<T: Config> = StorageValue<_, BlockNumberFor<T>, ValueQuery>;
}
/// Payload used by this example crate to hold price
@@ -353,7 +354,7 @@ pub struct PricePayload<Public, BlockNumber> {
public: Public,
}
impl<T: SigningTypes> SignedPayload<T> for PricePayload<T::Public, T::BlockNumber> {
impl<T: SigningTypes> SignedPayload<T> for PricePayload<T::Public, BlockNumberFor<T>> {
fn public(&self) -> T::Public {
self.public.clone()
}
@@ -374,7 +375,7 @@ impl<T: Config> Pallet<T> {
/// and local storage usage.
///
/// Returns a type of transaction that should be produced in current run.
fn choose_transaction_type(block_number: T::BlockNumber) -> TransactionType {
fn choose_transaction_type(block_number: BlockNumberFor<T>) -> TransactionType {
/// A friendlier name for the error that is going to be returned in case we are in the grace
/// period.
const RECENTLY_SENT: () = ();
@@ -389,16 +390,17 @@ impl<T: Config> Pallet<T> {
// low-level method of local storage API, which means that only one worker
// will be able to "acquire a lock" and send a transaction if multiple workers
// happen to be executed concurrently.
let res = val.mutate(|last_send: Result<Option<T::BlockNumber>, StorageRetrievalError>| {
match last_send {
// If we already have a value in storage and the block number is recent enough
// we avoid sending another transaction at this time.
Ok(Some(block)) if block_number < block + T::GracePeriod::get() =>
Err(RECENTLY_SENT),
// In every other case we attempt to acquire the lock and send a transaction.
_ => Ok(block_number),
}
});
let res =
val.mutate(|last_send: Result<Option<BlockNumberFor<T>>, StorageRetrievalError>| {
match last_send {
// If we already have a value in storage and the block number is recent enough
// we avoid sending another transaction at this time.
Ok(Some(block)) if block_number < block + T::GracePeriod::get() =>
Err(RECENTLY_SENT),
// In every other case we attempt to acquire the lock and send a transaction.
_ => Ok(block_number),
}
});
// The result of `mutate` call will give us a nested `Result` type.
// The first one matches the return of the closure passed to `mutate`, i.e.
@@ -419,9 +421,9 @@ impl<T: Config> Pallet<T> {
let transaction_type = block_number % 4u32.into();
if transaction_type == Zero::zero() {
TransactionType::Signed
} else if transaction_type == T::BlockNumber::from(1u32) {
} else if transaction_type == BlockNumberFor::<T>::from(1u32) {
TransactionType::UnsignedForAny
} else if transaction_type == T::BlockNumber::from(2u32) {
} else if transaction_type == BlockNumberFor::<T>::from(2u32) {
TransactionType::UnsignedForAll
} else {
TransactionType::Raw
@@ -472,7 +474,9 @@ impl<T: Config> Pallet<T> {
}
/// A helper function to fetch the price and send a raw unsigned transaction.
fn fetch_price_and_send_raw_unsigned(block_number: T::BlockNumber) -> Result<(), &'static str> {
fn fetch_price_and_send_raw_unsigned(
block_number: BlockNumberFor<T>,
) -> Result<(), &'static str> {
// Make sure we don't fetch the price if unsigned transaction is going to be rejected
// anyway.
let next_unsigned_at = <NextUnsignedAt<T>>::get();
@@ -505,7 +509,7 @@ impl<T: Config> Pallet<T> {
/// A helper function to fetch the price, sign payload and send an unsigned transaction
fn fetch_price_and_send_unsigned_for_any_account(
block_number: T::BlockNumber,
block_number: BlockNumberFor<T>,
) -> Result<(), &'static str> {
// Make sure we don't fetch the price if unsigned transaction is going to be rejected
// anyway.
@@ -535,7 +539,7 @@ impl<T: Config> Pallet<T> {
/// A helper function to fetch the price, sign payload and send an unsigned transaction
fn fetch_price_and_send_unsigned_for_all_accounts(
block_number: T::BlockNumber,
block_number: BlockNumberFor<T>,
) -> Result<(), &'static str> {
// Make sure we don't fetch the price if unsigned transaction is going to be rejected
// anyway.
@@ -669,7 +673,7 @@ impl<T: Config> Pallet<T> {
}
fn validate_transaction_parameters(
block_number: &T::BlockNumber,
block_number: &BlockNumberFor<T>,
new_price: &u32,
) -> TransactionValidity {
// Now let's check if the transaction has any chance to succeed.
@@ -30,20 +30,16 @@ use sp_core::{
use sp_keystore::{testing::MemoryKeystore, Keystore, KeystoreExt};
use sp_runtime::{
testing::{Header, TestXt},
testing::TestXt,
traits::{BlakeTwo256, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, Verify},
RuntimeAppPublic,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
// For testing the module, we construct a mock runtime.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Example: example_offchain_worker::{Pallet, Call, Storage, Event<T>, ValidateUnsigned},
@@ -58,12 +54,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = sp_core::sr25519::Public;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -274,7 +269,7 @@ fn should_submit_unsigned_transaction_on_chain_for_any_account() {
let signature_valid =
<PricePayload<
<Test as SigningTypes>::Public,
<Test as frame_system::Config>::BlockNumber,
frame_system::pallet_prelude::BlockNumberFor<Test>,
> as SignedPayload<Test>>::verify::<crypto::TestAuthId>(&price_payload, signature);
assert!(signature_valid);
@@ -328,7 +323,7 @@ fn should_submit_unsigned_transaction_on_chain_for_all_accounts() {
let signature_valid =
<PricePayload<
<Test as SigningTypes>::Public,
<Test as frame_system::Config>::BlockNumber,
frame_system::pallet_prelude::BlockNumberFor<Test>,
> as SignedPayload<Test>>::verify::<crypto::TestAuthId>(&price_payload, signature);
assert!(signature_valid);
+4 -5
View File
@@ -17,16 +17,13 @@
use crate as pallet_template;
use frame_support::{derive_impl, sp_runtime::BuildStorage};
use sp_core::ConstU64;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
TemplatePallet: pallet_template,
@@ -37,6 +34,8 @@ frame_support::construct_runtime!(
/// details.
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test {
type Block = Block;
type BlockHashCount = ConstU64<10>;
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
+54 -46
View File
@@ -126,6 +126,7 @@ use frame_support::{
},
weights::Weight,
};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_runtime::{
generic::Digest,
traits::{
@@ -178,14 +179,17 @@ pub struct Executive<
impl<
System: frame_system::Config + EnsureInherentsAreFirst<Block>,
Block: traits::Block<Header = System::Header, Hash = System::Hash>,
Block: traits::Block<
Header = frame_system::pallet_prelude::HeaderFor<System>,
Hash = System::Hash,
>,
Context: Default,
UnsignedValidator,
AllPalletsWithSystem: OnRuntimeUpgrade
+ OnInitialize<System::BlockNumber>
+ OnIdle<System::BlockNumber>
+ OnFinalize<System::BlockNumber>
+ OffchainWorker<System::BlockNumber>,
+ OnInitialize<BlockNumberFor<System>>
+ OnIdle<BlockNumberFor<System>>
+ OnFinalize<BlockNumberFor<System>>
+ OffchainWorker<BlockNumberFor<System>>,
COnRuntimeUpgrade: OnRuntimeUpgrade,
> ExecuteBlock<Block>
for Executive<System, Block, Context, UnsignedValidator, AllPalletsWithSystem, COnRuntimeUpgrade>
@@ -212,15 +216,18 @@ where
#[cfg(feature = "try-runtime")]
impl<
System: frame_system::Config + EnsureInherentsAreFirst<Block>,
Block: traits::Block<Header = System::Header, Hash = System::Hash>,
Block: traits::Block<
Header = frame_system::pallet_prelude::HeaderFor<System>,
Hash = System::Hash,
>,
Context: Default,
UnsignedValidator,
AllPalletsWithSystem: OnRuntimeUpgrade
+ OnInitialize<System::BlockNumber>
+ OnIdle<System::BlockNumber>
+ OnFinalize<System::BlockNumber>
+ OffchainWorker<System::BlockNumber>
+ frame_support::traits::TryState<System::BlockNumber>,
+ OnInitialize<BlockNumberFor<System>>
+ OnIdle<BlockNumberFor<System>>
+ OnFinalize<BlockNumberFor<System>>
+ OffchainWorker<BlockNumberFor<System>>
+ frame_support::traits::TryState<BlockNumberFor<System>>,
COnRuntimeUpgrade: OnRuntimeUpgrade,
> Executive<System, Block, Context, UnsignedValidator, AllPalletsWithSystem, COnRuntimeUpgrade>
where
@@ -297,10 +304,9 @@ where
// run the try-state checks of all pallets, ensuring they don't alter any state.
let _guard = frame_support::StorageNoopGuard::default();
<AllPalletsWithSystem as frame_support::traits::TryState<System::BlockNumber>>::try_state(
*header.number(),
select,
)
<AllPalletsWithSystem as frame_support::traits::TryState<
BlockNumberFor<System>,
>>::try_state(*header.number(), select)
.map_err(|e| {
frame_support::log::error!(target: LOG_TARGET, "failure: {:?}", e);
e
@@ -350,7 +356,9 @@ where
) -> Result<Weight, TryRuntimeError> {
if checks.try_state() {
let _guard = frame_support::StorageNoopGuard::default();
<AllPalletsWithSystem as frame_support::traits::TryState<System::BlockNumber>>::try_state(
<AllPalletsWithSystem as frame_support::traits::TryState<
BlockNumberFor<System>,
>>::try_state(
frame_system::Pallet::<System>::block_number(),
frame_try_runtime::TryStateSelect::All,
)?;
@@ -363,7 +371,9 @@ where
if checks.try_state() {
let _guard = frame_support::StorageNoopGuard::default();
<AllPalletsWithSystem as frame_support::traits::TryState<System::BlockNumber>>::try_state(
<AllPalletsWithSystem as frame_support::traits::TryState<
BlockNumberFor<System>,
>>::try_state(
frame_system::Pallet::<System>::block_number(),
frame_try_runtime::TryStateSelect::All,
)?;
@@ -375,14 +385,17 @@ where
impl<
System: frame_system::Config + EnsureInherentsAreFirst<Block>,
Block: traits::Block<Header = System::Header, Hash = System::Hash>,
Block: traits::Block<
Header = frame_system::pallet_prelude::HeaderFor<System>,
Hash = System::Hash,
>,
Context: Default,
UnsignedValidator,
AllPalletsWithSystem: OnRuntimeUpgrade
+ OnInitialize<System::BlockNumber>
+ OnIdle<System::BlockNumber>
+ OnFinalize<System::BlockNumber>
+ OffchainWorker<System::BlockNumber>,
+ OnInitialize<BlockNumberFor<System>>
+ OnIdle<BlockNumberFor<System>>
+ OnFinalize<BlockNumberFor<System>>
+ OffchainWorker<BlockNumberFor<System>>,
COnRuntimeUpgrade: OnRuntimeUpgrade,
> Executive<System, Block, Context, UnsignedValidator, AllPalletsWithSystem, COnRuntimeUpgrade>
where
@@ -399,14 +412,14 @@ where
}
/// Start the execution of a particular block.
pub fn initialize_block(header: &System::Header) {
pub fn initialize_block(header: &frame_system::pallet_prelude::HeaderFor<System>) {
sp_io::init_tracing();
sp_tracing::enter_span!(sp_tracing::Level::TRACE, "init_block");
let digests = Self::extract_pre_digest(header);
Self::initialize_block_impl(header.number(), header.parent_hash(), &digests);
}
fn extract_pre_digest(header: &System::Header) -> Digest {
fn extract_pre_digest(header: &frame_system::pallet_prelude::HeaderFor<System>) -> Digest {
let mut digest = <Digest>::default();
header.digest().logs().iter().for_each(|d| {
if d.as_pre_runtime().is_some() {
@@ -417,7 +430,7 @@ where
}
fn initialize_block_impl(
block_number: &System::BlockNumber,
block_number: &BlockNumberFor<System>,
parent_hash: &System::Hash,
digest: &Digest,
) {
@@ -432,7 +445,7 @@ where
}
<frame_system::Pallet<System>>::initialize(block_number, parent_hash, digest);
weight = weight.saturating_add(<AllPalletsWithSystem as OnInitialize<
System::BlockNumber,
BlockNumberFor<System>,
>>::on_initialize(*block_number));
weight = weight.saturating_add(
<System::BlockWeights as frame_support::traits::Get<_>>::get().base_block,
@@ -467,8 +480,8 @@ where
// Check that `parent_hash` is correct.
let n = *header.number();
assert!(
n > System::BlockNumber::zero() &&
<frame_system::Pallet<System>>::block_hash(n - System::BlockNumber::one()) ==
n > BlockNumberFor::<System>::zero() &&
<frame_system::Pallet<System>>::block_hash(n - BlockNumberFor::<System>::one()) ==
*header.parent_hash(),
"Parent hash should be valid.",
);
@@ -518,7 +531,7 @@ where
/// Finalize the block - it is up the caller to ensure that all header fields are valid
/// except state-root.
pub fn finalize_block() -> System::Header {
pub fn finalize_block() -> frame_system::pallet_prelude::HeaderFor<System> {
sp_io::init_tracing();
sp_tracing::enter_span!(sp_tracing::Level::TRACE, "finalize_block");
<frame_system::Pallet<System>>::note_finished_extrinsics();
@@ -535,7 +548,7 @@ where
let remaining_weight = max_weight.saturating_sub(weight.total());
if remaining_weight.all_gt(Weight::zero()) {
let used_weight = <AllPalletsWithSystem as OnIdle<System::BlockNumber>>::on_idle(
let used_weight = <AllPalletsWithSystem as OnIdle<BlockNumberFor<System>>>::on_idle(
block_number,
remaining_weight,
);
@@ -545,7 +558,7 @@ where
);
}
<AllPalletsWithSystem as OnFinalize<System::BlockNumber>>::on_finalize(block_number);
<AllPalletsWithSystem as OnFinalize<BlockNumberFor<System>>>::on_finalize(block_number);
}
/// Apply extrinsic outside of the block execution function.
@@ -585,7 +598,7 @@ where
Ok(r.map(|_| ()).map_err(|e| e.error))
}
fn final_checks(header: &System::Header) {
fn final_checks(header: &frame_system::pallet_prelude::HeaderFor<System>) {
sp_tracing::enter_span!(sp_tracing::Level::TRACE, "final_checks");
// remove temporaries
let new_header = <frame_system::Pallet<System>>::finalize();
@@ -657,7 +670,7 @@ where
}
/// Start an offchain worker and generate extrinsics.
pub fn offchain_worker(header: &System::Header) {
pub fn offchain_worker(header: &frame_system::pallet_prelude::HeaderFor<System>) {
sp_io::init_tracing();
// We need to keep events available for offchain workers,
// hence we initialize the block manually.
@@ -671,7 +684,7 @@ where
// as well.
frame_system::BlockHash::<System>::insert(header.number(), header.hash());
<AllPalletsWithSystem as OffchainWorker<System::BlockNumber>>::offchain_worker(
<AllPalletsWithSystem as OffchainWorker<BlockNumberFor<System>>>::offchain_worker(
*header.number(),
)
}
@@ -718,17 +731,17 @@ mod tests {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
// module hooks.
// one with block number arg and one without
fn on_initialize(n: T::BlockNumber) -> Weight {
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
println!("on_initialize({})", n);
Weight::from_parts(175, 0)
}
fn on_idle(n: T::BlockNumber, remaining_weight: Weight) -> Weight {
fn on_idle(n: BlockNumberFor<T>, remaining_weight: Weight) -> Weight {
println!("on_idle{}, {})", n, remaining_weight);
Weight::from_parts(175, 0)
}
fn on_finalize(n: T::BlockNumber) {
fn on_finalize(n: BlockNumberFor<T>) {
println!("on_finalize({})", n);
}
@@ -737,8 +750,8 @@ mod tests {
Weight::from_parts(200, 0)
}
fn offchain_worker(n: T::BlockNumber) {
assert_eq!(T::BlockNumber::from(1u32), n);
fn offchain_worker(n: BlockNumberFor<T>) {
assert_eq!(BlockNumberFor::<T>::from(1u32), n);
}
}
@@ -828,10 +841,7 @@ mod tests {
}
frame_support::construct_runtime!(
pub struct Runtime where
Block = TestBlock,
NodeBlock = TestBlock,
UncheckedExtrinsic = TestUncheckedExtrinsic
pub struct Runtime
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -860,12 +870,11 @@ mod tests {
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type RuntimeCall = RuntimeCall;
type BlockNumber = u64;
type Hash = sp_core::H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<u64>;
type Header = Header;
type Block = TestBlock;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = RuntimeVersion;
@@ -929,7 +938,6 @@ mod tests {
);
type TestXt = sp_runtime::testing::TestXt<RuntimeCall, SignedExtra>;
type TestBlock = Block<TestXt>;
type TestUncheckedExtrinsic = TestXt;
// Will contain `true` when the custom runtime logic was called.
const CUSTOM_ON_RUNTIME_KEY: &[u8] = b":custom:on_runtime";
+3 -3
View File
@@ -272,8 +272,8 @@ pub mod pallet {
}
#[pallet::hooks]
impl<T: Config> Hooks<T::BlockNumber> for Pallet<T> {
fn on_idle(_: T::BlockNumber, remaining_weight: Weight) -> Weight {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_idle(_: BlockNumberFor<T>, remaining_weight: Weight) -> Weight {
if remaining_weight.any_lt(T::DbWeight::get().reads(2)) {
return Weight::from_parts(0, 0)
}
@@ -295,7 +295,7 @@ pub mod pallet {
}
#[cfg(feature = "try-runtime")]
fn try_state(_n: T::BlockNumber) -> Result<(), TryRuntimeError> {
fn try_state(_n: BlockNumberFor<T>) -> Result<(), TryRuntimeError> {
// ensure that the value of `ErasToCheckPerBlock` is less than
// `T::MaxErasToCheckPerBlock`.
ensure!(
+3 -9
View File
@@ -51,13 +51,12 @@ impl frame_system::Config for Runtime {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = AccountIndex;
type BlockNumber = BlockNumber;
type RuntimeCall = RuntimeCall;
type Hash = sp_core::H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = sp_runtime::testing::Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type Version = ();
@@ -198,14 +197,9 @@ impl fast_unstake::Config for Runtime {
}
type Block = frame_system::mocking::MockBlock<Runtime>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
frame_support::construct_runtime!(
pub struct Runtime
where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
pub struct Runtime {
System: frame_system,
Timestamp: pallet_timestamp,
Balances: pallet_balances,
+2 -8
View File
@@ -24,19 +24,14 @@ use frame_support::{
};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Glutton: pallet_glutton::{Pallet, Event},
@@ -50,13 +45,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+5 -4
View File
@@ -37,6 +37,7 @@
use codec::{self as codec, Decode, Encode};
use frame_support::traits::{Get, KeyOwnerProofSystem};
use frame_system::pallet_prelude::BlockNumberFor;
use log::{error, info};
use sp_consensus_grandpa::{AuthorityId, EquivocationProof, RoundNumber, SetId, KEY_TYPE};
use sp_runtime::{
@@ -118,7 +119,7 @@ pub struct EquivocationReportSystem<T, R, P, L>(sp_std::marker::PhantomData<(T,
impl<T, R, P, L>
OffenceReportSystem<
Option<T::AccountId>,
(EquivocationProof<T::Hash, T::BlockNumber>, T::KeyOwnerProof),
(EquivocationProof<T::Hash, BlockNumberFor<T>>, T::KeyOwnerProof),
> for EquivocationReportSystem<T, R, P, L>
where
T: Config + pallet_authorship::Config + frame_system::offchain::SendTransactionTypes<Call<T>>,
@@ -134,7 +135,7 @@ where
type Longevity = L;
fn publish_evidence(
evidence: (EquivocationProof<T::Hash, T::BlockNumber>, T::KeyOwnerProof),
evidence: (EquivocationProof<T::Hash, BlockNumberFor<T>>, T::KeyOwnerProof),
) -> Result<(), ()> {
use frame_system::offchain::SubmitTransaction;
let (equivocation_proof, key_owner_proof) = evidence;
@@ -152,7 +153,7 @@ where
}
fn check_evidence(
evidence: (EquivocationProof<T::Hash, T::BlockNumber>, T::KeyOwnerProof),
evidence: (EquivocationProof<T::Hash, BlockNumberFor<T>>, T::KeyOwnerProof),
) -> Result<(), TransactionValidityError> {
let (equivocation_proof, key_owner_proof) = evidence;
@@ -172,7 +173,7 @@ where
fn process_evidence(
reporter: Option<T::AccountId>,
evidence: (EquivocationProof<T::Hash, T::BlockNumber>, T::KeyOwnerProof),
evidence: (EquivocationProof<T::Hash, BlockNumberFor<T>>, T::KeyOwnerProof),
) -> Result<(), DispatchError> {
let (equivocation_proof, key_owner_proof) = evidence;
let reporter = reporter.or_else(|| <pallet_authorship::Pallet<T>>::author());
+19 -18
View File
@@ -42,6 +42,7 @@ use frame_support::{
weights::Weight,
WeakBoundedVec,
};
use frame_system::pallet_prelude::BlockNumberFor;
use scale_info::TypeInfo;
use sp_consensus_grandpa::{
ConsensusLog, EquivocationProof, ScheduledChange, SetId, GRANDPA_AUTHORITIES_KEY,
@@ -113,13 +114,13 @@ pub mod pallet {
/// (from an offchain context).
type EquivocationReportSystem: OffenceReportSystem<
Option<Self::AccountId>,
(EquivocationProof<Self::Hash, Self::BlockNumber>, Self::KeyOwnerProof),
(EquivocationProof<Self::Hash, BlockNumberFor<Self>>, Self::KeyOwnerProof),
>;
}
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_finalize(block_number: T::BlockNumber) {
fn on_finalize(block_number: BlockNumberFor<T>) {
// check for scheduled pending authority set changes
if let Some(pending_change) = <PendingChange<T>>::get() {
// emit signal if we're at the block that scheduled the change
@@ -191,7 +192,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::report_equivocation(key_owner_proof.validator_count()))]
pub fn report_equivocation(
origin: OriginFor<T>,
equivocation_proof: Box<EquivocationProof<T::Hash, T::BlockNumber>>,
equivocation_proof: Box<EquivocationProof<T::Hash, BlockNumberFor<T>>>,
key_owner_proof: T::KeyOwnerProof,
) -> DispatchResultWithPostInfo {
let reporter = ensure_signed(origin)?;
@@ -217,7 +218,7 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::report_equivocation(key_owner_proof.validator_count()))]
pub fn report_equivocation_unsigned(
origin: OriginFor<T>,
equivocation_proof: Box<EquivocationProof<T::Hash, T::BlockNumber>>,
equivocation_proof: Box<EquivocationProof<T::Hash, BlockNumberFor<T>>>,
key_owner_proof: T::KeyOwnerProof,
) -> DispatchResultWithPostInfo {
ensure_none(origin)?;
@@ -245,8 +246,8 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::note_stalled())]
pub fn note_stalled(
origin: OriginFor<T>,
delay: T::BlockNumber,
best_finalized_block_number: T::BlockNumber,
delay: BlockNumberFor<T>,
best_finalized_block_number: BlockNumberFor<T>,
) -> DispatchResult {
ensure_root(origin)?;
@@ -287,7 +288,7 @@ pub mod pallet {
}
#[pallet::type_value]
pub(super) fn DefaultForState<T: Config>() -> StoredState<T::BlockNumber> {
pub(super) fn DefaultForState<T: Config>() -> StoredState<BlockNumberFor<T>> {
StoredState::Live
}
@@ -295,23 +296,23 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn state)]
pub(super) type State<T: Config> =
StorageValue<_, StoredState<T::BlockNumber>, ValueQuery, DefaultForState<T>>;
StorageValue<_, StoredState<BlockNumberFor<T>>, ValueQuery, DefaultForState<T>>;
/// Pending change: (signaled at, scheduled change).
#[pallet::storage]
#[pallet::getter(fn pending_change)]
pub(super) type PendingChange<T: Config> =
StorageValue<_, StoredPendingChange<T::BlockNumber, T::MaxAuthorities>>;
StorageValue<_, StoredPendingChange<BlockNumberFor<T>, T::MaxAuthorities>>;
/// next block number where we can force a change.
#[pallet::storage]
#[pallet::getter(fn next_forced)]
pub(super) type NextForced<T: Config> = StorageValue<_, T::BlockNumber>;
pub(super) type NextForced<T: Config> = StorageValue<_, BlockNumberFor<T>>;
/// `true` if we are currently stalled.
#[pallet::storage]
#[pallet::getter(fn stalled)]
pub(super) type Stalled<T: Config> = StorageValue<_, (T::BlockNumber, T::BlockNumber)>;
pub(super) type Stalled<T: Config> = StorageValue<_, (BlockNumberFor<T>, BlockNumberFor<T>)>;
/// The number of changes (both in terms of keys and underlying economic responsibilities)
/// in the "set" of Grandpa validators from genesis.
@@ -429,7 +430,7 @@ impl<T: Config> Pallet<T> {
/// Schedule GRANDPA to pause starting in the given number of blocks.
/// Cannot be done when already paused.
pub fn schedule_pause(in_blocks: T::BlockNumber) -> DispatchResult {
pub fn schedule_pause(in_blocks: BlockNumberFor<T>) -> DispatchResult {
if let StoredState::Live = <State<T>>::get() {
let scheduled_at = <frame_system::Pallet<T>>::block_number();
<State<T>>::put(StoredState::PendingPause { delay: in_blocks, scheduled_at });
@@ -441,7 +442,7 @@ impl<T: Config> Pallet<T> {
}
/// Schedule a resume of GRANDPA after pausing.
pub fn schedule_resume(in_blocks: T::BlockNumber) -> DispatchResult {
pub fn schedule_resume(in_blocks: BlockNumberFor<T>) -> DispatchResult {
if let StoredState::Paused = <State<T>>::get() {
let scheduled_at = <frame_system::Pallet<T>>::block_number();
<State<T>>::put(StoredState::PendingResume { delay: in_blocks, scheduled_at });
@@ -468,8 +469,8 @@ impl<T: Config> Pallet<T> {
/// an error if a change is already pending.
pub fn schedule_change(
next_authorities: AuthorityList,
in_blocks: T::BlockNumber,
forced: Option<T::BlockNumber>,
in_blocks: BlockNumberFor<T>,
forced: Option<BlockNumberFor<T>>,
) -> DispatchResult {
if !<PendingChange<T>>::exists() {
let scheduled_at = <frame_system::Pallet<T>>::block_number();
@@ -506,7 +507,7 @@ impl<T: Config> Pallet<T> {
}
/// Deposit one of this module's logs.
fn deposit_log(log: ConsensusLog<T::BlockNumber>) {
fn deposit_log(log: ConsensusLog<BlockNumberFor<T>>) {
let log = DigestItem::Consensus(GRANDPA_ENGINE_ID, log.encode());
<frame_system::Pallet<T>>::deposit_log(log);
}
@@ -530,13 +531,13 @@ impl<T: Config> Pallet<T> {
/// will push the transaction to the pool. Only useful in an offchain
/// context.
pub fn submit_unsigned_equivocation_report(
equivocation_proof: EquivocationProof<T::Hash, T::BlockNumber>,
equivocation_proof: EquivocationProof<T::Hash, BlockNumberFor<T>>,
key_owner_proof: T::KeyOwnerProof,
) -> Option<()> {
T::EquivocationReportSystem::publish_evidence((equivocation_proof, key_owner_proof)).ok()
}
fn on_stalled(further_wait: T::BlockNumber, median: T::BlockNumber) {
fn on_stalled(further_wait: BlockNumberFor<T>, median: BlockNumberFor<T>) {
// when we record old authority sets we could try to figure out _who_
// failed. until then, we can't meaningfully guard against
// `next == last` the way that normal session changes do.
+3 -8
View File
@@ -34,20 +34,16 @@ use sp_keyring::Ed25519Keyring;
use sp_runtime::{
curve::PiecewiseLinear,
impl_opaque_keys,
testing::{Header, TestXt, UintAuthorityId},
testing::{TestXt, UintAuthorityId},
traits::{IdentityLookup, OpaqueKeys},
BuildStorage, DigestItem, Perbill,
};
use sp_staking::{EraIndex, SessionIndex};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
Authorship: pallet_authorship,
@@ -74,13 +70,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+2 -8
View File
@@ -29,19 +29,14 @@ use frame_support::{
use frame_system::{EnsureRoot, EnsureSignedBy};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
BuildStorage,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -55,13 +50,12 @@ impl frame_system::Config for Test {
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
@@ -36,7 +36,10 @@ const MAX_KEYS: u32 = 1000;
pub fn create_heartbeat<T: Config>(
k: u32,
) -> Result<
(crate::Heartbeat<T::BlockNumber>, <T::AuthorityId as RuntimeAppPublic>::Signature),
(
crate::Heartbeat<frame_system::pallet_prelude::BlockNumberFor<T>>,
<T::AuthorityId as RuntimeAppPublic>::Signature,
),
&'static str,
> {
let mut keys = Vec::new();
@@ -48,7 +51,7 @@ pub fn create_heartbeat<T: Config>(
Keys::<T>::put(bounded_keys);
let input_heartbeat = Heartbeat {
block_number: T::BlockNumber::zero(),
block_number: frame_system::pallet_prelude::BlockNumberFor::<T>::zero(),
session_index: 0,
authority_index: k - 1,
validators_len: keys.len() as u32,
+9 -9
View File
@@ -245,7 +245,7 @@ pub type IdentificationTuple<T> = (
>>::Identification,
);
type OffchainResult<T, A> = Result<A, OffchainErr<<T as frame_system::Config>::BlockNumber>>;
type OffchainResult<T, A> = Result<A, OffchainErr<BlockNumberFor<T>>>;
#[frame_support::pallet]
pub mod pallet {
@@ -287,7 +287,7 @@ pub mod pallet {
/// rough time when we should start considering sending heartbeats, since the workers
/// avoids sending them at the very beginning of the session, assuming there is a
/// chance the authority will produce a block and they won't be necessary.
type NextSessionRotation: EstimateNextSessionRotation<Self::BlockNumber>;
type NextSessionRotation: EstimateNextSessionRotation<BlockNumberFor<Self>>;
/// A type that gives us the ability to submit unresponsiveness offence reports.
type ReportUnresponsiveness: ReportOffence<
@@ -339,7 +339,7 @@ pub mod pallet {
/// more accurate then the value we calculate for `HeartbeatAfter`.
#[pallet::storage]
#[pallet::getter(fn heartbeat_after)]
pub(super) type HeartbeatAfter<T: Config> = StorageValue<_, T::BlockNumber, ValueQuery>;
pub(super) type HeartbeatAfter<T: Config> = StorageValue<_, BlockNumberFor<T>, ValueQuery>;
/// The current set of keys that may issue a heartbeat.
#[pallet::storage]
@@ -393,7 +393,7 @@ pub mod pallet {
))]
pub fn heartbeat(
origin: OriginFor<T>,
heartbeat: Heartbeat<T::BlockNumber>,
heartbeat: Heartbeat<BlockNumberFor<T>>,
// since signature verification is done in `validate_unsigned`
// we can skip doing it here again.
_signature: <T::AuthorityId as RuntimeAppPublic>::Signature,
@@ -505,7 +505,7 @@ pub mod pallet {
/// Keep track of number of authored blocks per authority, uncles are counted as
/// well since they're a valid proof of being online.
impl<T: Config + pallet_authorship::Config>
pallet_authorship::EventHandler<ValidatorId<T>, T::BlockNumber> for Pallet<T>
pallet_authorship::EventHandler<ValidatorId<T>, BlockNumberFor<T>> for Pallet<T>
{
fn note_author(author: ValidatorId<T>) {
Self::note_authorship(author);
@@ -551,7 +551,7 @@ impl<T: Config> Pallet<T> {
}
pub(crate) fn send_heartbeats(
block_number: T::BlockNumber,
block_number: BlockNumberFor<T>,
) -> OffchainResult<T, impl Iterator<Item = OffchainResult<T, ()>>> {
const START_HEARTBEAT_RANDOM_PERIOD: Permill = Permill::from_percent(10);
const START_HEARTBEAT_FINAL_PERIOD: Permill = Permill::from_percent(80);
@@ -614,7 +614,7 @@ impl<T: Config> Pallet<T> {
authority_index: u32,
key: T::AuthorityId,
session_index: SessionIndex,
block_number: T::BlockNumber,
block_number: BlockNumberFor<T>,
validators_len: u32,
) -> OffchainResult<T, ()> {
// A helper function to prepare heartbeat call.
@@ -677,7 +677,7 @@ impl<T: Config> Pallet<T> {
fn with_heartbeat_lock<R>(
authority_index: u32,
session_index: SessionIndex,
now: T::BlockNumber,
now: BlockNumberFor<T>,
f: impl FnOnce() -> OffchainResult<T, R>,
) -> OffchainResult<T, R> {
let key = {
@@ -687,7 +687,7 @@ impl<T: Config> Pallet<T> {
};
let storage = StorageValueRef::persistent(&key);
let res = storage.mutate(
|status: Result<Option<HeartbeatStatus<T::BlockNumber>>, StorageRetrievalError>| {
|status: Result<Option<HeartbeatStatus<BlockNumberFor<T>>>, StorageRetrievalError>| {
// Check if there is already a lock for that particular block.
// This means that the heartbeat has already been sent, and we are just waiting
// for it to be included. However if it doesn't get included for INCLUDE_THRESHOLD
+3 -8
View File
@@ -27,7 +27,7 @@ use frame_support::{
use pallet_session::historical as pallet_session_historical;
use sp_core::H256;
use sp_runtime::{
testing::{Header, TestXt, UintAuthorityId},
testing::{TestXt, UintAuthorityId},
traits::{BlakeTwo256, ConvertInto, IdentityLookup},
BuildStorage, Permill,
};
@@ -39,14 +39,10 @@ use sp_staking::{
use crate as imonline;
use crate::Config;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;
frame_support::construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub struct Runtime
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
@@ -124,13 +120,12 @@ impl frame_system::Config for Runtime {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+3 -8
View File
@@ -22,16 +22,12 @@
use crate::{self as pallet_indices, Config};
use frame_support::traits::{ConstU32, ConstU64};
use sp_core::H256;
use sp_runtime::{testing::Header, BuildStorage};
use sp_runtime::BuildStorage;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -47,12 +43,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = u64;
type Lookup = Indices;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -74,11 +74,12 @@ use safe_mix::TripletMix;
use codec::Encode;
use frame_support::{pallet_prelude::Weight, traits::Randomness};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_runtime::traits::{Hash, Saturating};
const RANDOM_MATERIAL_LEN: u32 = 81;
fn block_number_to_index<T: Config>(block_number: T::BlockNumber) -> usize {
fn block_number_to_index<T: Config>(block_number: BlockNumberFor<T>) -> usize {
// on_initialize is called on the first block after genesis
let index = (block_number - 1u32.into()) % RANDOM_MATERIAL_LEN.into();
index.try_into().ok().expect("Something % 81 is always smaller than usize; qed")
@@ -90,7 +91,6 @@ pub use pallet::*;
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
@@ -100,7 +100,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(block_number: T::BlockNumber) -> Weight {
fn on_initialize(block_number: BlockNumberFor<T>) -> Weight {
let parent_hash = <frame_system::Pallet<T>>::parent_hash();
<RandomMaterial<T>>::mutate(|ref mut values| {
@@ -123,7 +123,7 @@ pub mod pallet {
StorageValue<_, BoundedVec<T::Hash, ConstU32<RANDOM_MATERIAL_LEN>>, ValueQuery>;
}
impl<T: Config> Randomness<T::Hash, T::BlockNumber> for Pallet<T> {
impl<T: Config> Randomness<T::Hash, BlockNumberFor<T>> for Pallet<T> {
/// This randomness uses a low-influence function, drawing upon the block hashes from the
/// previous 81 blocks. Its result for any given subject will be known far in advance by anyone
/// observing the chain. Any block producer has significant influence over their block hashes
@@ -134,7 +134,7 @@ impl<T: Config> Randomness<T::Hash, T::BlockNumber> for Pallet<T> {
/// WARNING: Hashing the result of this function will remove any low-influence properties it has
/// and mean that all bits of the resulting value are entirely manipulatable by the author of
/// the parent block, who can determine the value of `parent_hash`.
fn random(subject: &[u8]) -> (T::Hash, T::BlockNumber) {
fn random(subject: &[u8]) -> (T::Hash, BlockNumberFor<T>) {
let block_number = <frame_system::Pallet<T>>::block_number();
let index = block_number_to_index::<T>(block_number);
@@ -164,7 +164,6 @@ mod tests {
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, Header as _, IdentityLookup},
BuildStorage,
};
@@ -175,14 +174,10 @@ mod tests {
};
use frame_system::limits;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
CollectiveFlip: pallet_insecure_randomness_collective_flip::{Pallet, Storage},
@@ -201,13 +196,12 @@ mod tests {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+5 -5
View File
@@ -142,7 +142,7 @@ pub mod pallet {
type Currency: ReservableCurrency<Self::AccountId>;
/// Something that provides randomness in the runtime.
type Randomness: Randomness<Self::Hash, Self::BlockNumber>;
type Randomness: Randomness<Self::Hash, BlockNumberFor<Self>>;
/// The overarching event type.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
@@ -208,7 +208,7 @@ pub mod pallet {
/// The configuration for the current lottery.
#[pallet::storage]
pub(crate) type Lottery<T: Config> =
StorageValue<_, LotteryConfig<T::BlockNumber, BalanceOf<T>>>;
StorageValue<_, LotteryConfig<BlockNumberFor<T>, BalanceOf<T>>>;
/// Users who have purchased a ticket. (Lottery Index, Tickets Purchased)
#[pallet::storage]
@@ -239,7 +239,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(n: T::BlockNumber) -> Weight {
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
Lottery::<T>::mutate(|mut lottery| -> Weight {
if let Some(config) = &mut lottery {
let payout_block =
@@ -350,8 +350,8 @@ pub mod pallet {
pub fn start_lottery(
origin: OriginFor<T>,
price: BalanceOf<T>,
length: T::BlockNumber,
delay: T::BlockNumber,
length: BlockNumberFor<T>,
delay: BlockNumberFor<T>,
repeat: bool,
) -> DispatchResult {
T::ManagerOrigin::ensure_origin(origin)?;
+2 -8
View File
@@ -28,19 +28,14 @@ use frame_support_test::TestRandomness;
use frame_system::EnsureRoot;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage, Perbill,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -60,12 +55,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type RuntimeCall = RuntimeCall;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+2 -8
View File
@@ -525,7 +525,6 @@ mod tests {
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BadOrigin, BlakeTwo256, IdentityLookup},
BuildStorage,
};
@@ -536,14 +535,10 @@ mod tests {
};
use frame_system::EnsureSignedBy;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Membership: pallet_membership::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -562,13 +557,12 @@ mod tests {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -57,6 +57,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
use frame_support::{log, weights::Weight};
use frame_system::pallet_prelude::{BlockNumberFor, HeaderFor};
use sp_mmr_primitives::utils;
use sp_runtime::{
traits::{self, One, Saturating},
@@ -91,7 +92,7 @@ pub struct ParentNumberAndHash<T: frame_system::Config> {
}
impl<T: frame_system::Config> LeafDataProvider for ParentNumberAndHash<T> {
type LeafData = (<T as frame_system::Config>::BlockNumber, <T as frame_system::Config>::Hash);
type LeafData = (BlockNumberFor<T>, <T as frame_system::Config>::Hash);
fn leaf_data() -> Self::LeafData {
(
@@ -120,7 +121,6 @@ pub(crate) type HashOf<T, I> = <<T as Config<I>>::Hashing as traits::Hash>::Outp
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
@@ -201,7 +201,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
fn on_initialize(_n: T::BlockNumber) -> Weight {
fn on_initialize(_n: BlockNumberFor<T>) -> Weight {
use primitives::LeafDataProvider;
let leaves = Self::mmr_leaves();
let peaks_before = sp_mmr_primitives::utils::NodesUtils::new(leaves).number_of_peaks();
@@ -266,11 +266,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
pos: NodeIndex,
parent_hash: <T as frame_system::Config>::Hash,
) -> sp_std::prelude::Vec<u8> {
NodesUtils::node_temp_offchain_key::<<T as frame_system::Config>::Header>(
&T::INDEXING_PREFIX,
pos,
parent_hash,
)
NodesUtils::node_temp_offchain_key::<HeaderFor<T>>(&T::INDEXING_PREFIX, pos, parent_hash)
}
/// Build canonical offchain key for node `pos` in MMR.
@@ -286,7 +282,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
fn leaf_index_to_parent_block_num(
leaf_index: LeafIndex,
leaves_count: LeafIndex,
) -> <T as frame_system::Config>::BlockNumber {
) -> BlockNumberFor<T> {
// leaves are zero-indexed and were added one per block since pallet activation,
// while block numbers are one-indexed, so block number that added `leaf_idx` is:
// `block_num = block_num_when_pallet_activated + leaf_idx + 1`
@@ -298,16 +294,16 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}
/// Convert a block number into a leaf index.
fn block_num_to_leaf_index(block_num: T::BlockNumber) -> Result<LeafIndex, Error>
fn block_num_to_leaf_index(block_num: BlockNumberFor<T>) -> Result<LeafIndex, Error>
where
T: frame_system::Config,
{
let first_mmr_block = utils::first_mmr_block_num::<T::Header>(
let first_mmr_block = utils::first_mmr_block_num::<HeaderFor<T>>(
<frame_system::Pallet<T>>::block_number(),
Self::mmr_leaves(),
)?;
utils::block_num_to_leaf_index::<T::Header>(block_num, first_mmr_block)
utils::block_num_to_leaf_index::<HeaderFor<T>>(block_num, first_mmr_block)
}
/// Generate an MMR proof for the given `block_numbers`.
@@ -320,8 +316,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// all the leaves to be present.
/// It may return an error or panic if used incorrectly.
pub fn generate_proof(
block_numbers: Vec<T::BlockNumber>,
best_known_block_number: Option<T::BlockNumber>,
block_numbers: Vec<BlockNumberFor<T>>,
best_known_block_number: Option<BlockNumberFor<T>>,
) -> Result<(Vec<LeafOf<T, I>>, primitives::Proof<HashOf<T, I>>), primitives::Error> {
// check whether best_known_block_number provided, else use current best block
let best_known_block_number =
@@ -25,19 +25,12 @@ use frame_support::{
};
use sp_core::H256;
use sp_mmr_primitives::{Compact, LeafDataProvider};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup, Keccak256},
};
use sp_runtime::traits::{BlakeTwo256, IdentityLookup, Keccak256};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
MMR: pallet_mmr::{Pallet, Storage},
@@ -49,12 +42,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = sp_core::sr25519::Public;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
@@ -54,7 +54,7 @@ pub(crate) fn hex(s: &str) -> H256 {
s.parse().unwrap()
}
type BlockNumber = <Test as frame_system::Config>::BlockNumber;
type BlockNumber = frame_system::pallet_prelude::BlockNumberFor<Test>;
fn decode_node(
v: Vec<u8>,
@@ -37,20 +37,13 @@ use frame_support::{
use rand::{rngs::StdRng, Rng, SeedableRng};
use rand_distr::Pareto;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use std::collections::{BTreeMap, BTreeSet};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event<T>},
@@ -64,13 +57,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
+3 -9
View File
@@ -29,20 +29,15 @@ use frame_support::{
};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
use sp_std::collections::btree_map::BTreeMap;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event<T>},
@@ -55,13 +50,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -289,7 +283,7 @@ impl QueuePausedQuery<MessageOrigin> for MockedQueuePauser {
/// Is generic since it is used by the unit test, integration tests and benchmarks.
pub fn new_test_ext<T: Config>() -> sp_io::TestExternalities
where
<T as frame_system::Config>::BlockNumber: From<u32>,
frame_system::pallet_prelude::BlockNumberFor<T>: From<u32>,
{
sp_tracing::try_init_simple();
WeightForCall::take();
+10 -10
View File
@@ -59,7 +59,7 @@ use frame_support::{
weights::Weight,
BoundedVec, RuntimeDebug,
};
use frame_system::{self as system, RawOrigin};
use frame_system::{self as system, pallet_prelude::BlockNumberFor, RawOrigin};
use scale_info::TypeInfo;
use sp_io::hashing::blake2_256;
use sp_runtime::{
@@ -183,7 +183,7 @@ pub mod pallet {
T::AccountId,
Blake2_128Concat,
[u8; 32],
Multisig<T::BlockNumber, BalanceOf<T>, T::AccountId, T::MaxSignatories>,
Multisig<BlockNumberFor<T>, BalanceOf<T>, T::AccountId, T::MaxSignatories>,
>;
#[pallet::error]
@@ -226,14 +226,14 @@ pub mod pallet {
/// A multisig operation has been approved by someone.
MultisigApproval {
approving: T::AccountId,
timepoint: Timepoint<T::BlockNumber>,
timepoint: Timepoint<BlockNumberFor<T>>,
multisig: T::AccountId,
call_hash: CallHash,
},
/// A multisig operation has been executed.
MultisigExecuted {
approving: T::AccountId,
timepoint: Timepoint<T::BlockNumber>,
timepoint: Timepoint<BlockNumberFor<T>>,
multisig: T::AccountId,
call_hash: CallHash,
result: DispatchResult,
@@ -241,7 +241,7 @@ pub mod pallet {
/// A multisig operation has been cancelled.
MultisigCancelled {
cancelling: T::AccountId,
timepoint: Timepoint<T::BlockNumber>,
timepoint: Timepoint<BlockNumberFor<T>>,
multisig: T::AccountId,
call_hash: CallHash,
},
@@ -366,7 +366,7 @@ pub mod pallet {
origin: OriginFor<T>,
threshold: u16,
other_signatories: Vec<T::AccountId>,
maybe_timepoint: Option<Timepoint<T::BlockNumber>>,
maybe_timepoint: Option<Timepoint<BlockNumberFor<T>>>,
call: Box<<T as Config>::RuntimeCall>,
max_weight: Weight,
) -> DispatchResultWithPostInfo {
@@ -423,7 +423,7 @@ pub mod pallet {
origin: OriginFor<T>,
threshold: u16,
other_signatories: Vec<T::AccountId>,
maybe_timepoint: Option<Timepoint<T::BlockNumber>>,
maybe_timepoint: Option<Timepoint<BlockNumberFor<T>>>,
call_hash: [u8; 32],
max_weight: Weight,
) -> DispatchResultWithPostInfo {
@@ -465,7 +465,7 @@ pub mod pallet {
origin: OriginFor<T>,
threshold: u16,
other_signatories: Vec<T::AccountId>,
timepoint: Timepoint<T::BlockNumber>,
timepoint: Timepoint<BlockNumberFor<T>>,
call_hash: [u8; 32],
) -> DispatchResult {
let who = ensure_signed(origin)?;
@@ -511,7 +511,7 @@ impl<T: Config> Pallet<T> {
who: T::AccountId,
threshold: u16,
other_signatories: Vec<T::AccountId>,
maybe_timepoint: Option<Timepoint<T::BlockNumber>>,
maybe_timepoint: Option<Timepoint<BlockNumberFor<T>>>,
call_or_hash: CallOrHash<T>,
max_weight: Weight,
) -> DispatchResultWithPostInfo {
@@ -637,7 +637,7 @@ impl<T: Config> Pallet<T> {
}
/// The current `Timepoint`.
pub fn timepoint() -> Timepoint<T::BlockNumber> {
pub fn timepoint() -> Timepoint<BlockNumberFor<T>> {
Timepoint {
height: <system::Pallet<T>>::block_number(),
index: <system::Pallet<T>>::extrinsic_index().unwrap_or_default(),
+2 -8
View File
@@ -28,19 +28,14 @@ use frame_support::{
};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
BuildStorage, TokenError,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -55,13 +50,12 @@ impl frame_system::Config for Test {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
@@ -29,7 +29,7 @@ use frame_support::{
Get,
},
};
use frame_system::RawOrigin as SystemOrigin;
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin as SystemOrigin};
use pallet_nfts::{CollectionConfig, CollectionSettings, ItemConfig, MintSettings};
use sp_runtime::traits::StaticLookup;
use sp_std::prelude::*;
@@ -39,11 +39,8 @@ use crate::Pallet as NftFractionalization;
type BalanceOf<T> =
<<T as Config>::Currency as InspectFungible<<T as SystemConfig>::AccountId>>::Balance;
type CollectionConfigOf<T> = CollectionConfig<
BalanceOf<T>,
<T as SystemConfig>::BlockNumber,
<T as Config>::NftCollectionId,
>;
type CollectionConfigOf<T> =
CollectionConfig<BalanceOf<T>, BlockNumberFor<T>, <T as Config>::NftCollectionId>;
fn default_collection_config<T: Config>() -> CollectionConfigOf<T>
where
@@ -58,7 +55,7 @@ where
fn mint_nft<T: Config>(nft_id: T::NftId) -> (T::AccountId, AccountIdLookupOf<T>)
where
T::Nfts: Create<T::AccountId, CollectionConfig<BalanceOf<T>, T::BlockNumber, T::NftCollectionId>>
T::Nfts: Create<T::AccountId, CollectionConfig<BalanceOf<T>, BlockNumberFor<T>, T::NftCollectionId>>
+ Mutate<T::AccountId, ItemConfig>,
{
let caller: T::AccountId = whitelisted_caller();
@@ -84,7 +81,7 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
benchmarks! {
where_clause {
where
T::Nfts: Create<T::AccountId, CollectionConfig<BalanceOf<T>, T::BlockNumber, T::NftCollectionId>>
T::Nfts: Create<T::AccountId, CollectionConfig<BalanceOf<T>, frame_system::pallet_prelude::BlockNumberFor::<T>, T::NftCollectionId>>
+ Mutate<T::AccountId, ItemConfig>,
}
@@ -29,12 +29,10 @@ use frame_system::EnsureSigned;
use pallet_nfts::PalletFeatures;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
BuildStorage, MultiSignature,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type Signature = MultiSignature;
type AccountPublic = <Signature as Verify>::Signer;
@@ -42,10 +40,7 @@ type AccountId = <AccountPublic as IdentifyAccount>::AccountId;
// Configure a mock runtime to test the pallet.
construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
NftFractionalization: pallet_nft_fractionalization,
@@ -61,12 +56,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
+4 -4
View File
@@ -30,7 +30,7 @@ use frame_support::{
traits::{EnsureOrigin, Get},
BoundedVec,
};
use frame_system::RawOrigin as SystemOrigin;
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin as SystemOrigin};
use sp_io::crypto::{sr25519_generate, sr25519_sign};
use sp_runtime::{
traits::{Bounded, IdentifyAccount, One},
@@ -589,7 +589,7 @@ benchmarks_instance_pallet! {
let (item, ..) = mint_item::<T, I>(0);
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let deadline = T::BlockNumber::max_value();
let deadline = BlockNumberFor::<T>::max_value();
}: _(SystemOrigin::Signed(caller.clone()), collection, item, delegate_lookup, Some(deadline))
verify {
assert_last_event::<T, I>(Event::TransferApproved { collection, item, owner: caller, delegate, deadline: Some(deadline) }.into());
@@ -601,7 +601,7 @@ benchmarks_instance_pallet! {
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let origin = SystemOrigin::Signed(caller.clone()).into();
let deadline = T::BlockNumber::max_value();
let deadline = BlockNumberFor::<T>::max_value();
Nfts::<T, I>::approve_transfer(origin, collection, item, delegate_lookup.clone(), Some(deadline))?;
}: _(SystemOrigin::Signed(caller.clone()), collection, item, delegate_lookup)
verify {
@@ -614,7 +614,7 @@ benchmarks_instance_pallet! {
let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let origin = SystemOrigin::Signed(caller.clone()).into();
let deadline = T::BlockNumber::max_value();
let deadline = BlockNumberFor::<T>::max_value();
Nfts::<T, I>::approve_transfer(origin, collection, item, delegate_lookup.clone(), Some(deadline))?;
}: _(SystemOrigin::Signed(caller.clone()), collection, item)
verify {

Some files were not shown because too many files have changed in this diff Show More