Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/workflows/rust-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
toolchain: [stable]
runs-on: ${{ matrix.os }}
env:
RUSTFLAGS: "-Cdebug-assertions=y"
Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,29 @@ cargo build --features try-runtime --release && cp target/release/substrate .

```bash
# Assuming local nodes are running (e.g., `./substrate --dev --tmp --ws-port 9999`).
# Multiple --uri flags can be provided for parallel state download.
# Multiple URIs can be provided for parallel state download, either
# comma-separated or via repeated --uri flags.
try-runtime \
--runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
on-runtime-upgrade \
--disable-mbm-checks \
live \
--uri ws://localhost:9999 \
--uri ws://localhost:9998
--uri ws://localhost:9999,ws://localhost:9998
...
```

To speed up state download, you can provide multiple URIs for parallel fetching:

```bash
# assuming multiple substrate nodes running on ports 9999, 9998, 9997
# comma-separated:
try-runtime \
--runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
on-runtime-upgrade \
live \
--uri ws://localhost:9999,ws://localhost:9998,ws://localhost:9997

# or repeated flags:
try-runtime \
--runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
on-runtime-upgrade \
Expand All @@ -210,8 +218,8 @@ try-runtime \

* Same as the previous example, but run it at specific block number's state and using the live
polkadot network. This means that this block hash's state should not yet have been pruned by
the node running at `rpc.polkadot.io`. Multiple `--uri` flags can be provided for parallel
state download.
the node running at `rpc.polkadot.io`. Multiple URIs can be provided for parallel
state download (comma-separated or via repeated `--uri` flags).

```bash
try-runtime \
Expand All @@ -236,8 +244,7 @@ For faster snapshot creation with large state, use multiple RPC endpoints:

```bash
try-runtime --runtime existing create-snapshot \
--uri ws://localhost:9999 \
--uri ws://localhost:9998 \
--uri ws://localhost:9999,ws://localhost:9998 \
-- my-snapshot.snap
```

Expand Down
22 changes: 14 additions & 8 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,28 @@
//!
//! ```bash
//! # Assuming local nodes are running (e.g., `./substrate --dev --tmp --ws-port 9999`).
//! # Multiple --uri flags can be provided for parallel state download.
//! # Multiple URIs can be provided for parallel state download, either
//! # comma-separated or via repeated --uri flags.
//! try-runtime \
//! --runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
//! on-runtime-upgrade \
//! --disable-mbm-checks \
//! live \
//! --uri ws://localhost:9999 \
//! --uri ws://localhost:9998
//! --uri ws://localhost:9999,ws://localhost:9998
//! ...
//! ```
//!
//! To speed up state download, you can provide multiple URIs for parallel fetching:
//!
//! ```bash
//! # assuming multiple substrate nodes running on ports 9999, 9998, 9997
//! # comma-separated:
//! try-runtime \
//! --runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
//! on-runtime-upgrade \
//! live \
//! --uri ws://localhost:9999,ws://localhost:9998,ws://localhost:9997
//!
//! # or repeated flags:
//! try-runtime \
//! --runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
//! on-runtime-upgrade \
Expand All @@ -226,8 +233,8 @@
//!
//! * Same as the previous example, but run it at specific block number's state and using the live
//! polkadot network. This means that this block hash's state should not yet have been pruned by
//! the node running at `rpc.polkadot.io`. Multiple `--uri` flags can be provided for parallel
//! state download.
//! the node running at `rpc.polkadot.io`. Multiple URIs can be provided for parallel
//! state download (comma-separated or via repeated `--uri` flags).
//!
//! ```bash
//! try-runtime \
Expand All @@ -252,8 +259,7 @@
//!
//! ```bash
//! try-runtime --runtime existing create-snapshot \
//! --uri ws://localhost:9999 \
//! --uri ws://localhost:9998 \
//! --uri ws://localhost:9999,ws://localhost:9998 \
//! -- my-snapshot.snap
//! ```
//!
Expand Down
80 changes: 78 additions & 2 deletions core/src/common/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ use crate::{
/// A `Live` variant for [`State`]
#[derive(Debug, Clone, clap::Args)]
pub struct LiveState {
/// The url(s) to connect to. Can be provided multiple times for parallel state download.
/// The url(s) to connect to. Can be comma-separated (no spaces) for parallel download.
#[arg(
short,
long,
value_parser = parse::url,
num_args = 1..,
value_delimiter = ',',
required = true,
)]
pub uri: Vec<String>,
Expand Down Expand Up @@ -483,3 +483,79 @@ fn storage_proof_to_raw_json(storage_proof: &sp_state_machine::StorageProof) ->
)
.to_string()
}

#[cfg(test)]
mod tests {
use super::*;
use clap::Parser;

#[derive(Parser)]
struct TestCli {
#[command(subcommand)]
state: State,
}

#[test]
fn uri_repeated_flags() {
let cli = TestCli::parse_from([
"test",
"live",
"--uri",
"ws://localhost:9999",
"--uri",
"ws://localhost:9998",
]);
match cli.state {
State::Live(live) => {
assert_eq!(live.uri, vec!["ws://localhost:9999", "ws://localhost:9998"]);
}
_ => panic!("expected Live variant"),
}
}

#[test]
fn uri_comma_separated() {
let cli = TestCli::parse_from([
"test",
"live",
"--uri",
"ws://localhost:9999,ws://localhost:9998",
]);
match cli.state {
State::Live(live) => {
assert_eq!(live.uri, vec!["ws://localhost:9999", "ws://localhost:9998"]);
}
_ => panic!("expected Live variant"),
}
}

#[test]
fn uri_single_value() {
let cli = TestCli::parse_from(["test", "live", "--uri", "wss://rpc.polkadot.io:443"]);
match cli.state {
State::Live(live) => {
assert_eq!(live.uri, vec!["wss://rpc.polkadot.io:443"]);
}
_ => panic!("expected Live variant"),
}
}

#[test]
fn uri_positional_not_swallowed() {
let cli = TestCli::parse_from([
"test",
"live",
"--uri",
"ws://localhost:9999",
"--pallet",
"System",
]);
match cli.state {
State::Live(live) => {
assert_eq!(live.uri, vec!["ws://localhost:9999"]);
assert_eq!(live.pallet, vec!["System"]);
}
_ => panic!("expected Live variant"),
}
}
}
Loading