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

[try-runtime-cli] Offchain worker support #8966

Merged
63 commits merged into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
c9333bd
make remote-ext work with ws and safe RPCs
kianenigma May 24, 2021
5a99270
Update docs.
kianenigma May 24, 2021
287126b
Update utils/frame/remote-externalities/Cargo.toml
kianenigma May 24, 2021
d2b0f48
Fix test
kianenigma May 24, 2021
b33ce8c
Merge branch 'kiz-remote-ext-paged' of github.com:paritytech/substrat…
kianenigma May 24, 2021
ab106bd
Update lock file
kianenigma May 24, 2021
0b3415d
Update utils/frame/remote-externalities/src/lib.rs
kianenigma May 25, 2021
22959b0
Fix build again.
kianenigma May 25, 2021
e7bf17d
checkpoint, merging the paged rpc now
kianenigma May 25, 2021
9724ce7
revert lifetime stuff
kianenigma May 25, 2021
832f4ce
Seems to be merged, dropping to do other more important stuff now
kianenigma May 25, 2021
70a04cb
Master.into()
kianenigma May 26, 2021
c6e1315
Merge remote-tracking branch 'origin' into zeke-kiz-try-runtime-offch…
emostov May 27, 2021
9cc0667
WIP: remote client init not working
emostov May 27, 2021
892e8c5
Small cleanups
emostov May 27, 2021
fe9ced0
use jsonrpsee alpha.7
emostov May 27, 2021
13f9200
WIP
emostov May 28, 2021
240dbc4
Try merge origin master
emostov May 31, 2021
ea13bff
Executiing without errors
emostov May 31, 2021
a126828
Reorg & cleanup
emostov Jun 1, 2021
2746f69
Trivial cleaning
emostov Jun 1, 2021
0961bd4
Add txpool & keystore extension
emostov Jun 1, 2021
b5fbe9d
Try merge origin master
emostov Jun 2, 2021
99fdf47
Small cleaning
emostov Jun 2, 2021
6b5ae7f
More :cleaning
emostov Jun 2, 2021
6e3746e
Flags: page-size, override-code
emostov Jun 4, 2021
6e352c4
WIP
emostov Jun 4, 2021
c1487a9
Merge remote-tracking branch 'origin' into zeke-kiz-try-runtime-offch…
emostov Jun 4, 2021
0d54943
Apply suggestions from code review
emostov Jun 4, 2021
650a470
Merge branch 'zeke-kiz-try-runtime-offchain-worker' of https://github…
emostov Jun 4, 2021
d63e364
Remove heap_pages
emostov Jun 4, 2021
a27219f
Dry code extraction from state
emostov Jun 4, 2021
8adf25f
Formatting
emostov Jun 4, 2021
7ed2c48
More formatting
emostov Jun 4, 2021
773b1d2
Add issue todo
emostov Jun 4, 2021
eec51c5
Use jsonrpsee 0.2.0
emostov Jun 4, 2021
045c7a1
Merge remote-tracking branch 'origin' into zeke-kiz-try-runtime-offch…
emostov Jun 4, 2021
d394b1e
Try trigger gitlab
emostov Jun 5, 2021
0d85d13
Fix "block_import_works" test
emostov Jun 5, 2021
83586b2
fix native_big_block_import_fails_on_fallback test
emostov Jun 5, 2021
59eae13
fix commit should work
emostov Jun 5, 2021
ada7f67
Rewrite UI tests
emostov Jun 5, 2021
31b9a31
Revert "Rewrite UI tests"
emostov Jun 5, 2021
fad9c5d
try again with UI
emostov Jun 5, 2021
0e8975b
Use const for legacy heap pages val
emostov Jun 7, 2021
62a996d
Move parse module to its own file
emostov Jun 7, 2021
de5084d
Move rpc_api module to its own file
emostov Jun 7, 2021
2f119f8
Apply suggestions from code review
emostov Jun 7, 2021
bb15b97
trait names: Block, not B
emostov Jun 7, 2021
81da802
Corect HEAP_PAGES_TEST_LEGACY export
emostov Jun 7, 2021
8613ed0
Update utils/frame/remote-externalities/src/rpc_api.rs
emostov Jun 8, 2021
f57f9ae
Revert test_ext heap_page insert; adjust storage root instead
emostov Jun 8, 2021
dce60d9
Merge branch 'zeke-kiz-try-runtime-offchain-worker' of https://github…
emostov Jun 8, 2021
0b639a4
Try merge origin master
emostov Jun 8, 2021
d722a45
Doc comments for try_runtime::cli::Command
emostov Jun 8, 2021
d84540a
TryRuntime stub
emostov Jun 8, 2021
4808572
trailing comma
emostov Jun 8, 2021
dc3041d
Remove unused dev dep in frame-executive
emostov Jun 8, 2021
894df17
Improve parse::hash variable name & error index
emostov Jun 8, 2021
60123c9
Use Result for rpc_api fns
emostov Jun 8, 2021
699ea3f
Richer err messagges
emostov Jun 8, 2021
485cd83
Remove HEAP_PAGE_TEST_LEGACY
emostov Jun 9, 2021
b792e5c
Update bin/node/executor/tests/basic.rs
bkchr Jun 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
427 changes: 260 additions & 167 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions bin/node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ pub enum Subcommand {
#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),

/// Try some experimental command on the runtime. This includes migration and runtime-upgrade
/// testing.
/// Try some experimental command on the runtime. Note: `try-runtime` feature must be enabled.
#[cfg(feature = "try-runtime")]
TryRuntime(try_runtime_cli::TryRuntimeCmd),

Expand Down
2 changes: 2 additions & 0 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@ fn native_big_block_import_succeeds() {
fn native_big_block_import_fails_on_fallback() {
let mut t = new_test_ext(compact_code_unwrap(), false);

set_heap_pages(&mut t.ext(), sp_state_machine::HEAP_PAGES_TEST_LEGACY);
emostov marked this conversation as resolved.
Show resolved Hide resolved

assert!(
executor_call::<NeverNativeValue, fn() -> _>(
&mut t,
Expand Down
1 change: 1 addition & 0 deletions frame/executive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pallet-balances = { version = "3.0.0", path = "../balances" }
pallet-transaction-payment = { version = "3.0.0", path = "../transaction-payment" }
sp-version = { version = "3.0.0", path = "../../primitives/version" }
sp-inherents = { version = "3.0.0", path = "../../primitives/inherents" }
sp-state-machine = { version = "0.9.0", default-features = false, path = "../../primitives/state-machine" }
emostov marked this conversation as resolved.
Show resolved Hide resolved

[features]
default = ["std"]
Expand Down
4 changes: 4 additions & 0 deletions frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,11 @@ mod tests {
}

fn new_test_ext(balance_factor: Balance) -> sp_io::TestExternalities {
use sp_core::storage::well_known_keys::HEAP_PAGES;
use sp_state_machine::HEAP_PAGES_TEST_LEGACY;

let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
t.top.insert(HEAP_PAGES.to_vec(), HEAP_PAGES_TEST_LEGACY.encode());
pallet_balances::GenesisConfig::<Runtime> {
balances: vec![(1, 111 * balance_factor)],
}.assimilate_storage(&mut t).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion primitives/state-machine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ mod changes_trie {
#[cfg(feature = "std")]
mod std_reexport {
pub use sp_trie::{trie_types::{Layout, TrieDBMut}, StorageProof, TrieMut, DBValue, MemoryDB};
pub use crate::testing::TestExternalities;
pub use crate::testing::{TestExternalities, HEAP_PAGES_TEST_LEGACY};
pub use crate::basic::BasicExternalities;
pub use crate::read_only::{ReadOnlyExternalities, InspectState};
pub use crate::changes_trie::{
Expand Down
11 changes: 7 additions & 4 deletions primitives/state-machine/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ use crate::{
},
};

use codec::{Decode, Encode};
use codec::Decode;
use hash_db::Hasher;
use sp_core::{
offchain::testing::TestPersistentOffchainDB,
storage::{
well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES, is_child_storage_key},
well_known_keys::{CHANGES_TRIE_CONFIG, CODE, is_child_storage_key},
Storage,
},
traits::TaskExecutorExt,
testing::TaskExecutor,
};
use sp_externalities::{Extensions, Extension, ExtensionStore};

/// Legacy default value in `TestExternalities::new_with_code` for `:heap_pages`.
/// `:heap_pages` must now be explicitly set to this value.
pub const HEAP_PAGES_TEST_LEGACY: u64 = 8;
emostov marked this conversation as resolved.
Show resolved Hide resolved

/// Simple HashMap-based Externalities impl.
pub struct TestExternalities<H: Hasher, N: ChangesTrieBlockNumber = u64>
where
Expand Down Expand Up @@ -103,7 +107,6 @@ where
assert!(storage.top.keys().all(|key| !is_child_storage_key(key)));
assert!(storage.children_default.keys().all(|key| is_child_storage_key(key)));

storage.top.insert(HEAP_PAGES.to_vec(), 8u64.encode());
storage.top.insert(CODE.to_vec(), code.to_vec());

let mut extensions = Extensions::default();
Expand Down Expand Up @@ -308,7 +311,7 @@ mod tests {
ext.set_storage(b"doe".to_vec(), b"reindeer".to_vec());
ext.set_storage(b"dog".to_vec(), b"puppy".to_vec());
ext.set_storage(b"dogglesworth".to_vec(), b"cat".to_vec());
let root = H256::from(hex!("2a340d3dfd52f5992c6b117e9e45f479e6da5afffafeb26ab619cf137a95aeb8"));
let root = H256::from(hex!("ed4d8c799d996add422395a6abd7545491d40bd838d738afafa1b8a4de625489"));
assert_eq!(H256::from_slice(ext.storage_root().as_slice()), root);
}

Expand Down
8 changes: 4 additions & 4 deletions utils/frame/remote-externalities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
jsonrpsee-ws-client = { version = "=0.2.0-alpha.6", default-features = false }
jsonrpsee-proc-macros = "=0.2.0-alpha.6"
jsonrpsee-ws-client = { version = "0.2.0", default-features = false, features = ["tokio02"] }
jsonrpsee-proc-macros = "0.2.0"

hex = "0.4.0"
env_logger = "0.8.2"
log = "0.4.11"
codec = { package = "parity-scale-codec", version = "2.0.0" }

serde_json = "1.0"
serde = "1.0.0"

sp-io = { version = "3.0.0", path = "../../../primitives/io" }
sp-core = { version = "3.0.0", path = "../../../primitives/core" }
sp-runtime = { version = "3.0.0", path = "../../../primitives/runtime" }

[dev-dependencies]
tokio = { version = "1.6.0", features = ["macros", "rt"] }
emostov marked this conversation as resolved.
Show resolved Hide resolved
tokio = { version = "0.2", features = ["full"] }
pallet-elections-phragmen = { path = "../../../frame/elections-phragmen", version = "4.0.0" }
frame-support = { path = "../../../frame/support", version = "3.0.0" }

Expand Down
27 changes: 17 additions & 10 deletions utils/frame/remote-externalities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ use sp_core::{
use codec::{Encode, Decode};
use sp_runtime::traits::Block as BlockT;
use jsonrpsee_ws_client::{
WsClientBuilder, WsClient, v2::params::JsonRpcParams, traits::Client,
WsClientBuilder, WsClient, v2::params::JsonRpcParams,
};

pub mod rpc_api;

type KeyPair = (StorageKey, StorageData);

const LOG_TARGET: &str = "remote-ext";
Expand Down Expand Up @@ -72,7 +74,7 @@ impl<B: BlockT> Default for Mode<B> {
}
}

/// configuration of the online execution.
/// Configuration of the offline execution.
///
/// A state snapshot config must be present.
#[derive(Clone)]
Expand All @@ -81,7 +83,7 @@ pub struct OfflineConfig {
pub state_snapshot: SnapshotConfig,
}

/// Description of the transport protocol.
/// Description of the transport protocol (for online execution).
#[derive(Debug)]
pub struct Transport {
uri: String,
Expand Down Expand Up @@ -115,23 +117,24 @@ pub struct OnlineConfig<B: BlockT> {
pub transport: Transport,
}

impl<B: BlockT> OnlineConfig<B> {
/// Return rpc (ws) client.
fn rpc_client(&self) -> &WsClient {
self.transport.client.as_ref().expect("ws client must have been initialized by now; qed.")
}
}

impl<B: BlockT> Default for OnlineConfig<B> {
fn default() -> Self {
Self {
transport: Transport { uri: DEFAULT_TARGET.to_string(), client: None },
transport: Transport { uri: DEFAULT_TARGET.to_owned(), client: None },
at: None,
state_snapshot: None,
modules: vec![],
}
}
}

impl<B: BlockT> OnlineConfig<B> {
/// Return rpc (ws) client.
fn rpc_client(&self) -> &WsClient {
self.transport.client.as_ref().expect("ws client must have been initialized by now; qed.")
}
}

/// Configuration of the state snapshot.
#[derive(Clone)]
Expand Down Expand Up @@ -189,6 +192,7 @@ impl<B: BlockT> Builder<B> {

// RPC methods
impl<B: BlockT> Builder<B> {
/// Get the latest finalized head.
async fn rpc_get_head(&self) -> Result<B::Hash, &'static str> {
trace!(target: LOG_TARGET, "rpc: finalized_head");
RpcApi::<B>::finalized_head(self.as_online().rpc_client()).await.map_err(|e| {
Expand Down Expand Up @@ -250,6 +254,7 @@ impl<B: BlockT> Builder<B> {
prefix: StorageKey,
at: B::Hash,
) -> Result<Vec<KeyPair>, &'static str> {
use jsonrpsee_ws_client::traits::Client;
use serde_json::to_value;
let keys = self.get_keys_paged(prefix, at).await?;
let keys_count = keys.len();
Expand Down Expand Up @@ -438,8 +443,10 @@ impl<B: BlockT> Builder<B> {
info!(target: LOG_TARGET, "injecting a total of {} keys", kv.len());
for (k, v) in kv {
let (k, v) = (k.0, v.0);
// Insert the key,value pair into the test trie backend
ext.insert(k, v);
}

Ok(ext)
}
}
Expand Down
47 changes: 47 additions & 0 deletions utils/frame/remote-externalities/src/rpc_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// This file is part of Substrate.

// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
emostov marked this conversation as resolved.
Show resolved Hide resolved
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! WS RPC API for one off RPC calls to a substrate node.
// TODO: Consolidate one off RPC calls https://github.com/paritytech/substrate/issues/8988

use super::*;

/// Get the header of the block identified by `at`
pub async fn get_header<B: BlockT, S: AsRef<str>>(from: S, at: B::Hash) -> B::Header
where
B::Header: serde::de::DeserializeOwned,
{
use jsonrpsee_ws_client::traits::Client;
let params = vec![serde_json::to_value(at).unwrap()];
emostov marked this conversation as resolved.
Show resolved Hide resolved
let client = WsClientBuilder::default()
.max_request_body_size(u32::MAX)
.build(from.as_ref())
.await
.unwrap();
emostov marked this conversation as resolved.
Show resolved Hide resolved
client.request::<B::Header>("chain_getHeader", JsonRpcParams::Array(params)).await.unwrap()
emostov marked this conversation as resolved.
Show resolved Hide resolved
}

/// Get the finalized head
pub async fn get_finalized_head<B: BlockT, S: AsRef<str>>(from: S) -> B::Hash {
use jsonrpsee_ws_client::traits::Client;
let client = WsClientBuilder::default()
.max_request_body_size(u32::MAX)
.build(from.as_ref())
.await
.unwrap();
client.request::<B::Hash>("chain_getFinalizedHead", JsonRpcParams::NoParams).await.unwrap()
emostov marked this conversation as resolved.
Show resolved Hide resolved
}
5 changes: 4 additions & 1 deletion utils/frame/try-runtime/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
log = "0.4.8"
parity-scale-codec = { version = "2.0.0" }
serde = "1.0.0"
structopt = "0.3.8"

sc-service = { version = "0.9.0", default-features = false, path = "../../../../client/service" }
sc-cli = { version = "0.9.0", path = "../../../../client/cli" }
sc-executor = { version = "0.9.0", path = "../../../../client/executor" }
sc-client-api = { version = "3.0.0", path = "../../../../client/api" }
structopt = "0.3.8"
sc-chain-spec = { version = "3.0.0", path = "../../../../client/chain-spec" }
sp-state-machine = { version = "0.9.0", path = "../../../../primitives/state-machine" }
sp-api = { version = "3.0.0", path = "../../../../primitives/api" }
sp-blockchain = { version = "3.0.0", path = "../../../../primitives/blockchain" }
sp-runtime = { version = "3.0.0", path = "../../../../primitives/runtime" }
sp-externalities = { version = "0.9.0", path = "../../../../primitives/externalities" }
sp-core = { version = "3.0.0", path = "../../../../primitives/core" }
sp-keystore = { version = "0.9.0", path = "../../../../primitives/keystore" }
frame-try-runtime = { version = "0.9.0", path = "../../../../frame/try-runtime" }

remote-externalities = { version = "0.9.0", path = "../../remote-externalities" }
Loading