Skip to content

Commit d0e69c8

Browse files
committed
Fix WS/HTTP URI mismatch for live commands
Live mode works with either ws(s):// or http(s):// in --uri. The endpoint is converted to HTTP for state download and to WS for block/header RPC. This is a temporary workaround until frame-remote-externalities restores proper WS transport support in a future release; see paritytech/polkadot-sdk#10258, paritytech/polkadot-sdk#10766, and paritytech/polkadot-sdk#10779 .
1 parent 7113f1d commit d0e69c8

12 files changed

Lines changed: 79 additions & 616 deletions

File tree

Cargo.lock

Lines changed: 6 additions & 586 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ hex = { version = "0.4.3", default-features = false }
2424
itertools = { version = "~0.14" }
2525
log = { version = "~0.4.29" }
2626
parity-scale-codec = { version = "~3.7" }
27+
jsonrpsee = { version = "~0.24", features = ["http-client"] }
2728
regex = { version = "~1.12" }
2829
serde = { version = "~1.0" }
2930
serde_json = { version = "~1.0" }
@@ -69,8 +70,8 @@ sp-weights = { version = "33.2.0" }
6970
substrate-rpc-client = { version = "0.54.0" }
7071

7172
polkadot-primitives = { version = "22.0.0" }
72-
cumulus-primitives-parachain-inherent = { version = "0.22.0" }
73-
cumulus-primitives-core = { version = "0.22.0" }
73+
cumulus-primitives-parachain-inherent = { version = "0.23.0" }
74+
cumulus-primitives-core = { version = "0.23.0" }
7475
cumulus-client-parachain-inherent = { version = "0.22.0" }
7576

7677
# Local

cli/tests/create_snapshot.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ use tokio::process::Command;
3535
#[tokio::test]
3636
async fn create_snapshot_works() {
3737
let port = 45789;
38-
let ws_url = format!("ws://localhost:{}", port);
38+
let ws_uri = format!("ws://localhost:{}", port);
39+
let http_uri = format!("http://localhost:{}", port);
3940

4041
// Spawn a dev node.
4142
let _ = std::thread::spawn(move || {
@@ -66,29 +67,35 @@ async fn create_snapshot_works() {
6667

6768
common::run_with_timeout(Duration::from_secs(60), async move {
6869
fn create_snapshot(
69-
ws_url: &str,
70+
uri: &str,
7071
snap_file: &PathBuf,
7172
at: sp_core::H256,
7273
) -> tokio::process::Child {
7374
Command::new(cargo_bin!("try-runtime"))
7475
.stdout(std::process::Stdio::piped())
7576
.stderr(std::process::Stdio::piped())
7677
.arg("--runtime=existing")
77-
.args(["create-snapshot", format!("--uri={}", ws_url).as_str()])
78+
.args(["create-snapshot", format!("--uri={}", uri).as_str()])
7879
.arg(snap_file)
7980
.args(["--at", format!("{:?}", at).as_str()])
8081
.kill_on_drop(true)
8182
.spawn()
8283
.unwrap()
8384
}
8485
let block_number = 2;
85-
let block_hash = common::block_hash(block_number, &ws_url).await.unwrap();
86+
let block_hash = common::block_hash(block_number, &ws_uri).await.unwrap();
8687

8788
// Try to create a snapshot.
88-
let child = create_snapshot(&ws_url, &snap_file_path, block_hash);
89+
let child = create_snapshot(&http_uri, &snap_file_path, block_hash);
8990
let out = child.wait_with_output().await.unwrap();
90-
91-
assert!(out.status.success());
91+
assert!(
92+
out.status.success(),
93+
"try-runtime exited unsuccessfully: status={:?}, code={:?}\n\nstdout:\n{}\n\nstderr:\n{}",
94+
out.status,
95+
out.status.code(),
96+
String::from_utf8_lossy(&out.stdout),
97+
String::from_utf8_lossy(&out.stderr),
98+
);
9299

93100
let snapshot_is_on_disk = Path::new(&snap_file_path).exists();
94101
assert!(snapshot_is_on_disk, "Snapshot was not written to disk");

cli/tests/execute_block.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,26 @@ async fn execute_block_works() {
5050

5151
// Test passing --at
5252
common::run_with_timeout(Duration::from_secs(60), async move {
53-
let ws_url = format!("ws://localhost:{}", port);
53+
let ws_uri = format!("ws://localhost:{}", port);
5454

55-
fn execute_block(ws_url: &str, at: sp_core::H256) -> tokio::process::Child {
55+
fn execute_block(uri: &str, at: sp_core::H256) -> tokio::process::Child {
5656
Command::new(cargo_bin!("try-runtime"))
5757
.stdout(std::process::Stdio::piped())
5858
.stderr(std::process::Stdio::piped())
5959
.arg("--runtime=existing")
6060
.args(["execute-block"])
61-
.args(["live", format!("--uri={}", ws_url).as_str()])
61+
.args(["live", format!("--uri={}", uri).as_str()])
6262
.args(["--at", format!("{:?}", at).as_str()])
6363
.kill_on_drop(true)
6464
.spawn()
6565
.unwrap()
6666
}
6767

6868
let block_number = 3;
69-
let block_hash = common::block_hash(block_number, &ws_url).await.unwrap();
69+
let block_hash = common::block_hash(block_number, &ws_uri).await.unwrap();
7070

7171
// Try to execute the block.
72-
let mut block_execution = execute_block(&ws_url, block_hash);
72+
let mut block_execution = execute_block(&ws_uri, block_hash);
7373

7474
// The execute-block command is actually executing the next block.
7575
let expected_output = format!(r#".*Block #{} successfully executed"#, block_number);
@@ -92,7 +92,7 @@ async fn execute_block_works() {
9292

9393
// Test not passing --at
9494
common::run_with_timeout(Duration::from_secs(60), async move {
95-
let ws_url = format!("ws://localhost:{}", port);
95+
let ws_uri = format!("ws://localhost:{}", port);
9696

9797
fn execute_block(ws_url: &str) -> tokio::process::Child {
9898
Command::new(cargo_bin!("try-runtime"))
@@ -107,7 +107,7 @@ async fn execute_block_works() {
107107
}
108108

109109
// Try to execute the block.
110-
let mut block_execution = execute_block(&ws_url);
110+
let mut block_execution = execute_block(&ws_uri);
111111
let expected_output = r".*Block #(\d+) successfully executed";
112112
let re = Regex::new(expected_output).unwrap();
113113
let matched =

cli/tests/follow_chain.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ use tokio::process::Command;
2727
#[tokio::test]
2828
async fn follow_chain_works() {
2929
let port = 45789;
30-
let ws_url = format!("ws://localhost:{}", port);
30+
let ws_uri = format!("ws://localhost:{}", port);
31+
let http_uri = format!("http://localhost:{}", port);
3132

3233
// Spawn a dev node.
3334
let _ = std::thread::spawn(move || {
@@ -49,19 +50,19 @@ async fn follow_chain_works() {
4950
std::thread::sleep(Duration::from_secs(180));
5051

5152
common::run_with_timeout(Duration::from_secs(60), async move {
52-
fn start_follow(ws_url: &str) -> tokio::process::Child {
53+
fn start_follow(uri: &str) -> tokio::process::Child {
5354
Command::new(cargo_bin!("try-runtime"))
5455
.stdout(std::process::Stdio::piped())
5556
.stderr(std::process::Stdio::piped())
5657
.arg("--runtime=existing")
57-
.args(["follow-chain", format!("--uri={}", ws_url).as_str()])
58+
.args(["follow-chain", format!("--uri={}", uri).as_str()])
5859
.kill_on_drop(true)
5960
.spawn()
6061
.unwrap()
6162
}
6263

6364
// Kick off the follow-chain process and wait for it to process at least 3 blocks.
64-
let mut follow = start_follow(&ws_url);
65+
let mut follow = start_follow(&http_uri);
6566
let re = Regex::new(r".*executed block ([3-9]|[1-9]\d+).*").unwrap();
6667
let matched =
6768
common::wait_for_stream_pattern_match(follow.stderr.take().unwrap(), re).await;

core/src/commands/create_snapshot.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use substrate_rpc_client::{ws_client, StateApi};
2323

2424
use crate::{
2525
common::{
26+
parse,
2627
shared_parameters,
2728
state::{build_executor, LiveState, RuntimeChecks, State},
2829
},
@@ -62,10 +63,12 @@ where
6263
let path = match snapshot_path {
6364
Some(path) => path,
6465
None => {
65-
let rpc = ws_client(&command.from.uri).await.unwrap();
66+
let rpc = ws_client(&parse::to_ws_uri(&command.from.uri))
67+
.await
68+
.map_err(|e| format!("failed to build ws client: {e:?}"))?;
6669
let remote_spec = StateApi::<Block::Hash>::runtime_version(&rpc, None)
6770
.await
68-
.unwrap();
71+
.map_err(|e| format!("failed to fetch runtime version: {e:?}"))?;
6972
let path_str = format!(
7073
"{}-{}@{}.snap",
7174
remote_spec.spec_name.to_lowercase(),

core/src/commands/execute_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ where
9696
{
9797
let executor = build_executor::<HostFns>(&shared);
9898
let block_ws_uri = command.block_ws_uri();
99-
let rpc = ws_client(&block_ws_uri).await?;
99+
let rpc = ws_client(&crate::common::parse::to_ws_uri(&block_ws_uri)).await?;
100100

101101
let live_state = match command.state {
102102
State::Live(live_state) => {

core/src/commands/follow_chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub struct Command {
7373
async fn start_subscribing<Header: DeserializeOwned + Serialize + Send + Sync + 'static>(
7474
url: &str,
7575
) -> sc_cli::Result<(WsClient, Subscription<Header>)> {
76-
let client = ws_client(url)
76+
let client = ws_client(&parse::to_ws_uri(url))
7777
.await
7878
.map_err(|e| sc_cli::Error::Application(e.into()))?;
7979

core/src/commands/offchain_worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ where
7676
{
7777
let executor = build_executor(&shared);
7878
let block_ws_uri = command.header_ws_uri();
79-
let rpc = ws_client(&block_ws_uri).await?;
79+
let rpc = ws_client(&parse::to_ws_uri(&block_ws_uri)).await?;
8080

8181
let live_state = match command.state {
8282
State::Live(live_state) => live_state,

core/src/common/empty_block/production.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{ops::DerefMut, str::FromStr, sync::Arc};
22

3+
use array_bytes::Hexify;
34
use parity_scale_codec::{Decode, Encode};
45
use sc_cli::Result;
56
use sc_executor::{HostFunctions, WasmExecutor};
@@ -66,7 +67,7 @@ where
6667

6768
log::info!(
6869
"Produced a new block ({})",
69-
array_bytes::bytes2hex("0x", next_block.header().hash())
70+
next_block.header().hash().as_bytes().hexify_prefixed()
7071
);
7172

7273
let mut ext_guard = ext_mutex.lock().await;

0 commit comments

Comments
 (0)