-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Update contract multi-block migration #14313
Conversation
Co-authored-by: PG Herveou <pgherveou@gmail.com>
Ensure that we do as many steps as possible given the weight limit passed to on_idle
Co-authored-by: PG Herveou <pgherveou@gmail.com>
Co-authored-by: Juan <juangirini@gmail.com>
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.
Gotta love the docs
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
@agryaznov I think I got them all, thanks for going deep on this review and the previous one 🙏
|
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.
Currently this
substrate/frame/contracts/src/migration.rs
Lines 300 to 306 in 103d50c
log::debug!( | |
target: LOG_TARGET, | |
"{}: Range supported {:?}, range requested {:?}", | |
<Pallet<T>>::name(), | |
T::Migrations::VERSION_RANGE, | |
(storage_version, target_version) | |
); |
prints out a message like this
Contracts: Range supported (12, 12), range requested (StorageVersion(11), StorageVersion(12))
Which imo could cause a cognitive dissonance for a person not quite deep into the MBM implementation details (which I believe could be the most users of the pallet): "requested` (11,12), supported (12,12), but it's okay...".
Maybe it worth making it print supported range like (T::Migrations::VERSION_RANGE.0 - 1, T::Migrations::VERSION_RANGE)
?
Or, even better, to print it in the same fashion as it was specified in the runtime config: "range requested/supported (12,)
"
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
match result { | ||
// There is not enough weight to perform a migration, or make any progress, we | ||
// just return the remaining weight. | ||
NoMigrationPerformed | InProgress { steps_done: 0 } => return remaining_weight, |
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.
Isn't that the same as just break
?
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.
well this case means that there might be a migration in progress, but we did not have enough gas to make any kind of progress, so you want to exit early here, are doing any work in this function is unsafe is there an actual migration going on.
if in_storage == target { | ||
return true | ||
} | ||
if in_storage > target { | ||
return false | ||
} | ||
|
||
let (low, high) = Self::VERSION_RANGE; | ||
let Some(first_supported) = low.checked_sub(1) else { | ||
return false | ||
}; | ||
|
||
in_storage >= first_supported && target == high | ||
target == high && in_storage + 1 == low |
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.
What if no migration is needed and also none is provided? In this case it would return false
and pre_upgrade
will fail even though migrations will be fine.
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.
then you should probably not include it at all in the runtime executive
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.
As long as we can catch the case when somebody forgets to put it back in again this is fine. I suppose try-runtime
will catch this missing migration.
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.
if we want to be lean and embed as little code as possible, we probably want to enforce it, I would be for leaving it like that and adding an explicit message in the pre_upgrade if storage_version == target_version
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.
It does indeed, last time I tried, will test it again here
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.
it is also only invoked in try_runtime, you will get away with just a warning if you were to run such a migration
substrate/frame/contracts/src/migration.rs
Lines 264 to 271 in 921dc43
if storage_version == latest_version { | |
log::warn!( | |
target: LOG_TARGET, | |
"{name}: No Migration performed storage_version = latest_version = {:?}", | |
&storage_version | |
); | |
return T::WeightInfo::on_runtime_upgrade_noop() | |
} |
bot merge |
* move migrate sequence to config * remove commented out code * Update frame/contracts/src/lib.rs Co-authored-by: PG Herveou <pgherveou@gmail.com> * remove Migrations generic * make runtime use noop migrations * restrict is_upgrade_supported * Update contract multi-block migration Ensure that we do as many steps as possible given the weight limit passed to on_idle * undo is_upgrade_supported change * Update bin/node/runtime/src/lib.rs Co-authored-by: PG Herveou <pgherveou@gmail.com> * wip * fix comment (paritytech#14316) * fix test * fix * Update frame/contracts/src/migration.rs Co-authored-by: Juan <juangirini@gmail.com> * fix test doc * Apply suggestions from code review Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Fix compilation with feature runtime-benchmarks * fix example * fix cargo doc --document-private-items * private links * Remove dup comment * add doc for MigrationInProgress * PR review remove duplicate asserts * simplify upper bound * fix link * typo * typo * no unwrap() * correct log message * missing * fix typo * PR comment * Add example with single element tuple * Improve migration message * Update frame/contracts/src/benchmarking/mod.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Update frame/contracts/src/migration.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * Update frame/contracts/src/migration.rs Co-authored-by: Sasha Gryaznov <hi@agryaznov.com> * use saturating_accrue instead of += * add more doc * Contracts: Better migration types (paritytech#14418) * Add explicit error, if try-runtime runs a noop migration * use mut remaining_weight --------- Co-authored-by: Juan Girini <juangirini@gmail.com> Co-authored-by: Sasha Gryaznov <hi@agryaznov.com>
Follow-up to #14045: