-
Notifications
You must be signed in to change notification settings - Fork 799
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
Consider creating a convention to expose the most common Config types for discoverability #308
Comments
An alternative implementation would be to create a |
I don't think user have to go through the source file of frame_support::traits to see that DenyAll and AllowAll exist. I feel like discovering implementation of traits is not so difficult using the rust doc implementors section. |
Hmm... I think you and I have a different mental model of how an average FRAME developer looks like in our minds. I definitely do agree that it's discoverable, but only in the case where the FRAME dev knows to look for the rustdocs. In contrast, I am imagining FRAME devs coming from backgrounds that are not necessarily Rust-based (or even non-software development altogether), and the only thing that can characterize them is their passion for building things on blockchain. With this in mind, I would say that they would not necessarily know where to look for information/documentation. I'd even go further to suggest that they may also not know where to ask for help, and you can see how little road bumps like these pile up and eventually cause them to abandon developing in FRAME altogether (I've seen a recent case where this happened in the subport repo, so you can imagine the number of unreported cases similar to this). Perhaps the solution to the issue that I'm describing is simply having easily accessible docs and presenting information more openly and clearer, and I would agree with that, but I also believe that there is a benefit in designing a system where common conventions exist, which would facilitate the development experience of FRAME devs. |
I feel like providing enum or set of types to be used to implement the Though I agree we can improve the doc, and, when it is possible, to directly link to usual implementation. Here For this particular example about |
Ah, perhaps you misunderstood me. That is not what I'm suggesting to do. I'm suggesting that we keep the traits for the Config types, but additionally create an enum that implements the trait on said enum for the common Config types. Its implementation would simply be to forward function calls to its variants: enum BaseCallFilterOptions {
AllowAll(frame_support::traits::AllowAll),
DenyAll(frame_support::traits::DenyAll),
}
impl<T> Filter<T> for BaseCallFilterOptions {
// this function will have to change to include a self parameter
fn filter(&self, arg: &T) -> bool {
match self {
Self::AllowAll(a) => a.filter(arg),
Self::DenyAll(d) => d.filter(arg),
}
}
} FRAME devs will still continue to be able to implement In summary, I want to optimize for the common use case and generate |
yes ok maybe we can improve some associated types indeed |
Not sure that this would not explode very fast into your face. You would need one attribute macro per trait and external traits would not be supported. |
As explained in this comment, that is not what I'm suggesting to do. FRAME devs will still be able to implement the traits on the types that they want; all I'm suggesting is to create an enum for the most common options. Perhaps if I named the attribute |
Yeah I understood that, but you want to use a macro to generate this enum or not? |
And to implement the |
Okay, I think I see what you mean now. Firstly, the On the part where "external traits would not be supported", I suspect that means the But yes, due to the limitations of enums, I considered whether we should instead generate a module like You've definitely raised a good point about knowing the structure of the bounded trait on the |
No that would be fine. However, it would only work for the common FRAME traits.
By external trait I mean, any trait that is defined by a downstream project. Maybe
For all possible config types? Even if they are not used? |
Only for those types that were mentioned in |
Okay, yeah I have seen your example above again. I'm personally still not fully sold for it :P I still see this as a mainly a lack of documentation. |
would be mostly solved by paritytech/substrate#13454 |
I'd close this -- paritytech/substrate#13454 looks like it's a solution to the problem we're facing. |
Take for example
frame_system::Config
. While constructing the runtime, I would have to implement theConfig
trait for the runtime, something similar to the following:It is not readily apparent that
frame_support::traits
contains a type that is assignable toBaseCallFilter
. In addition, the runtime creator will have to go through the source file offrame_support::traits
in order to know that there is also theDenyAll
enum that could be assigned toBaseCallFilter
.It would be so great for pallets to generate an enum that contains the most commonly used configuration types, e.g. generating something akin to the following for
BaseCallFilter
:This would greatly help in discoverability, since this works very well with IDE code completions. Moreover, should we decide to take this approach, we could establish a convention where
[ConfigTypeName]Options
is always an enum containing the most commonly used configuration types, thereby facilitating ease of configuration.Further work can also be done automate the creation of such an enum while creating the pallet. What I imagine pallet authors would be able to do in the future would be something like the following:
This would then automatically generate a
BaseCallFilterOptions
enum for the pallet, and also implement theFilter
trait onBaseCallFilterOptions
, which essentially forwards the appropriate method calls to its variants. The pallet author would then be responsible for implementingFilter
on theAllowAll
andDenyAll
types.cc @shawntabrizi @thiolliere
The text was updated successfully, but these errors were encountered: