feat(pallet-assets): define and implement sufficients traits for pallet-assets#2872
feat(pallet-assets): define and implement sufficients traits for pallet-assets#2872pandres95 wants to merge 6 commits intoparitytech:masterfrom
pallet-assets#2872Conversation
aa33aa3 to
b1e3ae1
Compare
|
Per @muharem's suggestion, I decided to close #1768 and continue here. Ready to gather feedback (I know this PR might come with some controversy). |
ac13956 to
0d7e338
Compare
substrate/frame/assets/src/traits.rs
Outdated
| @@ -0,0 +1,26 @@ | |||
| pub mod sufficients { | |||
There was a problem hiding this comment.
sufficients isn't really a good name because the mod has nothing to do with the behavior of sufficient assets, but merely setting the sufficient property to true or false.
I would therefore call it sufficiency.
I also question whether this should be in the Assets pallet at all and not frame-support like the Account Touch trait.
There was a problem hiding this comment.
@muharem and @liamaharon have done some recent work on this pallet, maybe they can comment.
There was a problem hiding this comment.
I get it. Just resolved all the other changes.
As for whether sufficiency should be on Assets pallet and not on frame-support, my hint was this @muharem's comment:
not sure if this concept is general enough, I cannot really say.
This is because this concept might not be general enough, but is somewhat specific to Assets. Instead, the most general concept, actually, is the AccountTouch trait.
but an alternative can be a separate trait on Assets pallet level, which lets you inspect some additional characteristics of an asset.
That's what I based on to close #1768 and open this PR instead. 😁
There was a problem hiding this comment.
I clearly see use cases for a trait to read the is_sufficient flag. But I am not fully agree with the use case you giving in the description - "Checking whether an asset was appropriately created as sufficient". When it is tests within the package, I think it is fine to access the internals of a package (e.g. storage). And you should not need to test it as in your example from outside.
I also would like to question if you have a real use case, where you need to alter is_sufficient flag. if you look to the public api of the pallet, the altering api - force_asset_status has more parameters then just one flag. I can easily imagine someone coming and introducing new function with all those parameters. What I am trying to say, it is good to have real use cases for introducing such contracts. And not trying to say that one better than another.
| @@ -0,0 +1,20 @@ | |||
| use crate::{ | |||
There was a problem hiding this comment.
maybe traits and impls? otherwise the list of files will grow here pretty quick.
I also have only strong opinion on keeping our folders/files/modules style consistent, since there is no yet agreement on it, I would just try to keep it close to what we have now, and now we tend to have less files than many.
There was a problem hiding this comment.
Would this mean also moving impl_fungibles and impl_stored_map onto an impls file/folder? I see the point on making the file structure lighter, but seeing that other impls are not that light (i.e. impl_fungibles is 311 lines) a bit of not-flatness might be good for the sake of readibility from time to time.
My suggestion:
...
impls/
├─ fungibles.rs
├─ stored_maps.rs
├─ sufficiency.rs
├─ mod.rs
...
traits.rs
...
41dbc74 to
f5f1878
Compare
|
Reply to #2872 (comment)
I see it's possible to come up with a more general solution, by considering a more general trait that works alongside This would general enough, and would enable every possible entity out there to be a provider or set that possibility. Now, I'm not sure of whether that would be achievable without some ambiguity (on entity ID, for example) so I think sticking to sufficiency for now would help @muharem. Maybe if we get enough feedback on a way around, I could move forward with a more general solution that can go on |
0bdaf95 to
34ef3a7
Compare
|
Since I've already implemented the last set of requested changes, it'd be nice to have some sort of feedback regarding this PR, before I can move forward with a further proposal on generalizing this concept. I'd appreciate that. |
|
Closing due to inactivity. If someone is interested about this proposal in the future, just ping me. |
This pull request supersedes #1768, and implements methods to access and mutate
is_sufficientvalue of an asset.Description
This Pull Request introduces two traits under
pallet-asset: a trait calledsufficients::Inspect, and a trait calledsufficients::Mutate. These methods are useful since pallet implementors can benefit from having this (so far missing) piece of information, either for testing checks or for handling accounts touching on behalf of others.Use Cases
Use Case: Checking whether an asset was appropriately created as sufficient
A pallet might have a rule that allows creating assets, but only marking one of these (i.e. the first) as sufficient. A typical test for this would resemble something like this
Without this getter, implementing
assert_sufficiencywould require (as shown here) the following steps:sp_io::storage::get.AssetDetailsstruct that resembles the expected one, sinceis_sufficientis a private field.With the getter, it would be something as simple as this, no further illegal accesses required:
Use Case: Checking sufficiency for an existing asset
Some pallets might see it useful to check whether an asset is sufficient, for some cases where it might be useful (e.g. some restricted versions of DEXes where pool implementors would like to check that those assets are sufficient).
Without the getter, this would require building the pallet as an extension of the Assets pallet. Some tricks like the one explained in the use case above would be impractical.
Implementation
The implementation is actually really simple.
substrate/frame/pallets/assets/src/traits.rs:sufficients::Inspectandsufficients::Mutate. The method signature returnsbool, defaults tofalsewhen the asset does not exist.impl_sufficients.rsfile, getting the asset's details, and mapping the response asasset.is_sufficient.Checklist
Trequired)