-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[Feature] Sequential migration execution for try-runtime #12319
[Feature] Sequential migration execution for try-runtime #12319
Conversation
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.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.
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Just removed the redundant calls to pre/post. Because all of this is happening in |
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.
This was also annoying me, thanks for changing it!
frame/support/src/traits/hooks.rs
Outdated
@@ -22,6 +22,7 @@ use impl_trait_for_tuples::impl_for_tuples; | |||
use sp_runtime::traits::AtLeast32BitUnsigned; | |||
use sp_std::prelude::*; | |||
|
|||
#[cfg(test)] |
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 you want to achieve here? That this is also enabled when we are compiling the tests?
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.
This has to be enabled only when it's both test
and try-runtime
and is exactly what it currently does.
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.
To give some context:
#[cfg(feature = "try-runtime")]
use codec::{Decode, Encode};
Will give an unused import error, because this import is only used within tests, so when we are building with try-runtime - there's a warning emitted and build fails.
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.
To give a bit more context cargo remote -- test --features=try-runtime
this is the only time this import has to be enabled.
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.
#[cfg(all(feature = "try-runtime", test))]
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.
yeah, I was looking for that :)
frame/support/src/traits/hooks.rs
Outdated
// expected unwrap: we want to panic if any checks fail right here right now. | ||
let state = Tuple::pre_upgrade().unwrap(); |
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.
Probably better to just have some new on_runtime_upgrade_with_pre_and_post
that returns a result. (the name is for sure shit!)
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.
To be fair I'm not sure if this is needed, try-runtime is used for testing. If any of the checks panic - it's they need to be fixed. Seems like extra complexity to come up with another method that does have a Result return type just for the sake of a couple of unwraps.
On the other hand it hurts readability a little bit.
If I'm being honest I just don't want to add yet another method to this interface and make things more confusing for future implementors.
Correct me if I'm wrong, you are proposing to add an extra method on OnRuntimeUpgrade
when try-runtime
.
The one that's going to be called instead of on_runtime_upgrade
for try-runtime
scenarios.
Alternatively we could introduce this method and still call it in on_runtime_upgrade
, but then we'd have to unwrap anyway, so there is no point.
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 @bkchr's point is to only prevent unwrap()
, I disagree.
If there's more benefit in the new method, I am all ears.
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.
My point here was to prevent the unwrap. However, if we keep it. I demand a expect
that provides more context, at least like the index of the tuple to have some idea what failed.
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.
We've discussed it before and I think the real answer here is RUST_BACKTRACE=1
, which gives you exactly the failing line. That being said, @ruseinov can you please update the unwraps to expect?
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.
My point here was to prevent the unwrap. However, if we keep it. I demand a
expect
that provides more context, at least like the index of the tuple to have some idea what failed.
Will do!
Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
bot rebase |
Rebased |
assert_eq!(<u32 as Decode>::decode(&mut nested_states[0].as_slice()).unwrap(), 100u32); | ||
assert_eq!(<bool as Decode>::decode(&mut nested_states[1].as_slice()).unwrap(), true); | ||
<TestNested123 as OnRuntimeUpgrade>::post_upgrade(origin_state).unwrap(); | ||
TestExternalities::default().execute_with(|| { |
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.
This test is not quite needed anymore as we don't combine the outputs anymore.
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.
I mean, it is nice that we're testing impl_trait_for_tuples
, but I think it should be more meaningful.
For example, with the new logic, I would test the following:
- if
feature = try-runtime
, pre-migrate has been run. You can assert this by writing to some static value inpre_migrate
- if if
not(feature = try-runtime)
, they don't happen. You can test this by making sure aOnRuntimeUpgrade
that panicspre_upgrade
runs fine innot(feature = try-runtime)
.
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.
I don’t see a reason to introduce those tbh. try-runtime methods are feature-gated, so are the tests. We can’t test feature-gated stuff in a non-feature-gated test.
We have assertions in the test implementations of OnRuntimeUpgrade trait and I think it’s totally valid to test all those scenarios to see that things have been executed with nested tuples, for example.
frame/support/src/traits/hooks.rs
Outdated
weight = weight.saturating_add(Tuple::on_runtime_upgrade()); | ||
|
||
let _guard = frame_support::StorageNoopGuard::default(); | ||
// expected unwrap: we want to panic if any checks fail right here right now. |
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.
bad indentation (my bad)
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.
Tests need rework, logic all good.
bot merge |
Waiting for commit status. |
* master: [Fix] parameter_types! dead code errors (#12340) [Feature] Sequential migration execution for try-runtime (#12319) bench: Use `_` instead of `::` in auto-generated file names (#12332) Fast Unstake Pallet (#12129) Rename anonymous to pure proxy (#12283) Migrate remaining old decl_* macros to the new pallet attribute macros (#12271) pallet-utility: Disallow none origin (#12321) Make automatic storage deposits resistant against changing deposit prices (#12083) Format templates and fix `--steps` default value (#12286) Bump `wasmtime` to 1.0.0 (#12317) Introduce 'intermediate_insert' method to hide implementation details (#12215) Bound staking storage items (#12230) Use `array-bytes` for All Array/Bytes/Hex Operations (#12190) BREAKING: Rename Origin (#12258) Use temporary db for benchmarking (#12254) rpc: Implement `chainSpec` RPC API (#12261) Import target block body during warp sync (#12300) Proper naming wrt expectations (#12311) [ci] Revert cancel-pipeline job (#12309)
…12319) * [Feature] Sequential migration execution for try-runtime * remove unused * guards * reinstate encode/decode * proper feature gate * proper test feature gate * Update frame/support/src/traits/hooks.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/support/src/traits/hooks.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * fix tests * redo Tuple tests * Update frame/support/src/traits/hooks.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * use parameter_types for testing * lint fix * Update frame/support/src/traits/hooks.rs Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> * Update frame/support/src/traits/hooks.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * eloquent feature gate * redo tests * more fixes * properly handle pre/post errors * remove some tests and fix the others * add format import * import fix * more import fixes Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: parity-processbot <>
Fixes #12295
@bkchr let me know if that's what you had in mind.