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

Implementation of ink! env (revision 3) #312

Merged
merged 189 commits into from
Feb 3, 2020
Merged

Implementation of ink! env (revision 3) #312

merged 189 commits into from
Feb 3, 2020

Conversation

Robbepop
Copy link
Collaborator

@Robbepop Robbepop commented Jan 18, 2020

#194 Re-implementation of env module (revision 3)

Issues that can be closed upon merging this:

ToDos

  • Finalize implementation of on-chain env (revision 3)
  • FInalize implementation of off-chain env (revision 3)
    • Querying of all contract, chain spec or execution context properties.
    • Read and write from and to contract storage.
    • Printing to contract execution console and put them into records so that they can be queried.
    • Calling runtime functions and registering runtime call handler.
    • Reading from runtime storage and setting it.
    • Push & pop execution contexts.
    • Getting and setting random block hashes. (ext_random)
    • Emitting of events stored into records that can be queried.
    • Support for advancing blocks.
    • Initialization routines.
  • Adjust ink_lang2 for env (revision 3)
    • Add dynamic allocator instance. (Follow-up PR)
    • Add utility wrappers in ink_lang2 crate that replace missing EnvAccess types.
    • Adjust the macro generated output of ink_lang2_macro to use env (revision 3).
  • Remove all usage of env (revision 1) and env (revision 2) from ink! codebase
    • Remove all usage of env (revision 1)
    • Remove all usage of env (revision 2)
  • Remove env (revision 1) and env (revision 2)
    • Remove env (revision 1)
    • Remove env (revision 2)
  • Put env (revision 3) as ink_env into its own ink! crate.
  • Remove ink_model
    • Remove ink_model ink! crate
    • Remove ink_model layer example contracts
  • Remove ink_lang (revision 1)
    • Remove ink_lang (revision 1) ink! crate
    • Remove ink_lang (revision 1) example contracts
  • Remove ink_core-only example contracts
  • Return Option<Result<T>> for get_contract_storage
  • Move ink_core::storage into ink_storage crate (Follow-up PR)
  • Remove test-env crate feature (Follow-up PR)

Follow-up PRs

  • Add dynamic allocator instance.
  • Move ink_core::storage into ink_storage crate
  • Move ink_core::env into ink_env crate
  • Remove test-env crate feature and replace it in parts with ink-test crate feature

Crate Dependency Graph

Anticipated dependency graph after planned follow-up PRs have been merged.

2020-02-01-012659_1346x692_scrot

Description

  • This is a great simplification of env2 while still providing its efficiency guarantees.
  • The test-env feature is going to be removed.
  • The only compilation configurations that are going to be allowed are either no_std + wasm32-unknown-unknown or std (e.g. for off-chain testing). The environmental interface is generally the same for both configurations. However, in the case of #[cfg(test)] there is going to be another test sub module to allow for low-level off-chain testing environment manipulations.

The interface has a typed and an untyped subset of APIs.

  • An example of a typed interface is fn caller since it returns a T::AccountId where T: EnvTypes.
  • An example of an untyped interface is fn get_contract_storage<T> since it doesn't have any dependencies on a specific EnvTypes provider.
  • As in env2 all operations between the smart contract and its environment are still implicitly cached and buffered to avoid dynamic allocations. We could even reduce this to no dynamic allocations at all in this implementation by using a static buffer instead.
  • Whereas env (revision 2) took over the job to also provide dynamic allocators this is no longer true for env (revision 3) and will instead be handled in its own sub module (e.g. dyn_alloc).

The env revision 3 will replace all usage of env (revision 1) and env (revision 2).

Compiled Docs

The new off-chain test API

2020-01-28-003043_1662x1007_scrot

The contract calling and instantiation API

2020-01-23-150207_1666x868_scrot

The general environment API

2020-01-23-150154_871x1205_scrot

Contract Restoration

For the first time we also provide high-level APIs for contract restoration.

2020-01-18-133809_1161x1184_scrot

Runtime Emulation

Set certain runtime storage entries in the emulated off-chain runtime to allow querying them by the contract.

2020-01-27-163857_903x240_scrot

Initialize off-chain runtime dispatch handlers that emulate your runtime behaviour from the perspective of an invoking contract.

2020-01-27-163848_846x284_scrot

@Robbepop Robbepop mentioned this pull request Jan 18, 2020
81 tasks
@codecov-io
Copy link

codecov-io commented Jan 18, 2020

Codecov Report

Merging #312 into master will increase coverage by 29.78%.
The diff coverage is 83.09%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #312       +/-   ##
===========================================
+ Coverage   34.03%   63.82%   +29.78%     
===========================================
  Files          73       69        -4     
  Lines        4906     5181      +275     
===========================================
+ Hits         1670     3307     +1637     
+ Misses       3236     1874     -1362
Impacted Files Coverage Δ
lang/macro/src/codegen/env_types.rs 0% <ø> (ø)
lang/macro/src/codegen/storage.rs 0% <ø> (ø)
lang/macro/src/ir/utils.rs 0% <ø> (ø)
core/src/storage/collections/hash_map/impls.rs 80.32% <ø> (ø)
core/src/storage/collections/bitvec/tests.rs 98.62% <ø> (ø)
lang/macro/src/contract.rs 0% <ø> (ø)
core/src/storage/alloc/traits.rs 45.45% <ø> (+45.45%) ⬆️
lang/macro/src/extensions.rs 0% <ø> (ø)
lang/macro/src/codegen/mod.rs 0% <ø> (ø)
lang/macro/src/codegen/abi.rs 0% <ø> (ø)
... and 103 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 6fd834d...6bc22db. Read the comment docs.

core/src/env3/api.rs Outdated Show resolved Hide resolved
@Robbepop Robbepop dismissed stale reviews from ascjones via 728fdef February 3, 2020 13:04
@Robbepop Robbepop changed the title Initial implementation of env revision 3 Implementation of ink! env (revision 3) Feb 3, 2020
@Robbepop
Copy link
Collaborator Author

Robbepop commented Feb 3, 2020

taco

Well deserved taco. xD

ascjones
ascjones previously approved these changes Feb 3, 2020
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

@Robbepop Robbepop merged commit 321fe03 into master Feb 3, 2020
@Robbepop Robbepop deleted the robin-env3 branch February 3, 2020 13:49
ascjones pushed a commit to use-ink/cargo-contract that referenced this pull request Feb 3, 2020
@jacogr jacogr mentioned this pull request Feb 3, 2020
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

4 participants