Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[Feature] Sequential migration execution for try-runtime #12319

Merged
merged 24 commits into from
Sep 23, 2022

Conversation

ruseinov
Copy link
Contributor

@ruseinov ruseinov commented Sep 21, 2022

Fixes #12295

@bkchr let me know if that's what you had in mind.

@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Sep 21, 2022
@ruseinov ruseinov added B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. labels Sep 21, 2022
@ruseinov ruseinov added the D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. label Sep 21, 2022
ruseinov and others added 4 commits September 21, 2022 16:48
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

You should now be able to bring back this commit and it should work? cc @Ank4n

635bada

Logic def. sounds good, but not sure what is going on in the tests, have to look later.

Also, please add to the right project :p

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
@ruseinov
Copy link
Contributor Author

Logic def. sounds good, but not sure what is going on in the tests, have to look later.

Just removed the redundant calls to pre/post. Because all of this is happening in on_runtime_upgrade now and the state is being passed from one to another there too, sequentially.

Copy link
Member

@ggwpez ggwpez left a 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 Show resolved Hide resolved
@@ -22,6 +22,7 @@ use impl_trait_for_tuples::impl_for_tuples;
use sp_runtime::traits::AtLeast32BitUnsigned;
use sp_std::prelude::*;

#[cfg(test)]
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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))]

Copy link
Contributor Author

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 :)

Comment on lines 184 to 185
// expected unwrap: we want to panic if any checks fail right here right now.
let state = Tuple::pre_upgrade().unwrap();
Copy link
Member

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!)

Copy link
Contributor Author

@ruseinov ruseinov Sep 22, 2022

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.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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!

ruseinov and others added 2 commits September 22, 2022 16:08
Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ruseinov
Copy link
Contributor Author

bot rebase

@paritytech-processbot
Copy link

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(|| {
Copy link
Contributor

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.

Copy link
Contributor

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:

  1. if feature = try-runtime, pre-migrate has been run. You can assert this by writing to some static value in pre_migrate
  2. if if not(feature = try-runtime), they don't happen. You can test this by making sure a OnRuntimeUpgrade that panics pre_upgrade runs fine in not(feature = try-runtime).

Copy link
Contributor Author

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.

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

bad indentation (my bad)

Copy link
Contributor

@kianenigma kianenigma left a 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.

@ruseinov
Copy link
Contributor Author

bot merge

@paritytech-processbot
Copy link

Waiting for commit status.

@paritytech-processbot paritytech-processbot bot merged commit 8161ee1 into master Sep 23, 2022
@paritytech-processbot paritytech-processbot bot deleted the ru/feature/try-runtime-sequential branch September 23, 2022 14:30
ordian added a commit that referenced this pull request Sep 23, 2022
* 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)
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
…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 <>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Improvement] Make sure try-runtime executes migrations and their pre/post checks sequentially.
5 participants