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 state upgrades and migration #1050

Merged
merged 3 commits into from
Feb 18, 2020
Merged

Implement state upgrades and migration #1050

merged 3 commits into from
Feb 18, 2020

Conversation

andrevmatos
Copy link
Contributor

@andrevmatos andrevmatos commented Feb 17, 2020

Fix #614
Part of #152

  • A new submodule is implemented: src/migration/
  • State migration functions are implemented as a default exported function in numbered version modules, like src/migration/0.ts, which must always take a state from version N-1 and migrate to state N.
  • This function must then be imported on src/migration/index.ts, and put in a corresponding versioning entry in the migrations mapping object, and is applied with a migrateState function (as any/type-unsafe input & output)
  • src/state/decodeRaidenState function then calls migrateState to apply the needed upgrades in order on the parsed state object, throwing if anything goes wrong in each step, and then validating/decoding the resulting data against current RaidenState schema, throwing if it fails as well
  • 3rd argument of Raiden.create, which previously accepted localStorage xor state, now also supports both through an object in the format { storage; state? }, which can be used to upload a state, to be used instead of the stored one, while keeping localStorage setup (persistence).
  • It fails if trying to load an old state on top of a newer one (determined through blockNumber), and manual state purging is required if one wants to force loading a state (backup) through it
  • Migration is always applied to either stored or uploaded states, ensuring we can continue with previous state on new versions
  • It applies only to state upgrades on the same contracts/blockchain/account. It doesn't help when network upgrades through a new contracts deployment.
  • A set of JSON test files containing an example of minimum and full states for each version, always migrated, decoded & validated to current version, ensures present & future compliance and state upgradeability.

@andrevmatos andrevmatos added enhancement New feature or request sdk 🖥 labels Feb 17, 2020
@codecov
Copy link

codecov bot commented Feb 17, 2020

Codecov Report

Merging #1050 into master will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1050      +/-   ##
==========================================
+ Coverage   96.11%   96.14%   +0.02%     
==========================================
  Files          96       97       +1     
  Lines        3658     3681      +23     
  Branches      776      748      -28     
==========================================
+ Hits         3516     3539      +23     
  Misses         88       88              
  Partials       54       54              
Flag Coverage Δ
#dapp 91.53% <ø> (ø) ⬆️
#sdk 98.01% <97.77%> (+0.01%) ⬆️
Impacted Files Coverage Δ
raiden-ts/src/migration/0.ts 100.00% <0.00%> (ø)

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 c5ed396...9ff190e. Read the comment docs.

Copy link
Contributor

@kelsos kelsos left a comment

Choose a reason for hiding this comment

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

lgtm 👍 thanks

@andrevmatos andrevmatos merged commit 41069c3 into master Feb 18, 2020
@andrevmatos andrevmatos deleted the feat/migration branch February 18, 2020 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sdk 🖥
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement state upgrades
2 participants