-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
This works similarly to to `translate` but only translate a single entry. This function will be useful in the context of multi-block migration.
@pgherveou Command |
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
/// Calls that contribute to advancing the migration have their fees waived, as it's helpful | ||
/// for the chain. Note that while the migration is in progress, the pallet will also | ||
/// leverage the `on_idle` hooks to run migration steps. | ||
#[pallet::call_index(9)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note from talk with Sasha: should we give a different DispatchClass to this call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just asking based on title: could this have been made into something general and reusable?
@kianenigma, it was easier to build it inside the pallet first, but its pretty generic already and I am looking forward to making it a broader solution that can be used by other pallets, once it has been battle tested. |
pls merge master into your branch |
bot merge |
|
||
// Attempt to transfer the old deposit to the deposit account. | ||
let amount = old_deposit | ||
.saturating_sub(min_balance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why subtract min_balance here? if old_deposit < reducible_balance, then tranferring it away from the account should leave it with more than min_balance, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm we could test it again, but I think you need to remove the min_balance that was added in the original deposit to create the account.
* Frame Add translate_next This works similarly to to `translate` but only translate a single entry. This function will be useful in the context of multi-block migration. * Move to lazy migration * Updates * simplify MockMigration * wip * wip * add bench * add bench * fmt * fix bench * add . * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_contracts * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * Scalfold v10 / v11 fix tests * PR comment * tweak pub use * wip * wip * wip * misc merge master * misc merge master * wip * rm tmp stuff * wip * wip * wip * wip * wip * fixes * add state * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * fix * fixed compilation * clean up logs * wip * Revert "Frame Add translate_next" This reverts commit b878662. * Fix v10 logic * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * wip * fixes * exercise del_queue * bump sample size * fmt * wip * blank line * fix lint * fix rustdoc job lint * PR comment do not use dangerous into() * Ad macros for updating mod visibility * Add doc * Add max_weight to integrity_test * fix compilation * Add no migration tests * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_contracts * fix clippy * PR review * Update frame/contracts/src/lib.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Fix master merge * fix merge 2 * fix tryruntime * fix lint --------- Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: command-bot <> Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
* Frame Add translate_next This works similarly to to `translate` but only translate a single entry. This function will be useful in the context of multi-block migration. * Move to lazy migration * Updates * simplify MockMigration * wip * wip * add bench * add bench * fmt * fix bench * add . * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_contracts * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * Scalfold v10 / v11 fix tests * PR comment * tweak pub use * wip * wip * wip * misc merge master * misc merge master * wip * rm tmp stuff * wip * wip * wip * wip * wip * fixes * add state * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * fix * fixed compilation * clean up logs * wip * Revert "Frame Add translate_next" This reverts commit b878662. * Fix v10 logic * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * wip * fixes * exercise del_queue * bump sample size * fmt * wip * blank line * fix lint * fix rustdoc job lint * PR comment do not use dangerous into() * Ad macros for updating mod visibility * Add doc * Add max_weight to integrity_test * fix compilation * Add no migration tests * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_contracts * fix clippy * PR review * Update frame/contracts/src/lib.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Fix master merge * fix merge 2 * fix tryruntime * fix lint --------- Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: command-bot <> Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
Multi-block migration framework for pallet-contracts.
Fix #13638
Test migration with try-runtime
Steps to test against
contracts-rococo
:Instead of testing against a live chain, a snapshot of contracts-rococo running on version 8, can be used for testing.
One could test the migration, with the following snapshot.
contracts-rococo-9420@ed7ddd5b2bc635ff096f3457e18412cf8b7a7d0ca9375ad42aad65dae42c3077.snap.zip
It was generated with this command:
RUST_LOG="try-runtime::cli=debug" ./target/release/polkadot-parachain try-runtime \ --runtime existing \ --chain contracts-rococo \ create-snapshot \ --at 0xed7ddd5b2bc635ff096f3457e18412cf8b7a7d0ca9375ad42aad65dae42c3077 \ --uri ws://localhost:9944
It can be tested with this command
RUST_LOG="runtime::contracts=debug,try-runtime::cli=debug" ./target/release/polkadot-parachain try-runtime \ --runtime target/release/wbuild/contracts-rococo-runtime/contracts_rococo_runtime.wasm \ --chain contracts-rococo \ on-runtime-upgrade snap --snapshot-path ./contracts-rococo-9420@60070dc60358594d0132b82aca52724f0913120002d46d07a72a51850ef282e8.snap
Test migration with zombienet
For testing this migration, I checked out
polkadot-v0.9.32
that runs v8 of pallet-contracts so we can test all migrations steps included in this PR.You can now configure zombienet with
start zombienet with
Before running the migration, I use Polkadot-JS app and upload a dummy smart contract, so we can have some state to migrate. You could try to compile something with Ink, but that might be a bit tricky to get something that can work on such an old version. An easier way is to use
wat2wasm
to compile the dummy contract from pallet-contracts fixtures folder:Then using Polkadot-JS: Developer -> extrinsics -> instantiateWithCode.
In Developer -> Chain state. You should be able to see this data for your storage:
Now that we have setup the stage, we can go ahead and compile the new version of
contracts-rococo
Before compiling make sure you bump the spec version:
Then compile with:
cd parachains/runtimes/contracts/contracts-rococo cargo build --release
target/release/wbuild/contracts-rococo-runtime/contracts_rococo_runtime.compact.compressed.wasm
is the wasm file you want to upload from polkadot.js to test the migrationYou do that, we can use Polkadot-JS app again:
Once the migration is passed you should be able to read this new state:
Find blocks involved in a migration.
I built a custom CLI for that see repo here
Steps to make it a generic migration framework
The migration framework as it is build in this PR lives inside pallet-contracts.
To pull it out of the pallet and create a reusable framework, the following updates should be made:
MigrationInProgress
storage.This storage defines a cursor for the current migration step. If it exists, a migration is in progress.
We check the existence of this value before each dispatchable:
If we move this code to a library, we need to find a way to create this storage from something that is not a pallet
Or have Pallet implements a new trait, let's say MultiblockMigration
Ideally we implement some macros as well so that every Pallet that implements this trait get the ensure code automatically generated.
Once we have that, people can configure their Migration type that they pass to Executive with something like this