diff --git a/crates/subspace-runtime-primitives/src/utility.rs b/crates/subspace-runtime-primitives/src/utility.rs index b509660fd3..e84b4f4768 100644 --- a/crates/subspace-runtime-primitives/src/utility.rs +++ b/crates/subspace-runtime-primitives/src/utility.rs @@ -1,7 +1,10 @@ //! Runtime primitives for pallet-utility. +use core::marker::PhantomData; +use frame_support::pallet_prelude::TypeInfo; use frame_system::pallet_prelude::RuntimeCallFor; use scale_info::prelude::collections::VecDeque; +use sp_runtime::traits::{BlockNumberProvider, Get}; /// Trait used to convert from a generated `RuntimeCall` type to `pallet_utility::Call`. pub trait MaybeIntoUtilityCall @@ -52,3 +55,15 @@ where Some(call) }) } + +// `DefaultNonceProvider` uses the current block number as the nonce of the new account, +// this is used to prevent the replay attack see https://wiki.polkadot.network/docs/transaction-attacks#replay-attack +// for more detail. +#[derive(Debug, TypeInfo)] +pub struct DefaultNonceProvider(PhantomData<(T, N)>); + +impl> Get for DefaultNonceProvider { + fn get() -> N { + T::current_block_number() + } +} diff --git a/domains/runtime/auto-id/src/lib.rs b/domains/runtime/auto-id/src/lib.rs index f0cae00cc9..4d66e0f57b 100644 --- a/domains/runtime/auto-id/src/lib.rs +++ b/domains/runtime/auto-id/src/lib.rs @@ -68,6 +68,7 @@ use sp_subspace_mmr::domain_mmr_runtime_interface::{ use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrLeaf}; use sp_version::RuntimeVersion; use static_assertions::const_assert; +use subspace_runtime_primitives::utility::DefaultNonceProvider; use subspace_runtime_primitives::{ BlockNumber as ConsensusBlockNumber, Hash as ConsensusBlockHash, Moment, SlowAdjustingFeeUpdate, SHANNON, SSC, @@ -139,18 +140,6 @@ parameter_types! { pub RuntimeBlockWeights: BlockWeights = block_weights(); } -// `DefaultNonceProvider` uses the current block number as the nonce of the new account, -// this is used to prevent the replay attack see https://wiki.polkadot.network/docs/transaction-attacks#replay-attack -// for more detail. -#[derive(Debug, TypeInfo)] -pub struct DefaultNonceProvider; - -impl Get for DefaultNonceProvider { - fn get() -> Nonce { - System::block_number() - } -} - impl frame_system::Config for Runtime { /// The identifier used to distinguish between accounts. type AccountId = AccountId; @@ -161,7 +150,7 @@ impl frame_system::Config for Runtime { /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The type for storing how many extrinsics an account has signed. - type Nonce = TypeWithDefault; + type Nonce = TypeWithDefault>; /// The type for hashing blocks and tries. type Hash = Hash; /// The hashing algorithm used. diff --git a/domains/runtime/evm/src/lib.rs b/domains/runtime/evm/src/lib.rs index da09ab644b..907dd6cf14 100644 --- a/domains/runtime/evm/src/lib.rs +++ b/domains/runtime/evm/src/lib.rs @@ -91,7 +91,7 @@ use sp_subspace_mmr::domain_mmr_runtime_interface::{ use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrLeaf}; use sp_version::RuntimeVersion; use static_assertions::const_assert; -use subspace_runtime_primitives::utility::MaybeIntoUtilityCall; +use subspace_runtime_primitives::utility::{DefaultNonceProvider, MaybeIntoUtilityCall}; use subspace_runtime_primitives::{ BlockNumber as ConsensusBlockNumber, Hash as ConsensusBlockHash, Moment, SlowAdjustingFeeUpdate, SHANNON, SSC, @@ -317,18 +317,6 @@ parameter_types! { pub RuntimeBlockWeights: BlockWeights = block_weights(); } -// `DefaultNonceProvider` uses the current block number as the nonce of the new account, -// this is used to prevent the replay attack see https://wiki.polkadot.network/docs/transaction-attacks#replay-attack -// for more detail. -#[derive(Debug, TypeInfo)] -pub struct DefaultNonceProvider; - -impl Get for DefaultNonceProvider { - fn get() -> Nonce { - System::block_number() - } -} - impl frame_system::Config for Runtime { /// The identifier used to distinguish between accounts. type AccountId = AccountId; @@ -339,7 +327,7 @@ impl frame_system::Config for Runtime { /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = IdentityLookup; /// The type for storing how many extrinsics an account has signed. - type Nonce = TypeWithDefault; + type Nonce = TypeWithDefault>; /// The type for hashing blocks and tries. type Hash = Hash; /// The hashing algorithm used. diff --git a/domains/test/runtime/auto-id/src/lib.rs b/domains/test/runtime/auto-id/src/lib.rs index a328abe9b0..3194cffa85 100644 --- a/domains/test/runtime/auto-id/src/lib.rs +++ b/domains/test/runtime/auto-id/src/lib.rs @@ -68,6 +68,7 @@ use sp_subspace_mmr::domain_mmr_runtime_interface::{ use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrLeaf}; use sp_version::RuntimeVersion; use static_assertions::const_assert; +use subspace_runtime_primitives::utility::DefaultNonceProvider; use subspace_runtime_primitives::{ BlockNumber as ConsensusBlockNumber, Hash as ConsensusBlockHash, Moment, SlowAdjustingFeeUpdate, SSC, @@ -137,18 +138,6 @@ parameter_types! { pub RuntimeBlockWeights: BlockWeights = block_weights(); } -// `DefaultNonceProvider` uses the current block number as the nonce of the new account, -// this is used to prevent the replay attack see https://wiki.polkadot.network/docs/transaction-attacks#replay-attack -// for more detail. -#[derive(Debug, TypeInfo)] -pub struct DefaultNonceProvider; - -impl Get for DefaultNonceProvider { - fn get() -> Nonce { - System::block_number() - } -} - impl frame_system::Config for Runtime { /// The identifier used to distinguish between accounts. type AccountId = AccountId; @@ -159,7 +148,7 @@ impl frame_system::Config for Runtime { /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The type for storing how many extrinsics an account has signed. - type Nonce = TypeWithDefault; + type Nonce = TypeWithDefault>; /// The type for hashing blocks and tries. type Hash = Hash; /// The hashing algorithm used. diff --git a/domains/test/runtime/evm/src/lib.rs b/domains/test/runtime/evm/src/lib.rs index f3e1d8e2fc..45b4bbb7e7 100644 --- a/domains/test/runtime/evm/src/lib.rs +++ b/domains/test/runtime/evm/src/lib.rs @@ -90,7 +90,7 @@ use sp_subspace_mmr::domain_mmr_runtime_interface::{ use sp_subspace_mmr::{ConsensusChainMmrLeafProof, MmrLeaf}; use sp_version::RuntimeVersion; use static_assertions::const_assert; -use subspace_runtime_primitives::utility::MaybeIntoUtilityCall; +use subspace_runtime_primitives::utility::{DefaultNonceProvider, MaybeIntoUtilityCall}; use subspace_runtime_primitives::{ BlockNumber as ConsensusBlockNumber, Hash as ConsensusBlockHash, Moment, SHANNON, SSC, }; @@ -369,18 +369,6 @@ parameter_types! { pub RuntimeBlockWeights: BlockWeights = block_weights(); } -// `DefaultNonceProvider` uses the current block number as the nonce of the new account, -// this is used to prevent the replay attack see https://wiki.polkadot.network/docs/transaction-attacks#replay-attack -// for more detail. -#[derive(Debug, TypeInfo)] -pub struct DefaultNonceProvider; - -impl Get for DefaultNonceProvider { - fn get() -> Nonce { - System::block_number() - } -} - impl frame_system::Config for Runtime { /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; @@ -397,7 +385,7 @@ impl frame_system::Config for Runtime { /// The aggregated `RuntimeTask` type. type RuntimeTask = RuntimeTask; /// The type for storing how many extrinsics an account has signed. - type Nonce = TypeWithDefault; + type Nonce = TypeWithDefault>; /// The type for hashing blocks and tries. type Hash = Hash; /// The hashing algorithm used. diff --git a/test/subspace-test-runtime/src/lib.rs b/test/subspace-test-runtime/src/lib.rs index f2a4432d86..440f7ec917 100644 --- a/test/subspace-test-runtime/src/lib.rs +++ b/test/subspace-test-runtime/src/lib.rs @@ -107,6 +107,7 @@ use subspace_core_primitives::segments::{ }; use subspace_core_primitives::solutions::SolutionRange; use subspace_core_primitives::{hashes, PublicKey, Randomness, SlotNumber, U256}; +use subspace_runtime_primitives::utility::DefaultNonceProvider; use subspace_runtime_primitives::{ AccountId, Balance, BlockNumber, FindBlockRewardAddress, Hash, HoldIdentifier, Moment, Nonce, Signature, MIN_REPLICATION_FACTOR, SHANNON, SSC, @@ -216,18 +217,6 @@ parameter_types! { pub type SS58Prefix = ConstU16<6094>; -// `DefaultNonceProvider` uses the current block number as the nonce of the new account, -// this is used to prevent the replay attack see https://wiki.polkadot.network/docs/transaction-attacks#replay-attack -// for more detail. -#[derive(Debug, TypeInfo)] -pub struct DefaultNonceProvider; - -impl Get for DefaultNonceProvider { - fn get() -> Nonce { - System::block_number() - } -} - // Configure FRAME pallets to include in runtime. impl frame_system::Config for Runtime { @@ -246,7 +235,7 @@ impl frame_system::Config for Runtime { /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The type for storing how many extrinsics an account has signed. - type Nonce = TypeWithDefault; + type Nonce = TypeWithDefault>; /// The type for hashing blocks and tries. type Hash = Hash; /// The hashing algorithm used.