-
Notifications
You must be signed in to change notification settings - Fork 51
test(e2e): IPFS support #3528
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
Merged
Merged
test(e2e): IPFS support #3528
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e8b4b54
refactor(e2e): rename `devnet::runner` module to `cardano`
Alenar 988c6ab
feat(e2e): ipfs devnet runner first draft
Alenar 3abdf93
feat(e2e): wire IPFS devnet to infrastructure bootstrapping
Alenar b435ab5
feat(e2e): wire IPFS devnet to spawned aggregators
Alenar ef80b0a
feat(e2e): download + validate cardano db snapshots from ipfs if enabled
Alenar 4122629
feat(e2e): support attaching to existing IPFS devnet
Alenar 1a1ac65
docs(e2e): document network topology options in README (multi-aggrega…
Alenar 20426b2
ci: add one IPFS scenario to the end-to-end matrix
Alenar 33e37ed
chore: upgrade crate versions
Alenar 4ac2b58
refactor(ipfs-devnet): changes port used to limit collisions risks
Alenar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| use std::ffi::OsStr; | ||
| use std::path::{Path, PathBuf}; | ||
| use std::process::Stdio; | ||
|
|
||
| use anyhow::{Context, anyhow}; | ||
| use reqwest::Url; | ||
| use slog_scope::info; | ||
| use tokio::process::Command; | ||
|
|
||
| use mithril_common::StdResult; | ||
|
|
||
| use crate::RetryableDevnetError; | ||
| use crate::utils::{ChildLoggerExt, file_utils}; | ||
|
|
||
| const IPFS_DEVNET_SCRIPT_NAME: &str = "ipfs-devnet.sh"; | ||
|
|
||
| #[derive(Debug, Copy, Clone, Default)] | ||
| pub enum IpfsDevnetMode { | ||
| /// Spawn an IPFS devnet (default, only alive during the tests). | ||
| #[default] | ||
| Spawn, | ||
| /// Attach to an existing IPFS devnet. | ||
| Detached, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub struct IpfsDevnet { | ||
| devnet_script_path: PathBuf, | ||
| swarm_dir: PathBuf, | ||
| topology: Vec<KuboNode>, | ||
| mode: IpfsDevnetMode, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub struct KuboNode { | ||
| pub rpc_url: Url, | ||
| pub working_dir: PathBuf, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct IpfsDevnetBootstrapArgs { | ||
| pub devnet_scripts_dir: PathBuf, | ||
| pub number_of_nodes: u8, | ||
| pub swarm_target_dir: PathBuf, | ||
| pub kubo_version: Option<semver::Version>, | ||
| pub mode: IpfsDevnetMode, | ||
| } | ||
|
|
||
| impl IpfsDevnet { | ||
| fn build_command<C: AsRef<OsStr>>(&self, sub_command: C) -> StdResult<Command> { | ||
| let mut command = Command::new(self.devnet_script_path.clone()); | ||
| command | ||
| .arg(sub_command) | ||
| .env("SWARM_DIR", self.swarm_dir.as_os_str()) | ||
| .stdout(Stdio::piped()) | ||
| .stderr(Stdio::piped()) | ||
| .kill_on_drop(true); | ||
| Ok(command) | ||
| } | ||
|
|
||
| fn build_topology(number_of_nodes: u8, swarm_dir: &Path) -> Vec<KuboNode> { | ||
| (1..=number_of_nodes) | ||
| .map(|n| KuboNode { | ||
| rpc_url: Url::parse(&format!("http://127.0.0.1:{}", 5000_u16 + n as u16)).unwrap(), | ||
| working_dir: swarm_dir.join(format!("kubo-node-{n}")), | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| pub async fn bootstrap(bootstrap_args: &IpfsDevnetBootstrapArgs) -> StdResult<IpfsDevnet> { | ||
| match bootstrap_args.mode { | ||
| IpfsDevnetMode::Spawn => Self::bootstrap_new_network(bootstrap_args).await, | ||
| IpfsDevnetMode::Detached => Self::bootstrap_attached(bootstrap_args), | ||
| } | ||
| } | ||
|
|
||
| fn bootstrap_attached(bootstrap_args: &IpfsDevnetBootstrapArgs) -> StdResult<IpfsDevnet> { | ||
| let devnet_script_path = file_utils::get_process_path( | ||
| IPFS_DEVNET_SCRIPT_NAME, | ||
| &bootstrap_args.devnet_scripts_dir, | ||
| )?; | ||
| let swarm_dir = bootstrap_args.swarm_target_dir.to_owned(); | ||
|
Alenar marked this conversation as resolved.
|
||
| let swarm_dir_entries: Vec<_> = swarm_dir | ||
| .read_dir() | ||
| .with_context(|| format!("Failed to read swarm directory: '{}'", swarm_dir.display()))? | ||
| .filter_map(|e| e.ok()) | ||
| .filter(|e| e.file_type().is_ok_and(|t| t.is_dir())) | ||
| .collect(); | ||
|
|
||
| for i in 1..=bootstrap_args.number_of_nodes { | ||
| let expected_node = format!("kubo-node-{i}"); | ||
| if !swarm_dir_entries | ||
| .iter() | ||
| .any(|e| e.file_name().to_string_lossy() == expected_node) | ||
| { | ||
| anyhow::bail!( | ||
| "Expected node '{}' missing in attached swarm directory ('{}'), please re-initialize the devnet with at least {} nodes", | ||
| expected_node, | ||
| swarm_dir.display(), | ||
| bootstrap_args.number_of_nodes | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Ok(IpfsDevnet { | ||
| devnet_script_path, | ||
| swarm_dir: bootstrap_args.swarm_target_dir.to_owned(), | ||
| topology: Self::build_topology( | ||
| bootstrap_args.number_of_nodes, | ||
| &bootstrap_args.swarm_target_dir, | ||
| ), | ||
| mode: bootstrap_args.mode, | ||
| }) | ||
| } | ||
|
|
||
| async fn bootstrap_new_network( | ||
| bootstrap_args: &IpfsDevnetBootstrapArgs, | ||
| ) -> StdResult<IpfsDevnet> { | ||
| let devnet_script_path = file_utils::get_process_path( | ||
| IPFS_DEVNET_SCRIPT_NAME, | ||
| &bootstrap_args.devnet_scripts_dir, | ||
| )?; | ||
|
|
||
| let mut bootstrap_command = Command::new(&devnet_script_path); | ||
| bootstrap_command | ||
| .arg("init") | ||
| .arg("--overwrite") | ||
| .arg("--number") | ||
| .arg(bootstrap_args.number_of_nodes.to_string()) | ||
| .arg("--swarm-dir") | ||
| .arg(bootstrap_args.swarm_target_dir.as_os_str()); | ||
|
|
||
| if let Some(kubo_version) = &bootstrap_args.kubo_version { | ||
| bootstrap_command.env("KUBO_VERSION", kubo_version.to_string()); | ||
| } | ||
|
|
||
| bootstrap_command | ||
| .current_dir(&bootstrap_args.devnet_scripts_dir) | ||
| .stdout(Stdio::piped()) | ||
| .stderr(Stdio::piped()) | ||
| .kill_on_drop(true); | ||
|
|
||
| info!("Bootstrapping the IPFS Devnet"; "script" => &devnet_script_path.display(), "cmd" => "init"); | ||
|
|
||
| let exit_status = bootstrap_command | ||
| .spawn() | ||
| .with_context(|| format!("{IPFS_DEVNET_SCRIPT_NAME} failed to start"))? | ||
| .wait_forwarding_output_to_slog_scope(IPFS_DEVNET_SCRIPT_NAME) | ||
| .await | ||
| .with_context(|| format!("{IPFS_DEVNET_SCRIPT_NAME} failed to run"))?; | ||
| match exit_status.code() { | ||
| Some(0) => Ok(IpfsDevnet { | ||
| devnet_script_path, | ||
| swarm_dir: bootstrap_args.swarm_target_dir.to_owned(), | ||
| topology: Self::build_topology( | ||
| bootstrap_args.number_of_nodes, | ||
| &bootstrap_args.swarm_target_dir, | ||
| ), | ||
| mode: bootstrap_args.mode, | ||
| }), | ||
| Some(code) => Err(anyhow!(RetryableDevnetError(format!( | ||
| "IPFS Bootstrap devnet exited with status code: {code}" | ||
| )))), | ||
| None => Err(anyhow!("IPFS Bootstrap devnet terminated by signal")), | ||
| } | ||
| } | ||
|
|
||
| pub fn swarm_dir(&self) -> PathBuf { | ||
| self.swarm_dir.clone() | ||
| } | ||
|
|
||
| pub fn topology(&self) -> &[KuboNode] { | ||
| &self.topology | ||
| } | ||
|
|
||
| pub async fn start(&self) -> StdResult<()> { | ||
| // Note: running the start command on an already running devnet does nothing, so running it | ||
| // against a "Detached" devnet poses no risk (if stopped, it will start, if running, it will do nothing). | ||
| let mut run_command = self.build_command("start")?; | ||
|
|
||
| info!("Starting the IPFS devnet"; "script" => &self.devnet_script_path.display(), "cmd" => "start"); | ||
|
|
||
| let status = run_command | ||
| .spawn() | ||
| .with_context(|| "Failed to start the IPFS devnet")? | ||
| .wait_forwarding_output_to_slog_scope(&format!("{IPFS_DEVNET_SCRIPT_NAME} start")) | ||
| .await | ||
| .with_context(|| "Error while starting the IPFS devnet")?; | ||
| match status.code() { | ||
| Some(0) => Ok(()), | ||
| Some(code) => Err(anyhow!(RetryableDevnetError(format!( | ||
| "Run IPFS devnet exited with status code: {code}" | ||
| )))), | ||
| None => Err(anyhow!("Run IPFS devnet terminated by signal")), | ||
| } | ||
| } | ||
|
|
||
| pub async fn stop(&self) -> StdResult<()> { | ||
| if matches!(self.mode, IpfsDevnetMode::Detached) { | ||
| info!("IPFS devnet is in detached mode, leaving it running"); | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let mut run_command = self.build_command("stop")?; | ||
|
|
||
| info!("Stopping the IPFS devnet"; "script" => &self.devnet_script_path.display(), "cmd" => "stop"); | ||
|
|
||
| let exit_status = run_command | ||
| .spawn() | ||
| .with_context(|| "Failed to stop the IPFS devnet")? | ||
| .wait_forwarding_output_to_slog_scope(&format!("{IPFS_DEVNET_SCRIPT_NAME} stop")) | ||
| .await | ||
| .with_context(|| "Error while stopping the IPFS devnet")?; | ||
| match exit_status.code() { | ||
| Some(0) => Ok(()), | ||
| Some(code) => Err(anyhow!("Stop IPFS devnet exited with status code: {code}")), | ||
| None => Err(anyhow!("Stop IPFS devnet terminated by signal")), | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| mod runner; | ||
| mod cardano; | ||
| mod ipfs; | ||
|
|
||
| pub use runner::{ | ||
| Devnet, DevnetBootstrapArgs, DevnetTopology, FullNode, PoolNode, RetryableDevnetError, | ||
| }; | ||
| pub use cardano::{Devnet, DevnetBootstrapArgs, DevnetTopology, FullNode, PoolNode}; | ||
| pub use ipfs::{IpfsDevnet, IpfsDevnetBootstrapArgs, IpfsDevnetMode, KuboNode}; | ||
|
|
||
| #[derive(thiserror::Error, Debug, PartialEq, Eq)] | ||
| #[error("Retryable devnet error: `{0}`")] | ||
| pub struct RetryableDevnetError(pub String); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.