Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

contracts: Make chain extensions composeable #11751

Closed
athei opened this issue Jun 28, 2022 · 0 comments · Fixed by #11816
Closed

contracts: Make chain extensions composeable #11751

athei opened this issue Jun 28, 2022 · 0 comments · Fixed by #11816
Assignees
Labels
J0-enhancement An additional feature request. Z2-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase.

Comments

@athei
Copy link
Member

athei commented Jun 28, 2022

Currently, you can only have one chain extension per pallet-contracts. The runtime author needs to provide a type implementing ChainExtension to the Config trait which is then called into whenever a contract uses a chain extension:

fn seal_call_chain_extension(
    func_id: u32,
    input_ptr: u32,
    input_len: u32,
    output_ptr: u32,
    output_len_ptr: u32
)

The meaning of the func_id is defined by the chain extension itself. The chain extension would use it to select which sub functionality (function) it should provide. This means that a single chain extension controls the whole function space.

This works fine if a chain wants to provide a single monolithic chain extension specific to its needs. However, we know that there are also general use chain extensions that are useful to many chains. Those would usually be candidates for inclusion to the pallet-contracts core API but it is desirable to have them exist as a chain extension for a while.

Because of this we want chain authors to be able to pick and choose different chain extensions and compose them. The idea is to the following:

  • Implement ChainExtension for (ChainExtension, ChainExtension, ...).
  • Divide the u32 function space into extension: u16, func: u16: The msb bits selects the chain extension and the lsb bits the function within.
  • trait ChainExtension will be changed to provide a const u16 to announce its extension id and the ChainExtension::call will only get the lsb bits.
  • seal_call_chain_extension remains unchanged.
  • Create a chain extension registry similar to the ss58 registry to coordinate extension ids
@athei athei added J0-enhancement An additional feature request. Z2-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase. labels Jun 28, 2022
@athei athei self-assigned this Jun 28, 2022
@athei athei moved this to Done in Smart Contracts Jul 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J0-enhancement An additional feature request. Z2-medium Can be fixed by a coder with good Rust knowledge but little knowledge of the codebase.
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

1 participant