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

Implement ink! chain extensions #592

Merged
merged 88 commits into from Jan 12, 2021
Merged

Implement ink! chain extensions #592

merged 88 commits into from Jan 12, 2021

Conversation

Robbepop
Copy link
Collaborator

@Robbepop Robbepop commented Nov 24, 2020

Implements #585.

ToDo List

  • Add unit tests for IR.
  • Add a UI test for the whole feature + new syntax.
  • Adjust ink_env definitions and remove crate feature.
  • Add IR implementation.
  • Add codegen implementation.
  • Add proc. macro definitions.
  • Create a design for handling and managing errors and error codes from chain extension methods.
  • Implement #[ink::chain_extension] code generation for the new design.
  • Write docs for usage and documenting details.
  • Rename #[ink::contract] env_types parameter to env.
  • Implement chain extension calling for the off-chain environment.
    • As the previous implementation the current off-chain environment implementation for calling and registering chain extension methods does not support access to the environment such as the runtime storage. This is a huge disadvantage and should be fixed as soon as possible in the rework of the off-chain environment.
  • Find solution for using Self::ErrorCode in chain extension method signatures. Ideally users should be able to use it.
    • Actually users do not really need to make use of it since return type of Result<T, Self::ErrorCode> is implcit for expect_ok && !expect_output.
  • Make chain extension codegen work for all configs:
    • expect_ok: false and expect_output: false
    • expect_ok: false and expect_output: true
    • expect_ok: true and expect_output: false
    • expect_ok: true and expect_output: true
  • Think about better names for expect_output and expect_ok.
    • Found better design with handle_status: bool and returns_result: bool attributes that default to true.

@Robbepop Robbepop marked this pull request as draft November 24, 2020 14:35
@codecov-io
Copy link

codecov-io commented Nov 24, 2020

Codecov Report

Merging #592 (5fcb008) into master (abd5cf1) will decrease coverage by 0.80%.
The diff coverage is 72.02%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #592      +/-   ##
==========================================
- Coverage   83.71%   82.90%   -0.81%     
==========================================
  Files         156      161       +5     
  Lines        6975     7353     +378     
==========================================
+ Hits         5839     6096     +257     
- Misses       1136     1257     +121     
Impacted Files Coverage Δ
crates/env/src/api.rs 43.75% <ø> (ø)
crates/env/src/backend.rs 0.00% <ø> (ø)
crates/env/src/call/call_builder.rs 0.00% <0.00%> (ø)
crates/env/src/call/create_builder.rs 0.00% <0.00%> (ø)
crates/env/src/chain_extension.rs 0.00% <0.00%> (ø)
crates/env/src/engine/off_chain/impls.rs 52.63% <0.00%> (-5.34%) ⬇️
crates/env/src/engine/off_chain/mod.rs 85.71% <ø> (-3.90%) ⬇️
crates/env/src/engine/off_chain/test_api.rs 80.85% <ø> (ø)
crates/env/src/types.rs 44.44% <ø> (ø)
crates/lang/codegen/src/lib.rs 100.00% <ø> (ø)
... and 35 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update abd5cf1...5fcb008. Read the comment docs.

@Robbepop Robbepop marked this pull request as ready for review November 30, 2020 15:21
Robbepop and others added 9 commits January 12, 2021 13:47
Co-authored-by: Michael Müller <michi@parity.io>
Co-authored-by: Michael Müller <michi@parity.io>
Co-authored-by: Michael Müller <michi@parity.io>
Co-authored-by: Michael Müller <michi@parity.io>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

LGTM. As discussed the expect_ok and expect_output attributes are not perfect, but I can't think of better names for now and is certainly not a blocker to merge.

crates/env/src/backend.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ast/attr_args.rs Outdated Show resolved Hide resolved
crates/lang/macro/src/lib.rs Show resolved Hide resolved
crates/lang/macro/src/lib.rs Show resolved Hide resolved
crates/lang/ir/src/ir/chain_extension.rs Outdated Show resolved Hide resolved
crates/lang/ir/src/ir/chain_extension.rs Show resolved Hide resolved
Robbepop and others added 6 commits January 12, 2021 18:42
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
@Robbepop
Copy link
Collaborator Author

Robbepop commented Jan 12, 2021

We concluded to try out how a new proposed syntax would look like instead of going with expect_output and expect_ok:

#[ink(
    extension = 1,
    handle_status = true|false,
    returns_result = true|false
)]
fn my_extension_method();

Where handle_status and returns_result both default to true.

@Robbepop Robbepop merged commit 59a7f5e into master Jan 12, 2021
@Robbepop Robbepop deleted the robin-impl-chain-extension branch January 12, 2021 19:39
@shawntabrizi
Copy link
Contributor

nice :)

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.

None yet

6 participants