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

Contract Migration #137

Closed
wants to merge 18 commits into from
Closed

Contract Migration #137

wants to merge 18 commits into from

Conversation

mrLSD
Copy link
Member

@mrLSD mrLSD commented Jun 10, 2021

Universal migration mechanism for storage state.
Possible actions:

    // Add field with Value
    Add,
    // Rename key field
    RenameKey,
    // Update value for key field
    UpdateValue,
    // Rename key and update value
    UpdateKeyValue,
    // Remove key field
    Remove,
    // Remove only value for key field
    RemoveValue,

The migration function can be invoked only by the contract owner (for security reasons).

birchmd and others added 11 commits June 1, 2021 19:04
* Add tests for state check after selfdestruct

* Aurora runner tracks storage usage to avoid underflow when storage is released in future transactions (#85)

* Implement generational storage (#87)

* Base precompile code between connectors (#73)

* Base precompile code between connectors

* Handle errors and validate input

* Use proper result

* Document `aurora encode-address` usage.

* Cache cargo artifacts between CI runs. (#92)

* Address comments from audit. (#86)

* Validate register length in `read_input_arr20()`
* Only read register length in `Engine::get_code_size`
* Add `read_input_borsh()`
* Ensure `method.args.len() == args_decoded.len()`
* Ensure register size is 8 in `read_u64`
* Use constant to specify the register ID used in `read_input()`

* Reduce size of `cargo cache` in CI. (#95)

* Define a `Wei` newtype for balances. (#96)

* Fix evm-bully builds after recent refactoring. (#100)

* Refactor `Engine::get_state` to return a `Result`. (#99)

* Ensure that `Cargo.lock` in the repo is valid. (#101)

* Remove unneeded nightly feature. (#102)

* Implement BC generational storage.

* fix address input

* remove note

* put key on the end of the storage key

* remove pub from methods

* Dispatch precompiles on the full address. (#107)

* Support state migration on upgrade. (#103)

* Implement the ETH connector. (#59)

* Move when to call `set_generation`

* Fix arg

Co-authored-by: Marcelo Fornet <mfornet94@gmail.com>
Co-authored-by: Arto Bendiken <arto@aurora.dev>
Co-authored-by: Michael Birch <michael@near.org>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Evgeny Ukhanov <mrlsd@ya.ru>

* Fix layout of the key

* Fix all tests (don't wipe the storage all the time)

* Use correct generation in writing storage

* Remove unnecessary references

Co-authored-by: Michael Birch <michael@near.org>
Co-authored-by: Joshua J. Bouw <dev@joshuajbouw.com>
Co-authored-by: Arto Bendiken <arto@aurora.dev>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Evgeny Ukhanov <mrlsd@ya.ru>
Co-authored-by: Michael Birch <michael.birch@aurora.dev>
@mrLSD mrLSD requested a review from artob as a code owner June 10, 2021 22:46
@mrLSD mrLSD self-assigned this Jun 10, 2021
@mrLSD mrLSD added the C-enhancement Category: New feature or request label Jun 10, 2021
@mrLSD mrLSD requested a review from sept-en June 10, 2021 22:46
@mrLSD mrLSD marked this pull request as draft June 10, 2021 22:47
@sept-en
Copy link
Contributor

sept-en commented Jun 10, 2021

Nice, thanks for working on this!
Please, make all I/O-related operations in src/lib.rs from the very beginning.
This way it will be easier to separate from business logic and we try to follow this pattern everywhere.

src/migration.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
mrLSD and others added 2 commits June 11, 2021 02:00
Move I/O from business logic

Co-authored-by: Kirill <septengineering@pm.me>
Co-authored-by: Kirill <septengineering@pm.me>
@mfornet
Copy link
Contributor

mfornet commented Jun 11, 2021

Haven't looked into the PR yet, but have few questions regarding the options:

/// Rename key field
RenameKey,
// Rename key and update value
UpdateKeyValue,

What do you mean by rename key? Borsh serialisation doesn't save the name of the fields on the storage. Or you meant something like. Moving value stored at key_1 to key_2 (and deleting key_1)?


// Remove only value for key field
RemoveValue,

What does it do, replace this value with empty sequence of bytes?


I don't know if I'm missing a conversation from some place. But can you provide here high level details (or even technical if necessary) about how are we planning to execute one migration using this changes, before jumping into the implementation.

@mrLSD
Copy link
Member Author

mrLSD commented Jun 11, 2021

Haven't looked into the PR yet, but have few questions regarding the options:

/// Rename key field
RenameKey,
// Rename key and update value
UpdateKeyValue,

What do you mean by rename key? Borsh serialisation doesn't save the name of the fields on the storage. Or you meant something like. Moving value stored at key_1 to key_2 (and deleting key_1)?
It doesn't matter. We can set any kind of key. So we can rename storage key (and don't touch value) and some other useful cases.

// Remove only value for key field
RemoveValue,

What does it do, replace this value with empty sequence of bytes?
yes

I don't know if I'm missing a conversation from some place. But can you provide here high level details (or even technical if necessary) about how are we planning to execute one migration using this changes, before jumping into the implementation.

@sept-en asks me to implement a migration mechanism for changing the storage state.

That logic currently covering all possible cases. Parameters set via json.

@mrLSD
Copy link
Member Author

mrLSD commented Jun 11, 2021

@birchmd Fill free for suggestions and ideas.
The short story is: @sept-en asks me about how to do the migration.
I proposed an idea and started implementation.

@birchmd
Copy link
Member

birchmd commented Jun 11, 2021

This PR feels more like a design proposal and so I think it should be discussed separately from any actual implementation. Hopefully if we all agree on a design first then we can avoid churn on code itself which will save us all time in the long run.

I have enabled GitHub discussions for the Engine repo and created a section called Design where we can talk about designs for new features/functionality.

The discussion for this migration functionality is here: #140
Please feel free to add more details there (e.g. @sept-en @mrLSD if this is something you are pushing for please comment with some pros for having a migration DSL, as opposed to migrations in code itself).

As a general note I think we should be spending more time on design than we currently are. Spending some time on design up-front can hopefully prevent sudden pivots like we have seen recently (e.g. don't burn NEP-141 tokens in connector, generational storage, tracking promise creation in exit precompiles). I know that each of those examples were in response to problems that arose with the implementation, and that a design phase will not always catch all such problems, but at least it gives us a better chance of doing so.

@mfornet
Copy link
Contributor

mfornet commented Jun 13, 2021

@sept-en asks me about how to do the migration. I proposed an idea and started implementation.

@mrLSD Where did you propose this idea, I can't find it anywhere, and the description of the PR doesn't help to it.

That logic currently covering all possible cases. Parameters set via json.

You didn't address the rest of my comments. So you are covering cases that are not described properly, and it is not straight forward to understand how they are going to be used.

Let's continue this conversation in #140 (thanks @birchmd for starting this discussion).

@joshuajbouw
Copy link
Contributor

This PR is stale, whats the status @mrLSD ?

@mrLSD
Copy link
Member Author

mrLSD commented Jul 7, 2021

This PR is stale, whats the status @mrLSD ?

Paused. See #140

@birchmd
Copy link
Member

birchmd commented Oct 4, 2021

Closing this as it is now vastly out of date with current develop branch.

@birchmd birchmd closed this Oct 4, 2021
@joshuajbouw joshuajbouw deleted the feat/migration branch July 11, 2022 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants