Skip to content

Consider creating a convention to expose the most common Config types for discoverability #308

@KiChjang

Description

@KiChjang

Take for example frame_system::Config. While constructing the runtime, I would have to implement the Config trait for the runtime, something similar to the following:

impl frame_system::Config for Runtime {
    type BaseCallFilter = frame_support::traits::AllowAll;
    // ...
}

It is not readily apparent that frame_support::traits contains a type that is assignable to BaseCallFilter. In addition, the runtime creator will have to go through the source file of frame_support::traits in order to know that there is also the DenyAll enum that could be assigned to BaseCallFilter.

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:

enum BaseCallFilterOptions {
    AllowAll,
    DenyAll,
}

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:

#[pallet::config]
pub trait frame_system::Config {
    #[pallet::common_config_options(AllowAll, DenyAll)]
    type BaseCallFilter: Filter<Self::Call>;
    // ...
}

This would then automatically generate a BaseCallFilterOptions enum for the pallet, and also implement the Filter trait on BaseCallFilterOptions, which essentially forwards the appropriate method calls to its variants. The pallet author would then be responsible for implementing Filter on the AllowAll and DenyAll types.

cc @shawntabrizi @thiolliere

Metadata

Metadata

Assignees

No one assigned

    Labels

    D3-involvedCan be fixed by an expert coder with good knowledge of the codebase.I5-enhancementAn additional feature request.T1-FRAMEThis PR/Issue is related to core FRAME, the framework.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions