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

Chain extension #662

Merged
merged 26 commits into from
Oct 20, 2022
Merged

Chain extension #662

merged 26 commits into from
Oct 20, 2022

Conversation

pmikolajczyk41
Copy link
Member

This PR includes:

  1. pallet_contracts::ChainExtension which exposes a single function for calling pallet_snarcos::bare_store_key with mocked arguments
  2. ink::chain_extension definition (reusable in any contract)
  3. sample ink! contract that uses the extension

Reading:

@pmikolajczyk41 pmikolajczyk41 requested a review from h4nsu October 14, 2022 08:36
Base automatically changed from snarcos-pallet to snarkeling October 14, 2022 08:51
bin/runtime/src/lib.rs Outdated Show resolved Hide resolved
bin/runtime/src/chain_extension/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@h4nsu h4nsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing, confused the hell out of me

@@ -0,0 +1,33 @@
[package]
name = "snarcos-extension"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it kinda weird this crate is under runtime folder. contracts would be much better place in my opinion

Copy link
Collaborator

@deuszx deuszx Oct 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to plead guilty here as I made @pmikolajczyk41 move it from /contracts to here.

My reasoning was (and still is) that the chain extension is part of the core chain (you can see it being defined in runtime/src/lib.rs ) and not living in the client space like contracts. Now it lives closer to the place where it's actually used and defined - we wouldn't be adding a chain extension written by clients (/contracts, even though now live in the node's repo, are not part of the core chain).

IMO this also lowers a congitive load on developers that will read the code. Since the chain extensions' functions are referred by an index (number) and not interface, having the caller's function index "closer" (in terms of code organization) to the actual index we will pattern match on should be it simpler to discover. For this particular case, consider the interface exposed to contracts (link) and the actual pattern matching in the chain extension that routes the calls (link).

We can still make it "publishable" and have contracts refer to it in their dependencies https://github.com/Cardinal-Cryptography/aleph-node/blob/liminal/chain-extension/contracts/snarcos-contract/Cargo.toml#L26 - making it all type-safe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both points and I really cannot decide. There is, lets say, some solution with using https://github.com/Supercolony-net/obce, but for now it would be an overkill.

I'll leave this as it is now, and in case we find it inconvenient, we'll move it somewhere else (I suppose/hope somebody will play with it more and thus have some experience-based feedback).

CCing @Yithis to make him aware of these doubts (since he'll be extending this extension (today?))

@pmikolajczyk41 pmikolajczyk41 merged commit fab52b8 into snarkeling Oct 20, 2022
@pmikolajczyk41 pmikolajczyk41 deleted the liminal/chain-extension branch October 20, 2022 05:50
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 this pull request may close these issues.

3 participants