-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Migration testing runtime API/Bot #8038
Migration testing runtime API/Bot #8038
Conversation
let heap_pages = Some(1024); | ||
let executor = NativeExecutor::<ExecDispatch>::new(wasm_method, heap_pages, 2); | ||
|
||
let ext = remote_externalities::Builder::new().inject(&[(code_key, code)]).build().await; |
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 .inject
here is where the whole crux of the work happens: inject the real code (i.e. the one that is currently in this repo) into the remote fake state. I should double-check that this is what we want.
This is more or less ready for review. A note about naming: I first called everything in this PR along the lines of To test it out, try either of:
or
and put this file into your substrate root https://drive.google.com/file/d/1WMzYzQREBSlNfPMXcRT33Qq1SKJNqjzf/view?usp=sharing |
type KeyPair = (StorageKey, StorageData); | ||
type Number = u32; | ||
type Hash = sp_core::H256; | ||
// TODO: make these two generic. |
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 would be happy to do this in a future PR. Given that we want to use this initially for known chains, I think it is an overkill for now.
} | ||
|
||
#[async_std::test] | ||
async fn can_load_cache() { |
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.
that binary file (20k) that I bushed will allow us to have at least this one test for this crate.. not sure what to do about it.
Co-authored-by: Alexander Popiak <[email protected]>
Co-authored-by: Alexander Popiak <[email protected]>
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 would highly appreciate a rather nimble review on this as I can use it quite a lot, and not needing to merge this branch into other works is a great luxury.
Note that I think there are lots of improvements to be made, this PR is just setting the foundation. All in all, I envision the TryRuntime
api (all gated by try-runtime
feature) to expose a lot of testing functionalities that would allow a runtime to be deeply diagnosed as a black box.
…' of github.com:paritytech/substrate into kiz-finally-finally-finally-finally-migration-testing-2
|
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 is utils/frame/try-runtime/remote-externalities/proxy_test
?
config.task_executor.clone(), | ||
registry, | ||
config.telemetry_span.clone(), | ||
).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.
out of curiosity, why async here ? instead of sync like we do for benchmarks ?
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.
remote-externalities is working with async/await, my assumption was that in such case you need to use the async_runner 🤔
@@ -273,7 +273,7 @@ pub struct TaskManager { | |||
impl TaskManager { | |||
/// If a Prometheus registry is passed, it will be used to report statistics about the | |||
/// service tasks. | |||
pub(super) fn new( | |||
pub fn new( |
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 looks like a structural change but I don't know that much about the client to say.
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 think it is fine but yeah might be worth asking, maybe @cecton?
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.
Normally you don't need to instantiate this but I guess in your case it makes sense if you want to benefit from the clean shutdown of the TaskManager
🤔 ... so I'm not opposed to it. @expenses maybe has another opinion on this?
On the other hand I'm worried by the tokio runtime created later on. You are creating and running 2 tokio runtimes.
|
…ally-finally-finally-finally-migration-testing-2
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 am pretty happy with this to start with. I expect it may change a bit as it gets used more, but since it is isolated under its own feature flag, seems super reasonable to merge soon.
…ally-finally-finally-finally-migration-testing-2
bot merge |
Waiting for commit status. |
Checks failed; merge aborted. |
…ally-finally-finally-finally-migration-testing-2
bot merge |
Trying merge. |
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 understand why this was merged with tons of unwraps in non-testing code. (Non-testing is everything that is not behind #[cfg(test)]
trace!(target: LOG_TARGET, "rpc: finalized_head"); | ||
let client: sc_rpc_api::chain::ChainClient<Number, Hash, (), ()> = | ||
jsonrpc_core_client::transports::http::connect(&uri).wait().unwrap(); | ||
Ok(client.finalized_head().wait().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.
Unwrap
rt.block_on::<_, _, ()>(futures::lazy(move || { | ||
trace!(target: LOG_TARGET, "rpc: finalized_head"); | ||
let client: sc_rpc_api::chain::ChainClient<Number, Hash, (), ()> = | ||
jsonrpc_core_client::transports::http::connect(&uri).wait().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.
Unwrap
rt.block_on::<_, _, ()>(futures::lazy(move || { | ||
trace!(target: LOG_TARGET, "rpc: storage_pairs: {:?} / {:?}", prefix, at); | ||
let client: sc_rpc_api::state::StateClient<Hash> = | ||
jsonrpc_core_client::transports::http::connect(&uri).wait().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.
And more and more
/// Relay the request to `state_getPairs` rpc endpoint. | ||
/// | ||
/// Note that this is an unsafe RPC. | ||
async fn rpc_get_pairs(&self, prefix: StorageKey, at: Hash) -> Vec<KeyPair> { |
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.
And why do we create a tokio runtime inside an async function!?
Sorry, will fix the unwraps in #8123 😄 the async runtime is discussed here: #8038 (comment) |
# Membership Request Hi, I am Kian Paimani, known as @kianenigma. I have been working on Polkadot/Kusama through Parity since February 2019 and I can categorize my main contributions to Polkadot's ecosystem as follows: 1. Maintaining and developing the staking sub-system. 2. General FRAME development, especially testing and quality assurance. 3. Polkadot-native side-projects. 4. Education > My first contribution to Polkadot is also indeed related to staking: paritytech/substrate#1915 ### Staking system I joke as the Polkadot staking to be both my blessing and my curse over the years. I started working on it since the first days that I joined this ecosystem and the work [is ongoing ever since](https://github.com/orgs/paritytech/projects/33/views/9). In the past, I focused on making sure that the staking system is secure and to some extent scalable. More recently, I coordinated the (imminent) launch of Nomination Pools. Nowadays I also put an extra effort on making sure that this sub-system of Polkadot is *sustainable*, through code refactor and educating other core developers. Lastly, I have been the main author of the [Polkadot staking newsletter](https://gist.github.com/kianenigma/aa835946455b9a3f167821b9d05ba376), which is my main attempt at making the entire complexity and development of this part of the protocol transparent to the end-users. I expect myself to contribute *directly* to the staking system for at least another ~12, if not more, and afterwards having the role of an advisor. Some notable contributions: - paritytech/substrate#4517 - paritytech/substrate#7910 - paritytech/substrate#6242 - paritytech/substrate#9415 - paritytech/polkadot#3141 - paritytech/substrate#11212 - paritytech/substrate#12129 ### FRAME Historically, I have contributed a variety of domains in FRAME, namely: - Early version of the weight system paritytech/substrate#3816 paritytech/substrate#3157 - Early version of the transaction fee system - Primitive arithmetic types paritytech/substrate#3456 - Council election pallet paritytech/substrate#3364 Many of which were, admittedly, a PoC at most, if not considered "poor". I am happy that nowadays many of the above have been refactored and are being maintained by new domain experts. These days, I put most of my FRAME focus on testing and quality assurance. Through my work in the staking system, I have had to deal with the high sensitivity and liveness requirement of protocol development first hand (I believe I had to do among the [very first storage migrations](paritytech/substrate#3948) in Kusama) and consequently I felt the need to make better testing facilities, all of which have been formulated in https://forum.polkadot.network/t/testing-complex-frame-pallets-discussion-tools/356. Some relevant PRs: - paritytech/substrate#8038 - paritytech/substrate#9788 - paritytech/substrate#10174 Regardless of wearing the staking hat, I plan to remain a direct contributor to FRAME, namely because I consider it to be an important requirements of successfully delivering more features to Polkadot's ecosystem. ### Polkadot-Native Side Projects I have started multiple small, mostly non-RUST projects in the polkadot ecosystem that I am very happy about, and I plan to continue doing so. I have not yet found the time to make a "polished product" out of any of these, but I hope that I can help foster our community such that someday a team will do so. I consider my role, for the time being, to *put ideas out there* through these side projects. - https://github.com/substrate-portfolio/polkadot-portfolio/ - https://github.com/kianenigma/polkadot-basic-notification/ - https://github.com/paritytech/polkadot-scripts/ - https://github.com/paritytech/substrate-debug-kit/ ### Education Lastly, aside from having had a number of educational talks over the years (all of which [are listed](https://hello.kianenigma.nl/talks/) in my personal website), I am a big enthusiast of the newly formed Polkadot Blockchain Academy. I have [been an instructor](https://singular.app/collectibles/statemine/16/2) in the first cohort, and continue to contribute for as long and as much as I can, whilst still attending to the former 3 duties. --- With all of that being said and done, I consider myself at the beginning of the path to Dan 4, but happy to start at a lower one as well.
# Membership Request Hi, I am Kian Paimani, known as @kianenigma. I have been working on Polkadot/Kusama through Parity since February 2019 and I can categorize my main contributions to Polkadot's ecosystem as follows: 1. Maintaining and developing the staking sub-system. 2. General FRAME development, especially testing and quality assurance. 3. Polkadot-native side-projects. 4. Education > My first contribution to Polkadot is also indeed related to staking: paritytech/substrate#1915 ### Staking system I joke as the Polkadot staking to be both my blessing and my curse over the years. I started working on it since the first days that I joined this ecosystem and the work [is ongoing ever since](https://github.com/orgs/paritytech/projects/33/views/9). In the past, I focused on making sure that the staking system is secure and to some extent scalable. More recently, I coordinated the (imminent) launch of Nomination Pools. Nowadays I also put an extra effort on making sure that this sub-system of Polkadot is *sustainable*, through code refactor and educating other core developers. Lastly, I have been the main author of the [Polkadot staking newsletter](https://gist.github.com/kianenigma/aa835946455b9a3f167821b9d05ba376), which is my main attempt at making the entire complexity and development of this part of the protocol transparent to the end-users. I expect myself to contribute *directly* to the staking system for at least another ~12, if not more, and afterwards having the role of an advisor. Some notable contributions: - paritytech/substrate#4517 - paritytech/substrate#7910 - paritytech/substrate#6242 - paritytech/substrate#9415 - paritytech/polkadot#3141 - paritytech/substrate#11212 - paritytech/substrate#12129 ### FRAME Historically, I have contributed a variety of domains in FRAME, namely: - Early version of the weight system paritytech/substrate#3816 paritytech/substrate#3157 - Early version of the transaction fee system - Primitive arithmetic types paritytech/substrate#3456 - Council election pallet paritytech/substrate#3364 Many of which were, admittedly, a PoC at most, if not considered "poor". I am happy that nowadays many of the above have been refactored and are being maintained by new domain experts. These days, I put most of my FRAME focus on testing and quality assurance. Through my work in the staking system, I have had to deal with the high sensitivity and liveness requirement of protocol development first hand (I believe I had to do among the [very first storage migrations](paritytech/substrate#3948) in Kusama) and consequently I felt the need to make better testing facilities, all of which have been formulated in https://forum.polkadot.network/t/testing-complex-frame-pallets-discussion-tools/356. Some relevant PRs: - paritytech/substrate#8038 - paritytech/substrate#9788 - paritytech/substrate#10174 Regardless of wearing the staking hat, I plan to remain a direct contributor to FRAME, namely because I consider it to be an important requirements of successfully delivering more features to Polkadot's ecosystem. ### Polkadot-Native Side Projects I have started multiple small, mostly non-RUST projects in the polkadot ecosystem that I am very happy about, and I plan to continue doing so. I have not yet found the time to make a "polished product" out of any of these, but I hope that I can help foster our community such that someday a team will do so. I consider my role, for the time being, to *put ideas out there* through these side projects. - https://github.com/substrate-portfolio/polkadot-portfolio/ - https://github.com/kianenigma/polkadot-basic-notification/ - https://github.com/paritytech/polkadot-scripts/ - https://github.com/paritytech/substrate-debug-kit/ ### Education Lastly, aside from having had a number of educational talks over the years (all of which [are listed](https://hello.kianenigma.nl/talks/) in my personal website), I am a big enthusiast of the newly formed Polkadot Blockchain Academy. I have [been an instructor](https://singular.app/collectibles/statemine/16/2) in the first cohort, and continue to contribute for as long and as much as I can, whilst still attending to the former 3 duties. --- With all of that being said and done, I consider myself at the beginning of the path to Dan 4, but happy to start at a lower one as well. Co-authored-by: Bastian Köcher <[email protected]>
A quick and dirty, but functioning attempt at making an end to end runtime api that can be triggered by a bot to test all the
OnRuntimeUpgrade
implementations inside a runtime, including two newly added hooks for some pre-and-post checks. I have one example of how these can work here: paritytech/polkadot@146f1e2#diff-db5840c3c03c740de25aed56b9257559c224a04619c079c94cddbb23f9a855a4R961Given that it works now, I see this as a leaner and more minimalistic approach compared to #7665, but we can replace parts of this PR with test-runner once it is compatible.
My vision with this work is:
OnRuntimeUpgrade
of a particular pallet to be executed against the live state of any chain:\migration_bot run target:pallet-staking source:remote('http://remote-host:9933')
.\migration_bot run target:all cache('./path-to-cache-file.bin')
.Current branch works fine, just needs a clean-up and configurability + making a few things generic (e.g. I assume
Hash = H256
which is not good). In its current state, runningcargo run -- dry-run --target all -lremote-ext=debug
will yield something like:You can try the same, if you have a locally running node.
If this line of work is deemed okay, I will continue with cleaning the code, and making a companion PR that adds the same subcommand to polkadot as well.
CC @apopiak @seunlanlege @bkchr @shawntabrizi