-
Notifications
You must be signed in to change notification settings - Fork 47
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
refactor: enforce no runtime in pallet #349
Conversation
@@ -177,7 +177,7 @@ pub trait DidVerifiableIdentifier { | |||
) -> Result<DidVerificationKey, SignatureError>; | |||
} | |||
|
|||
impl DidVerifiableIdentifier for runtime_common::DidIdentifier { | |||
impl<I: AsRef<[u8; 32]>> DidVerifiableIdentifier for I { |
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.
I'm up for better solution. This was the first thing that came to my mind. But it's definitely not the best solution since not every 32 Byte array is a DidVerifiableIdentifier. 🤔 On the other hand why not? You could try it on anything that is somehow a 32 Byte array.
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.
Can't we use the same trait requirements that the pallet requires?
type DidIdentifier: Parameter + DidVerifiableIdentifier + MaxEncodedLen;
Or if we want to be even more general, just taking whatever is needed from the Parameter
type.
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.
For the implementation the requirement I: AsRef<[u8; 32]>
should be enough. But I would like to limit it to the actual type that is the DidIdentifier
and not just all things that can be referenced as a [u8; 32]
. Which is also an AccountId
. But I think there is no way around that. 🤷 Adding more constraints maybe reduce the number of types this is implemented for, but I'm not sure if it's worth it? 🤔
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.
I would not spend too much on this, but if that's the only trait required right now in the method implementation and it's compiling, I would go on with that.
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.
As mentioned, there's still a dependency in the lock file from the launch and the staking pallets towards the runtime-common
crate. There are also few other comments, but the cleanup is very nice to have!
@@ -177,7 +177,7 @@ pub trait DidVerifiableIdentifier { | |||
) -> Result<DidVerificationKey, SignatureError>; | |||
} | |||
|
|||
impl DidVerifiableIdentifier for runtime_common::DidIdentifier { | |||
impl<I: AsRef<[u8; 32]>> DidVerifiableIdentifier for I { |
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.
Can't we use the same trait requirements that the pallet requires?
type DidIdentifier: Parameter + DidVerifiableIdentifier + MaxEncodedLen;
Or if we want to be even more general, just taking whatever is needed from the Parameter
type.
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.
LGTM
* refactor: clean inflation pallet of runtime code * refactor: clean pallet did lookup of runtime code * refactor: move parameter to common * refactor: clean pallet did of runtime references * refactor: clean kilt launch of runtime code * refactor: clean parachain-staking of runtime code (cherry picked from commit c724119)
* Adds two more relaychain bootnodes for staging environment (#334) * chore: reset peregrine stg (#335) * ci: use custom ci image (#336) * Optimizes docker layer (#337) * fix: add did lookup pallet to DID authorization logic + reverse lookup index (#343) * chore: update toolchain version to nightly 1.59 (#339) * feat: proxy type for disableling deposit claiming (#341) * fix: rococo protocol id (#369) * feat: generic access control (#316) * Updates toolchain version (#345) * refactor: enforce no runtime in pallet (#349) * fix: features (#353) * feat: add tips pallet (#352) * feat: upgrade to Polkadot v0.9.19 (#357) * chore: upgrade and clean up (#360) * Adds the new rococo chainspec (#363) * feat: add launch pallet removal migration (#359) * refactor: update rilt para id from 2015 to 2108 (#364) * fix: rilt para id (#365) * feat: upgrade to Polkadot v0.9.23 (#366) * use ci-linx:production base image (#368) * feat: upgrade to Polkadot v0.9.24 (#370) * fix: fix CI builders compilation errors and pin to a specific hash (#372)
No Ticket
This PR enforces that no pallet* has dependencies to any runtime code. Which boils down to:
pallet/*
have no dependency to any crates innodes/
andruntimes/*
runtimes/*
has dependencies to/pallets/*
but not to/nodes*
/nodes/*
has dependencies to everything.Why would we do that!? It makes the test for each pallet more redundant!
In a pallet: depending on
runtime-common
prevents us from having common configuration for that pallet.If a pallet has a dependency to
runtime-common
, we can't have a dependency the other way. So if we need to have a configuration struct in a pallet, this struct can't get set inside the runtime common pallet. Or in more general if we have a custom type in a pallet, that depends onruntime-common
we can't use this type in theruntime-common
crate.Pallets should not depend on runtime code in general
A pallet should have no dependency on runtime specifics anyways.
Pallets are usable in what ever runtime you want.
Using runtime code in a pallet would mean that we bind the pallet to this specific runtime (even if it's only used in tests).
*I didn't touch the staking pallet since this is a bit more work and it wasn't needed for the pallet I was working on.
Checklist:
array[3]
useget(3)
, ...)