-
Notifications
You must be signed in to change notification settings - Fork 7
Support forking a custom relay chain #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
afe7368
39059b6
194b2b0
f57ee66
f71986b
a56a60f
f0d732d
99b6956
85a2a41
380068f
fc2102d
93650d2
00de00b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ use crate::config::{ | |
| BiteOptions, CoresOverride, Parachain, Relaychain, Upgrades, ZombieBiteConfig, | ||
| }; | ||
|
|
||
| const KNOWN_RELAYS: [&str; 4] = ["polkadot", "kusama", "paseo", "westend"]; | ||
|
|
||
| #[derive(Parser, Debug)] | ||
| #[command(author, version, about, long_about = None)] | ||
| pub struct Args { | ||
|
|
@@ -29,7 +31,10 @@ pub enum Commands { | |
| /// The network will be using for bite | ||
| /// If not specified, will use the value from config. | ||
| /// If not in config, defaults to polkadot. | ||
| #[arg(short = 'r', long = "rc", value_parser = clap::builder::PossibleValuesParser::new(["polkadot", "kusama", "paseo", "westend"]))] | ||
| /// The network to bite: polkadot, kusama, paseo or westend. | ||
| /// For a relay that is not a public network use: | ||
| /// custom%<name>%<rpc_endpoint>%<chain_spec_path> | ||
| #[arg(short = 'r', long = "rc", verbatim_doc_comment)] | ||
| relay: Option<String>, | ||
| /// If provided we will override the runtime as part of the process of 'bite' | ||
| /// The resulting network will be running with this runtime. | ||
|
|
@@ -243,8 +248,16 @@ pub fn resolve_bite_config( | |
| "polkadot".to_string() | ||
| }; | ||
|
|
||
| let relaychain = if relay_runtime.is_some() || rc_sync_url.is_some() || relay_bite_at.is_some() | ||
| { | ||
| let relaychain = if relay_network.starts_with("custom%") { | ||
| resolve_custom_relaychain(&relay_network, relay_runtime.clone(), relay_bite_at)? | ||
| } else if !KNOWN_RELAYS.contains(&relay_network.as_str()) { | ||
| // Anything else is a typo, not a chain to bite: a custom relay has to | ||
| // come with its endpoint and chain-spec. | ||
| bail!( | ||
| "unknown relay '{relay_network}'; use one of {} or custom%<name>%<rpc_endpoint>%<chain_spec_path>", | ||
| KNOWN_RELAYS.join(", ") | ||
| ); | ||
| } else if relay_runtime.is_some() || rc_sync_url.is_some() || relay_bite_at.is_some() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But here we support more strings that may not start with custom%, I think we need to ensure is a valid rc.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now bails on anything that isn't a known network or custom%. Kept the permissive mapping only in |
||
| // CLI args provided, use them | ||
| Relaychain::new_with_values(&relay_network, relay_runtime, rc_sync_url, relay_bite_at) | ||
| } else if let Some(ref config) = config_file { | ||
|
|
@@ -470,6 +483,29 @@ pub fn resolve_spawn_config( | |
| }) | ||
| } | ||
|
|
||
| /// custom%<name>%<rpc_endpoint>%<chain_spec_path> | ||
| fn resolve_custom_relaychain( | ||
| s: &str, | ||
| maybe_override: Option<String>, | ||
| maybe_bite_at: Option<u32>, | ||
| ) -> Result<Relaychain, anyhow::Error> { | ||
| let parts: Vec<&str> = s.splitn(4, '%').collect(); | ||
| if parts.len() != 4 { | ||
| bail!("custom relay must be custom%<name>%<rpc_endpoint>%<chain_spec_path>, got '{s}'"); | ||
| } | ||
| let (name, rpc, chain_spec) = (parts[1], parts[2], parts[3]); | ||
| if name.is_empty() || rpc.is_empty() || chain_spec.is_empty() { | ||
| bail!("custom relay needs a name, an rpc endpoint and a chain-spec path, got '{s}'"); | ||
| } | ||
| Ok(Relaychain::new_custom( | ||
| name, | ||
| chain_spec, | ||
| rpc, | ||
| maybe_override, | ||
| maybe_bite_at, | ||
| )) | ||
| } | ||
|
|
||
| fn resolve_custom_parachain(s: &str) -> Parachain { | ||
| let parts: Vec<&str> = s.splitn(5, '%').collect(); | ||
| trace!("custom parts: {parts:?}"); | ||
|
|
@@ -562,4 +598,45 @@ mod test { | |
| let s = "custom%3392%wss://kusama-yap-3392.example.com:1234%/path/to/chain-spec.json%abc"; | ||
| let _para = resolve_custom_parachain(s); | ||
| } | ||
| #[test] | ||
| fn custom_relay_works() { | ||
| let rc = resolve_custom_relaychain( | ||
| "custom%previewnet%wss://previewnet.example.com%/path/to/previewnet.json", | ||
| None, | ||
| Some(42), | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert_eq!(rc.as_chain_string(), "previewnet"); | ||
| assert_eq!(rc.chain_spec(), Some("/path/to/previewnet.json")); | ||
| // a custom relay is passed to the node as a spec path, not a name | ||
| assert_eq!(rc.chain_arg(), "/path/to/previewnet.json"); | ||
| assert_eq!(rc.rpc_endpoint(), "wss://previewnet.example.com"); | ||
| assert_eq!(rc.sync_endpoint(), "wss://previewnet.example.com"); | ||
| assert_eq!(rc.at_block(), Some(42)); | ||
| assert!(rc.is_custom()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn custom_relay_needs_every_part() { | ||
| for bad in [ | ||
| "custom%previewnet%wss://previewnet.example.com", | ||
| "custom%previewnet%%/path/to/spec.json", | ||
| "custom%%wss://x%/path/to/spec.json", | ||
| ] { | ||
| assert!( | ||
| resolve_custom_relaychain(bad, None, None).is_err(), | ||
| "should reject '{bad}'" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn unknown_relay_name_keeps_its_name() { | ||
| // helper subcommands only get the name back as a string, and the | ||
| // artifacts are named after it | ||
| let rc = Relaychain::new("previewnet"); | ||
| assert_eq!(rc.as_chain_string(), "previewnet"); | ||
| assert!(rc.is_custom()); | ||
| } | ||
| } | ||
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.
We are dropping the help msj here with the possible values. I think we should include it.
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.
restored, lists the four networks plus the custom format