Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to configure default nonce #1557

Closed
wants to merge 15 commits into from
Closed

Conversation

gupnik
Copy link
Contributor

@gupnik gupnik commented Sep 14, 2023

Fixes https://github.com/paritytech-secops/srlabs_findings/issues/35, closes #326

This PR 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.

@gupnik gupnik added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Sep 14, 2023
@gupnik gupnik requested review from a team September 14, 2023 05:24
@h4x3rotab
Copy link

Why using the block number as the start point of the nonce? If it's used to prevent nonce reset after the account is reaped, then it makes more sense to use the timestample or some larger number. After all, the nonce can be higher than the block number theoretically.

substrate/frame/system/src/lib.rs Show resolved Hide resolved
substrate/frame/system/src/lib.rs Outdated Show resolved Hide resolved
@xlc
Copy link
Contributor

xlc commented Sep 14, 2023

Oh and make sure you still have tests to ensure the original behaivour is not impacted. Again, not everyone are going to use this and it is essential to the old functionality remains the same and working.

@ggwpez
Copy link
Member

ggwpez commented Sep 14, 2023

After all, the nonce can be higher than the block number theoretically.

Sure it could in theory, but this is a best effort approach that should prevent the most likely occurrences.

@gupnik
Copy link
Contributor Author

gupnik commented Sep 27, 2023

@ggwpez @kianenigma Can we proceed with this? Haven't heard from @xlc yet on why someone would opt not to use this. Unless we see a clear benefit, I don't think it's worth maintaining this optionality.

@xlc
Copy link
Contributor

xlc commented Sep 27, 2023

Please. I don't know why I even need to give you a reason to ask you to not force a breaking change to EVERYONE. Ok, here is one: EVM compatibility.

@gupnik
Copy link
Contributor Author

gupnik commented Sep 28, 2023

Please. I don't know why I even need to give you a reason to ask you to not force a breaking change to EVERYONE. Ok, here is one: EVM compatibility.

This is helpful. Thanks!

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this configurable through frame_system so you can express how you wish new account nonces to be created.

@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 2, 2024 06:07
@gupnik gupnik changed the title Starts nonce from the current block number Adds ability to configure default nonce Jan 2, 2024
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-clippy
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/4824508

@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 2, 2024 06:31
Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just now realize that we can already do this: type Nonce: Default allows us to already set a non-zero nonce upon creation - entirely without this merge request 🙈
But i guess since we often use types like u32, it would not be possible to implement another Default for it, so it should be fine.

prdoc/pr_1557.prdoc Outdated Show resolved Hide resolved
@@ -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>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentionally not a #[pallet::constant]?

type AccountDataOf<T> = <T as Config>::AccountData;
type AccountInfoOf<T> = AccountInfo<NonceOf<T>, AccountDataOf<T>>;

pub struct GetDefaultAccountInfo<T>(PhantomData<T>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub struct GetDefaultAccountInfo<T>(PhantomData<T>);
/// Provides the `Default` for value an account that does not yet exist.
pub struct GetDefaultAccountInfo<T>(PhantomData<T>);

@@ -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]
Copy link
Member

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 the DefaultNonce.

Co-authored-by: Oliver Tale-Yazdi <[email protected]>
kianenigma
kianenigma previously approved these changes Jan 15, 2024
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @ggwpez said the Default is already pretty flexible, with a newtype that implements Deref { Target = u32 } it might be possibly without any breaking changes? If it works it seems much superior in terms of code design to me.

If not it looks good, but I expect to see system+relay chains to start using this. It is a good idea to expose a standard SetDefaultNonceToBlockNumber for them all to use.

@kianenigma kianenigma dismissed their stale review January 15, 2024 05:30

will re-approve once alternative approach is explored.

@kianenigma
Copy link
Contributor

@gupnik can we revive this one? 🙈 💀

@gupnik
Copy link
Contributor Author

gupnik commented Apr 1, 2024

@gupnik can we revive this one? 🙈 💀

Thanks for the reminder. It's in my backlog but unable to get to it yet. Will revive this soon.

@ggwpez
Copy link
Member

ggwpez commented Apr 1, 2024

We dont actually need this, see polkadot-fellows/runtimes#248

@gupnik
Copy link
Contributor Author

gupnik commented Apr 2, 2024

We dont actually need this, see polkadot-fellows/runtimes#248

Thanks. Closing this one.

@gupnik gupnik closed this Apr 2, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 10, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 10, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
bkchr pushed a commit that referenced this pull request Apr 10, 2024
* Unnecessary clone

* Removed unused Enum value

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone

* Client - ConnectionParams wrapped with Arc + removed unnecessery clone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Initialize New Accounts with Nonce Equal to Block Number
7 participants