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

Storage refactoring new hope for review #1331

Merged

Commits on Jul 21, 2022

  1. Import new unstable functions with transparent hashing.

    Updated the API to work with the generic key `K: Encode` instead of the old `Key`.
    Also, the change contains optimization to reduce the size of contracts. In most cases, it is `#[inline(always)]`; but `return_value` also got small optimization; removed usage of `extract_from_slice` where it is not needed.
    xgreenx committed Jul 21, 2022
    Configuration menu
    Copy the full SHA
    2b26752 View commit details
    Browse the repository at this point in the history
  2. primitives crate:

    Removed old 32 bytes `Key`. Replaced it with `u32`. Added `KeyComposer`, it is a helper struct that does all manipulation with the storage key. It allows concat two storage keys into one, compute storage key for fields based on the filed, struct, enum, variants names.
    Removed all tests and benches. Didn't add it for new primitives because the key is standard `u32` and all keys are calculated during compilation.
    
    storage crate:
    Removed `SpreadLayout`, `PackedLayout`, `SpreadAllocate`, `PackedAllocate`, and all related helper functions.
    Removed `Packed` struct cause it is the default behavior for storage right now. Added `Lazy` struct that allows `get`/`set` value from/into the storage. It is similar to `Mapping` but works with one storage key and one value.
    Introduced new main traits to work with storage in `storage/src/traits/storage.rs`.
    Also added a new `OnCallInitializer` trait to improve the flow with upgradable contracts and support initialization on demand by default. Added `pull_or_init` macro that inits the storage struct if it is impossible to load it. It also can be used as optimization for contracts without an explicit constructor.
    Replaced implementation of old traits for main primitives with a new one. Added blanket implementation of new traits for structures that are `Packed` by default. It reduces the amount of code and adds support of generic structures but adds problems with tuples(now tuples implement new traits only if inner items are `Packed`).
    Introduced `AutoKey` and `ManualKey` that allows specifying which key the user wants to use. Added support of it into all traits and structures.
    Refactored `Mapping` to follow new rules.
    xgreenx committed Jul 21, 2022
    Configuration menu
    Copy the full SHA
    8dbf040 View commit details
    Browse the repository at this point in the history
  3. metadata crate:

    Updated storage layout in the metadata. Introduces the concept of roots and leafs. Root defines the storage key for all sub-tree until there will be another Root. Leafs are common types that are part of the sub-tree and serialized/deserialized together into one storage key.
    Replaced 32 bytes storage key with `u32`.
    Added validation that all root storage keys don't overlap. Maybe better to add that error or reuse that validator on the `cargo-contract` side to show a more user-friendly error.
    `RootLayout` and validator are used in codegen(next commit). The contract is wrapped into `RootLayout`, and we do validation for that tree.
    Metadata now contains name for each struct/enum/variant/field. It is useful information because now the storage key is calculated based on the name of struct/enum/variant/field.
    
    storage crate:
    Added a new helper crate `storage/codegen`. It contains some useful functional that is used in `ink_storage_derive` and in `ink_lang_codegen` crates. It has a method that returns all types of the struct/enum/unit and a method that finds "salt" in the generics of the struct/enum. It uses magic constant "KeyHolder"(about that you can read in issue) to find salt, so I tried to have only one place where we are using that constant.
    
    Replaced derive implementation of old trait with new one. You can check the tests to see how the implementation looks like. `Storable` recursively call `encode` and `decode` for all fields. `KeyHolder` return key of the salt. `Item` uses `AutoKey` or key specified by the user. I want to highlight that `PreferredKey` only is used with the `AutoItem` trait. If `PreferredKey` is `AutoKey`, then `AutoItem<AutoGenerated>` select auto-generated key, otherwise preferred. So `AutoItem` trait decides that key to use. It is why derive macro only set `PreferredKey`.
    Updated drive for `StorageLayout`, now it uses `u32` and pass name of the struct into metadata.
    xgreenx committed Jul 21, 2022
    Configuration menu
    Copy the full SHA
    341c48b View commit details
    Browse the repository at this point in the history
  4. Removed initialize_contract and related to initialization stuff. No…

    …w the codegen uses `pull_or_init` in the `call`. Updated `execute_constructor` to work with new storage methods.
    
    Allowed usage of generics during the declaration of the primary contract storage. Users can specify the default storage key with `KeyHolder` via generic.
    Added parser for `storage_item` macro with its config.
    xgreenx committed Jul 21, 2022
    Configuration menu
    Copy the full SHA
    346529c View commit details
    Browse the repository at this point in the history
  5. Removed the old codegen related to spread and packed layout. If some …

    …object implements `Decode` and `Encode`, it is `Packed`, and it uses the blanket implementation of new traits.
    
    In dispatch, codegen started to use a new method to work with storage.
    In metadata codegen added usage of new `RootLayout`. We wrap the contract into that layout because the contract has its storage key for all inner fields by default. Also added a run of validation logic during metadata generation.
    Added `storage_item` macro. It transforms all types from autokey into manual key(if types support it). It calculates the storage key based on the name(it uses the `KeyComposer::compute_key` function from the primitives crate). Also, macro generates an additional `Check` structure that includes all raw fields. It helps show correct errors to the user in case of typos, wrong types, etc.
    xgreenx committed Jul 21, 2022
    Configuration menu
    Copy the full SHA
    b731f92 View commit details
    Browse the repository at this point in the history
  6. Updated all examples to use a new API.

    Simplified delegate call example very well causes of new `OnCallInitializer` trait and support of manual specifying key.
    xgreenx committed Jul 21, 2022
    Configuration menu
    Copy the full SHA
    d6db8de View commit details
    Browse the repository at this point in the history
  7. UI tests for a new codegen.

    Can't highlight something unusual here=)
    xgreenx committed Jul 21, 2022
    Configuration menu
    Copy the full SHA
    f967986 View commit details
    Browse the repository at this point in the history

Commits on Aug 15, 2022

  1. Configuration menu
    Copy the full SHA
    fc3fcb0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8f511ec View commit details
    Browse the repository at this point in the history
  3. Make CI happy

    xgreenx committed Aug 15, 2022
    Configuration menu
    Copy the full SHA
    7e094eb View commit details
    Browse the repository at this point in the history
  4. Fix tests

    xgreenx committed Aug 15, 2022
    Configuration menu
    Copy the full SHA
    8c9942d View commit details
    Browse the repository at this point in the history
  5. Fix tests

    xgreenx committed Aug 15, 2022
    Configuration menu
    Copy the full SHA
    9188ca7 View commit details
    Browse the repository at this point in the history
  6. Fix tests

    xgreenx committed Aug 15, 2022
    Configuration menu
    Copy the full SHA
    7375b4c View commit details
    Browse the repository at this point in the history
  7. Fix tests

    xgreenx committed Aug 15, 2022
    Configuration menu
    Copy the full SHA
    906b1d8 View commit details
    Browse the repository at this point in the history

Commits on Aug 16, 2022

  1. Apply suggestions:

    - In most cases it is comments=)
    - Moved `pull_or_init` on one level upper.
    - Put the tests into the `impls/mod.rs`
    xgreenx committed Aug 16, 2022
    Configuration menu
    Copy the full SHA
    290b384 View commit details
    Browse the repository at this point in the history
  2. Fix doc

    xgreenx committed Aug 16, 2022
    Configuration menu
    Copy the full SHA
    1f7603f View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    09c24e1 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    07a71ea View commit details
    Browse the repository at this point in the history

Commits on Aug 17, 2022

  1. Suggestion from the review

    xgreenx committed Aug 17, 2022
    Configuration menu
    Copy the full SHA
    07889af View commit details
    Browse the repository at this point in the history
  2. Revert back u8

    xgreenx committed Aug 17, 2022
    Configuration menu
    Copy the full SHA
    f64d7f7 View commit details
    Browse the repository at this point in the history
  3. Remove unwrap

    xgreenx committed Aug 17, 2022
    Configuration menu
    Copy the full SHA
    efff8bf View commit details
    Browse the repository at this point in the history
  4. Collapse if let

    xgreenx committed Aug 17, 2022
    Configuration menu
    Copy the full SHA
    556ce20 View commit details
    Browse the repository at this point in the history
  5. Fixed overflow for enums

    xgreenx committed Aug 17, 2022
    Configuration menu
    Copy the full SHA
    5ce970d View commit details
    Browse the repository at this point in the history

Commits on Aug 18, 2022

  1. Fixing comments

    xgreenx committed Aug 18, 2022
    Configuration menu
    Copy the full SHA
    8fcdab2 View commit details
    Browse the repository at this point in the history

Commits on Aug 19, 2022

  1. Configuration menu
    Copy the full SHA
    ca9f95b View commit details
    Browse the repository at this point in the history
  2. Fix test

    xgreenx committed Aug 19, 2022
    Configuration menu
    Copy the full SHA
    8eb4cb9 View commit details
    Browse the repository at this point in the history

Commits on Aug 22, 2022

  1. Renamed key_holder.

    Add UI test for double storage_item.
    Applied suggestion from the review.
    xgreenx committed Aug 22, 2022
    Configuration menu
    Copy the full SHA
    66a6901 View commit details
    Browse the repository at this point in the history
  2. Nightly fmt

    xgreenx committed Aug 22, 2022
    Configuration menu
    Copy the full SHA
    8854be8 View commit details
    Browse the repository at this point in the history
  3. Remove Packed path

    xgreenx committed Aug 22, 2022
    Configuration menu
    Copy the full SHA
    15563de View commit details
    Browse the repository at this point in the history
  4. Fix doc test

    xgreenx committed Aug 22, 2022
    Configuration menu
    Copy the full SHA
    4f35230 View commit details
    Browse the repository at this point in the history

Commits on Aug 26, 2022

  1. Configuration menu
    Copy the full SHA
    5065b07 View commit details
    Browse the repository at this point in the history
  2. Merge branch 'master' into feature/storage-rework-new-hope

    # Conflicts:
    #	crates/lang/codegen/Cargo.toml
    #	crates/lang/codegen/src/generator/metadata.rs
    #	crates/lang/macro/Cargo.toml
    xgreenx committed Aug 26, 2022
    Configuration menu
    Copy the full SHA
    3247ee2 View commit details
    Browse the repository at this point in the history
  3. Fixed build

    xgreenx committed Aug 26, 2022
    Configuration menu
    Copy the full SHA
    63e3909 View commit details
    Browse the repository at this point in the history
  4. Fix build

    xgreenx committed Aug 26, 2022
    Configuration menu
    Copy the full SHA
    c07b471 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    72c84a8 View commit details
    Browse the repository at this point in the history
  6. Fix doc link

    xgreenx committed Aug 26, 2022
    Configuration menu
    Copy the full SHA
    cad9234 View commit details
    Browse the repository at this point in the history

Commits on Aug 29, 2022

  1. Merge branch 'master' into feature/storage-rework-new-hope

    # Conflicts:
    #	crates/lang/macro/Cargo.toml
    xgreenx committed Aug 29, 2022
    Configuration menu
    Copy the full SHA
    7371905 View commit details
    Browse the repository at this point in the history

Commits on Aug 30, 2022

  1. Fix mapping example

    xgreenx committed Aug 30, 2022
    Configuration menu
    Copy the full SHA
    477e4cf View commit details
    Browse the repository at this point in the history

Commits on Aug 31, 2022

  1. Applied suggestion.

    Removed `delegate-call` example with `OnCallInitializer`
    xgreenx committed Aug 31, 2022
    Configuration menu
    Copy the full SHA
    235d649 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8b9ccbc View commit details
    Browse the repository at this point in the history
  3. Merge remote-tracking branch 'parity/master' into feature/storage-rew…

    …ork-new-hope
    
    # Conflicts:
    #	.gitlab-ci.yml
    xgreenx committed Aug 31, 2022
    Configuration menu
    Copy the full SHA
    a42bc9d View commit details
    Browse the repository at this point in the history
  4. fix test

    xgreenx committed Aug 31, 2022
    Configuration menu
    Copy the full SHA
    be1563e View commit details
    Browse the repository at this point in the history
  5. fix test

    xgreenx committed Aug 31, 2022
    Configuration menu
    Copy the full SHA
    300b139 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    7b8733d View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    3e3fbd7 View commit details
    Browse the repository at this point in the history

Commits on Sep 1, 2022

  1. Configuration menu
    Copy the full SHA
    5808157 View commit details
    Browse the repository at this point in the history