Skip to content
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

PoC: Extension System #8

Closed
xlc opened this issue Apr 29, 2024 · 4 comments · Fixed by #27
Closed

PoC: Extension System #8

xlc opened this issue Apr 29, 2024 · 4 comments · Fixed by #27

Comments

@xlc
Copy link
Member

xlc commented Apr 29, 2024

Prototype an Extension System with following requirements:

  • Each extension can be defined as a Rust trait.
  • Some macro to read the definitions of it and generate a stable 64 bytes hash as a const ID field as the ExtensionId
    • It should normalize the order of methods and parameter names
    • The parameter type should be considered. But in that case, we will need to be able to generate a stable hash for it. In that case, we need to either use Implement stable type id paritytech/scale-info#182 or have a custom solution
  • User should be able to pass a list of Extension implementations, and the ExtensionExecutor should be able to perform discovery and invocation of the methods for an extension.
  • Extension can have associated types
  • A permission controller to safeguard extensions. For example, we may have an extension that allow arbitrary storage read but only expose it for the usage of offchain context. i.e. it should be disabled when executed via XCM. This also allows the runtime to dynamically disable an extension if needed.
@indirection42
Copy link
Contributor

indirection42 commented May 29, 2024

Have a look? https://github.com/open-web3-stack/XCQ/blob/poc-extension-system/poc/extensions/src/lib.rs

User should be able to pass a list of Extension implementations

"User" means Runtime, and the pass is compile-time, right?

@xlc
Copy link
Member Author

xlc commented May 30, 2024

"User" means Runtime, and the pass is compile-time, right?

Yes

You can open draft PR for WIP work. It is easier to review in that way

@indirection42
Copy link
Contributor

Questions about permission controller:

  • Where should I embed the executer context information (XCM/OffChain)? I am skimming through the XCM related chapter In PDA docs.
  • allows the runtime to dynamically disable an extension if needed.

Does dynamically mean run-time enable/disable, or we just provide api like add_filter for runtime to impl it? Is this requirement related with #9 ?

@xlc
Copy link
Member Author

xlc commented Jun 5, 2024

  • struct Context with a filed source enum InvokeSource { RuntimeAPI, XCM, Extrinsic, Runtime }
  • trait PermissionController with something like is_allowed(extensionId: ExtensionId, call: Call, context: Context) and have the executor takes a type implements this trait, and call it before execute an extension method
  • impl PermissionController for () that always return true, so it can be used as a default implementation
  • The runtime can then have a custom implementation, that checks for the extension id, and some other storages, to determine the return value. We need a pallet for this. No need to do it for PoC.

Something similar to this https://github.com/AcalaNetwork/Acala/blob/eb96173487545fe68ee67ece25c6e34c66148eed/runtime/acala/src/lib.rs#L218

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants