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

Remove Index type from Config trait #1074

Merged
merged 7 commits into from
Jul 20, 2023

Conversation

tadeohepperle
Copy link
Contributor

@tadeohepperle tadeohepperle commented Jul 17, 2023

fixes #1061

Whereever we previously required a Config::Index, now any type that implements Into<u64> can be used.

@tadeohepperle tadeohepperle marked this pull request as ready for review July 18, 2023 14:42
@tadeohepperle tadeohepperle requested a review from a team as a code owner July 18, 2023 14:42
@@ -27,7 +27,7 @@ pub trait ExtrinsicParams<Index, Hash>: Debug + 'static {
fn new(
spec_version: u32,
tx_version: u32,
nonce: Index,
nonce: impl Into<u64>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd keep this simple and just have it take a concrete u64; it's only called internally anyway, and so let's avoid extra generics unless they make the API more ergonomic for users :)

@jsdw
Copy link
Collaborator

jsdw commented Jul 19, 2023

Looks good to me! I'd just remove the impl Into<u64> generics (it's easy for a user to provide a u64 off the bat; I don't see the point of making it generic really :))

Did you double check that the signed extension itself always wants a u64? That's the one wrinkle that might complicate things a touch!

@jsdw
Copy link
Collaborator

jsdw commented Jul 19, 2023

Ah, a wrinkle! I had a look at the CheckNonce signed extension impl:

pub struct CheckNonce<T: Config>(#[codec(compact)] pub T::Index);

impl<T: Config> CheckNonce<T> {
	/// utility constructor. Used only in client/factory code.
	pub fn from(nonce: T::Index) -> Self {
		Self(nonce)
	}
}

Ie the nonce type is whatever the Index type is, and isn't necessarily a u64!

This means that we would indeed have to use the metadata to find out the size of the Index type in the CheckNonce signed extension in order to actually remove this param (which I think is what you originally were looking to do, so apologies for the misdirection there!!)

@jsdw
Copy link
Collaborator

jsdw commented Jul 20, 2023

Scrap that; @tadeohepperle pointed out that the nonce type is compact encoded in the signed extension, and so it's irrelevant what numeric type it actually is, so we're still good :)

tadeohepperle and others added 3 commits July 20, 2023 14:46
* practice TDD

* implement a hashmap 2-phases approach

* use nicer types

* add test for cache filling

* adjust test

---------

Co-authored-by: James Wilson <james@jsdw.me>
@@ -138,7 +138,7 @@
//! // here, or can use `create_partial_signed` to fetch the correct nonce.
//! let partial_tx = client.tx().create_partial_signed_with_nonce(
//! &payload,
//! 0,
//! 0u64,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: no more u64 type needed now :)

Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

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

Looks great!

@tadeohepperle tadeohepperle merged commit c2875de into master Jul 20, 2023
7 checks passed
@tadeohepperle tadeohepperle deleted the tadeo-hepperle-remove-index-from-config branch July 20, 2023 13:13
@jsdw jsdw mentioned this pull request Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config: Remove Index param
3 participants