-
Notifications
You must be signed in to change notification settings - Fork 354
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
Foreign assets creation via token reserve #3104
base: master
Are you sure you want to change the base?
Conversation
WASM runtime size check:Compared to target branchMoonbase runtime: 2424 KB (+4 KB) 🚨 Moonbeam runtime: 2380 KB (-24 KB) ✅ Moonriver runtime: 2392 KB (-8 KB) ✅ Compared to latest release (runtime-3401)Moonbase runtime: 2424 KB (+392 KB compared to latest release) 🚨 Moonbeam runtime: 2380 KB (+368 KB compared to latest release) Moonriver runtime: 2392 KB (+380 KB compared to latest release) |
{ | ||
type Success = OriginType; | ||
fn try_origin(o: O) -> Result<OriginType, O> { | ||
Original::try_origin(o)?; |
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 didn't follow the whole code, but how do we know here that the original Origin is indeed some type of Governance ?
What I mean is, I think we are coupling this enum which belongs to the pallet, to the configuration of the pallet. If we or someone configures the ForeignAssetCreatorOrigin to be Signed, then this would be marked as Governance, am I right ?
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.
MapSuccessToGovernance
and MapSuccessToXcm
are just some utility classes that will help converting the Success
type of EnsureSigned
, EnsureXcm
, EnsureRoot
, etc to be one of two types of OriginType
.
You still have to provide what is considered Governance and what's considered Xcm, for example in mocks.rs
I use MapSuccessToGovernance<EnsureRoot>
this will consider root as governance.
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.
Okay I follow now, we need to be careful because the constraint comes from the Success type in the definition of MapSuccessToGovernance
and MapSuccessToXcm
.
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 really like the changes now. I left some comments regarding how we constrain the ForeignAsset*Origin
types in the config, so we only allow some type of governance and some type of XCM. The implementation is smart, but is relying in the Success
type of the origin. This wouldn't mean it is a security issue, because we are the ones configuring the pallet correctly, but it could potentially be misconfigured.
{ | ||
type Success = OriginType; | ||
fn try_origin(o: O) -> Result<OriginType, O> { | ||
Original::try_origin(o)?; |
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.
Okay I follow now, we need to be careful because the constraint comes from the Success type in the definition of MapSuccessToGovernance
and MapSuccessToXcm
.
|
||
/// Used to convert the success of an EnsureOrigin into `OriginType::Governance` | ||
pub struct MapSuccessToGovernance<Original>(PhantomData<Original>); | ||
impl<O, Original: EnsureOrigin<O, Success = ()>> EnsureOrigin<O> |
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.
Implicitly, here it is assumed that having and empty tuple as the Success
type, means the Origin
comes from either Root or Governance, because no account is associated to the origin. While this is true in most cases, it is not strict (we could have a custom Signed origin that returns and empty tuple, and it would be considered Governance)
|
||
/// Used to convert the success of an EnsureOrigin into `OriginType::XCM` | ||
pub struct MapSuccessToXcm<Original>(PhantomData<Original>); | ||
impl<O, Original: EnsureOrigin<O, Success = Location>> EnsureOrigin<O> |
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.
Same as above, here it is a assumed that having a Location
as Success
type means that the Origin comes from XCM. In this case I would say is better than the other, because a Location type already indicates some relationship with an XCM origin.
What does it do?
create_foreign_asset
now reserves a deposit from the caller (i.e. parachain sovereign accounts)ForeignAssetCreationDeposit
) and can be changed withpallet_parameters
create_foreign_asset
,change_xcm_location
,freeze_foreign_asset
,unfreeze_foreign_asset
can only be called by a Parachain Location origin (through XCM) or Governancecreate_foreign_asset
Disclaimer: the pallet is not in use and the functionality wasn't exposed publicly AFAIK. The changes are still breaking, but most likely harmless.
TODO
What important points reviewers should know?
Some assumptions were made considering the current state of the pallet:
AssetOwner
was meant initially to be a descriptive enum of the possible sources of creation of an asset, but since there were no assets yet created, we only need to distinguish between migrated assets, and the ones created from now on (any account). Naming in this enum might be improved.Is there something left for follow-up PRs?
What alternative implementations were considered?
Using Fungibles was investigated, but the implementation uses ReservableCurrency, following the same pattern as pallet assets.
Are there relevant PRs or issues in other repositories (Substrate, Polkadot, Frontier, Cumulus)?
We should run the migration added here #3020 after this PR is merged.
What value does it bring to the blockchain users?
It should be easier for Parachain teams to register their assets natively in Moonbeam