-
Notifications
You must be signed in to change notification settings - Fork 707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds ability to configure default nonce #1557
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2ef967f
Use block number as nonce
ggwpez 2c33657
Fixes build
gupnik 526d20b
Adds test
gupnik f496aab
Updates test
gupnik 644b48d
Uses TryFrom
gupnik 0dbac97
Fixes test
gupnik 0444b78
Fixes another test
gupnik 010f783
Fixes another test
gupnik f7adbe3
Merge branch 'master' of github.com:paritytech/polkadot-sdk into oty-…
gupnik 8db0ef7
Adds ability to configure default nonce
gupnik 7042186
Adds PrDoc
gupnik 624e983
Fmt
gupnik 98e20ed
Adds derive_impl in missing places
gupnik 7b4feec
Fixes typo
gupnik 0cca9b6
Apply suggestions from code review
kianenigma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
title: Adds ability to configure default account nonce | ||
|
||
doc: | ||
- audience: Runtime Dev | ||
description: | | ||
Introduces the ability to configure the default nonce. This will also be used if the account is reaped. | ||
By default, the current behaviour is maintained and nonce starts from 0. | ||
|
||
migrations: | ||
db: [] | ||
|
||
runtime: [] | ||
|
||
crates: | ||
- name: frame-system | ||
|
||
host_functions: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -298,6 +298,7 @@ pub mod pallet { | |||||||
type BaseCallFilter = frame_support::traits::Everything; | ||||||||
type BlockHashCount = frame_support::traits::ConstU64<10>; | ||||||||
type OnSetCode = (); | ||||||||
type DefaultNonce = (); | ||||||||
} | ||||||||
|
||||||||
/// Default configurations of this pallet in a solo-chain environment. | ||||||||
|
@@ -392,6 +393,9 @@ pub mod pallet { | |||||||
|
||||||||
/// The set code logic, just the default since we're not a parachain. | ||||||||
type OnSetCode = (); | ||||||||
|
||||||||
/// The default nonce when an account is created. | ||||||||
type DefaultNonce = (); | ||||||||
} | ||||||||
|
||||||||
/// Default configurations of this pallet in a relay-chain environment. | ||||||||
|
@@ -463,6 +467,7 @@ pub mod pallet { | |||||||
type RuntimeTask: Task; | ||||||||
|
||||||||
/// This stores the number of previous transactions associated with a sender account. | ||||||||
#[pallet::no_default_bounds] | ||||||||
type Nonce: Parameter | ||||||||
+ Member | ||||||||
+ MaybeSerializeDeserialize | ||||||||
|
@@ -570,6 +575,9 @@ pub mod pallet { | |||||||
|
||||||||
/// The maximum number of consumers allowed on a single account. | ||||||||
type MaxConsumers: ConsumerLimits; | ||||||||
|
||||||||
/// The default nonce when an account is created. | ||||||||
type DefaultNonce: Get<Self::Nonce>; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentionally not a |
||||||||
} | ||||||||
|
||||||||
#[pallet::pallet] | ||||||||
|
@@ -837,6 +845,7 @@ pub mod pallet { | |||||||
T::AccountId, | ||||||||
AccountInfo<T::Nonce, T::AccountData>, | ||||||||
ValueQuery, | ||||||||
GetDefaultAccountInfo<T>, | ||||||||
>; | ||||||||
|
||||||||
/// Total extrinsics count for the current block. | ||||||||
|
@@ -1036,7 +1045,10 @@ pub type RefCount = u32; | |||||||
/// Information of an account. | ||||||||
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)] | ||||||||
pub struct AccountInfo<Nonce, AccountData> { | ||||||||
/// The number of transactions this account has sent. | ||||||||
/// A value that increases with every transaction that the account has sent. | ||||||||
/// | ||||||||
/// Gets reset when the account gets reaped and is initialized to the default nonce as provided | ||||||||
/// in the config. | ||||||||
pub nonce: Nonce, | ||||||||
/// The number of other modules that currently depend on this account's existence. The account | ||||||||
/// cannot be reaped until this is zero. | ||||||||
|
@@ -1052,6 +1064,17 @@ pub struct AccountInfo<Nonce, AccountData> { | |||||||
pub data: AccountData, | ||||||||
} | ||||||||
|
||||||||
type NonceOf<T> = <T as Config>::Nonce; | ||||||||
type AccountDataOf<T> = <T as Config>::AccountData; | ||||||||
type AccountInfoOf<T> = AccountInfo<NonceOf<T>, AccountDataOf<T>>; | ||||||||
|
||||||||
pub struct GetDefaultAccountInfo<T>(PhantomData<T>); | ||||||||
gupnik marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
impl<T: pallet::Config> Get<AccountInfoOf<T>> for GetDefaultAccountInfo<T> { | ||||||||
fn get() -> AccountInfoOf<T> { | ||||||||
AccountInfo { nonce: T::DefaultNonce::get(), ..Default::default() } | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
/// Stores the `spec_version` and `spec_name` of when the last runtime upgrade | ||||||||
/// happened. | ||||||||
#[derive(sp_runtime::RuntimeDebug, Encode, Decode, TypeInfo)] | ||||||||
|
@@ -1909,7 +1932,7 @@ impl<T: Config> Pallet<T> { | |||||||
|
||||||||
/// Increment a particular account's nonce by 1. | ||||||||
pub fn inc_account_nonce(who: impl EncodeLike<T::AccountId>) { | ||||||||
Account::<T>::mutate(who, |a| a.nonce += T::Nonce::one()); | ||||||||
Account::<T>::mutate(who, |a| a.nonce.saturating_inc()); | ||||||||
} | ||||||||
|
||||||||
/// Note what the extrinsic data of the current extrinsic index is. | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now there are two notations of default, once from the
Default
bound here, and one from theDefaultNonce
.