Skip to content

Commit 3023cd3

Browse files
ggwpezrockbmb
andauthored
fix uri argument order (#134)
This one stopped working: `try-runtime create-snapshot --uri wss://westend-asset-hub-rpc.polkadot.io:443 ah-westend.snap` and instead it was necessary to do this: `try-runtime create-snapshot ah-westend.snap --uri wss://westend-asset-hub-rpc.polkadot.io:443` The `1..` args of the `uri` argument would conflict with the `index = 1` or the snapshot path. I changed it now to require comma separation for uris, like `--uri URI1,URI2,URI3` Any better ideas? --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Alexandre Baldé <alexandre.balde@parity.io>
1 parent 629fd97 commit 3023cd3

4 files changed

Lines changed: 138 additions & 17 deletions

File tree

.github/workflows/rust-checks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ jobs:
8585
strategy:
8686
matrix:
8787
os: [ubuntu-latest]
88+
toolchain: [stable]
8889
runs-on: ${{ matrix.os }}
8990
env:
9091
RUSTFLAGS: "-Cdebug-assertions=y"

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,29 @@ cargo build --features try-runtime --release && cp target/release/substrate .
184184

185185
```bash
186186
# Assuming local nodes are running (e.g., `./substrate --dev --tmp --ws-port 9999`).
187-
# Multiple --uri flags can be provided for parallel state download.
187+
# Multiple URIs can be provided for parallel state download, either
188+
# comma-separated or via repeated --uri flags.
188189
try-runtime \
189190
--runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
190191
on-runtime-upgrade \
191192
--disable-mbm-checks \
192193
live \
193-
--uri ws://localhost:9999 \
194-
--uri ws://localhost:9998
194+
--uri ws://localhost:9999,ws://localhost:9998
195195
...
196196
```
197197

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

200200
```bash
201201
# assuming multiple substrate nodes running on ports 9999, 9998, 9997
202+
# comma-separated:
203+
try-runtime \
204+
--runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
205+
on-runtime-upgrade \
206+
live \
207+
--uri ws://localhost:9999,ws://localhost:9998,ws://localhost:9997
208+
209+
# or repeated flags:
202210
try-runtime \
203211
--runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
204212
on-runtime-upgrade \
@@ -210,8 +218,8 @@ try-runtime \
210218

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

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

237245
```bash
238246
try-runtime --runtime existing create-snapshot \
239-
--uri ws://localhost:9999 \
240-
--uri ws://localhost:9998 \
247+
--uri ws://localhost:9999,ws://localhost:9998 \
241248
-- my-snapshot.snap
242249
```
243250

cli/main.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,28 @@
200200
//!
201201
//! ```bash
202202
//! # Assuming local nodes are running (e.g., `./substrate --dev --tmp --ws-port 9999`).
203-
//! # Multiple --uri flags can be provided for parallel state download.
203+
//! # Multiple URIs can be provided for parallel state download, either
204+
//! # comma-separated or via repeated --uri flags.
204205
//! try-runtime \
205206
//! --runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
206207
//! on-runtime-upgrade \
207208
//! --disable-mbm-checks \
208209
//! live \
209-
//! --uri ws://localhost:9999 \
210-
//! --uri ws://localhost:9998
210+
//! --uri ws://localhost:9999,ws://localhost:9998
211211
//! ...
212212
//! ```
213213
//!
214214
//! To speed up state download, you can provide multiple URIs for parallel fetching:
215215
//!
216216
//! ```bash
217-
//! # assuming multiple substrate nodes running on ports 9999, 9998, 9997
217+
//! # comma-separated:
218+
//! try-runtime \
219+
//! --runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
220+
//! on-runtime-upgrade \
221+
//! live \
222+
//! --uri ws://localhost:9999,ws://localhost:9998,ws://localhost:9997
223+
//!
224+
//! # or repeated flags:
218225
//! try-runtime \
219226
//! --runtime /path-to-substrate/target/release/wbuild/my-runtime.wasm \
220227
//! on-runtime-upgrade \
@@ -226,8 +233,8 @@
226233
//!
227234
//! * Same as the previous example, but run it at specific block number's state and using the live
228235
//! polkadot network. This means that this block hash's state should not yet have been pruned by
229-
//! the node running at `rpc.polkadot.io`. Multiple `--uri` flags can be provided for parallel
230-
//! state download.
236+
//! the node running at `rpc.polkadot.io`. Multiple URIs can be provided for parallel state
237+
//! download (comma-separated or via repeated `--uri` flags).
231238
//!
232239
//! ```bash
233240
//! try-runtime \
@@ -252,8 +259,7 @@
252259
//!
253260
//! ```bash
254261
//! try-runtime --runtime existing create-snapshot \
255-
//! --uri ws://localhost:9999 \
256-
//! --uri ws://localhost:9998 \
262+
//! --uri ws://localhost:9999,ws://localhost:9998 \
257263
//! -- my-snapshot.snap
258264
//! ```
259265
//!

core/src/common/state.rs

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ use crate::{
4949
/// A `Live` variant for [`State`]
5050
#[derive(Debug, Clone, clap::Args)]
5151
pub struct LiveState {
52-
/// The url(s) to connect to. Can be provided multiple times for parallel state download.
52+
/// The url(s) to connect to. Can be comma-separated (no spaces) for parallel download.
5353
#[arg(
5454
short,
5555
long,
5656
value_parser = parse::url,
57-
num_args = 1..,
57+
value_delimiter = ',',
5858
required = true,
5959
)]
6060
pub uri: Vec<String>,
@@ -483,3 +483,110 @@ fn storage_proof_to_raw_json(storage_proof: &sp_state_machine::StorageProof) ->
483483
)
484484
.to_string()
485485
}
486+
487+
#[cfg(test)]
488+
mod tests {
489+
use clap::Parser;
490+
491+
use super::*;
492+
493+
#[derive(Parser)]
494+
struct TestCli {
495+
#[command(subcommand)]
496+
state: State,
497+
}
498+
499+
/// Multiple URIs via repeated `--uri` flags.
500+
#[test]
501+
fn uri_repeated_flags() {
502+
let cli = TestCli::parse_from([
503+
"test",
504+
"live",
505+
"--uri",
506+
"ws://localhost:9999",
507+
"--uri",
508+
"ws://localhost:9998",
509+
]);
510+
match cli.state {
511+
State::Live(live) => {
512+
assert_eq!(live.uri, vec!["ws://localhost:9999", "ws://localhost:9998"]);
513+
}
514+
_ => panic!("expected Live variant"),
515+
}
516+
}
517+
518+
/// Multiple URIs via comma-separated value in a single `--uri`.
519+
#[test]
520+
fn uri_comma_separated() {
521+
let cli = TestCli::parse_from([
522+
"test",
523+
"live",
524+
"--uri",
525+
"ws://localhost:9999,ws://localhost:9998",
526+
]);
527+
match cli.state {
528+
State::Live(live) => {
529+
assert_eq!(live.uri, vec!["ws://localhost:9999", "ws://localhost:9998"]);
530+
}
531+
_ => panic!("expected Live variant"),
532+
}
533+
}
534+
535+
/// Mixing repeated flags with comma-separated values in a single invocation.
536+
#[test]
537+
fn uri_mixed_repeated_and_comma() {
538+
let cli = TestCli::parse_from([
539+
"test",
540+
"live",
541+
"--uri",
542+
"ws://localhost:9999,ws://localhost:9998",
543+
"--uri",
544+
"ws://localhost:9997",
545+
]);
546+
match cli.state {
547+
State::Live(live) => {
548+
assert_eq!(
549+
live.uri,
550+
vec![
551+
"ws://localhost:9999",
552+
"ws://localhost:9998",
553+
"ws://localhost:9997",
554+
]
555+
);
556+
}
557+
_ => panic!("expected Live variant"),
558+
}
559+
}
560+
561+
/// Single URI, the common case.
562+
#[test]
563+
fn uri_single_value() {
564+
let cli = TestCli::parse_from(["test", "live", "--uri", "wss://rpc.polkadot.io:443"]);
565+
match cli.state {
566+
State::Live(live) => {
567+
assert_eq!(live.uri, vec!["wss://rpc.polkadot.io:443"]);
568+
}
569+
_ => panic!("expected Live variant"),
570+
}
571+
}
572+
573+
/// Arguments after `--uri` are not greedily consumed (the original bug).
574+
#[test]
575+
fn uri_positional_not_swallowed() {
576+
let cli = TestCli::parse_from([
577+
"test",
578+
"live",
579+
"--uri",
580+
"ws://localhost:9999",
581+
"--pallet",
582+
"System",
583+
]);
584+
match cli.state {
585+
State::Live(live) => {
586+
assert_eq!(live.uri, vec!["ws://localhost:9999"]);
587+
assert_eq!(live.pallet, vec!["System"]);
588+
}
589+
_ => panic!("expected Live variant"),
590+
}
591+
}
592+
}

0 commit comments

Comments
 (0)