Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-test-lab/mithril-end-to-end/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-end-to-end"
version = "0.4.37"
version = "0.4.38"
authors = { workspace = true }
edition = { workspace = true }
documentation = { workspace = true }
Expand Down
19 changes: 15 additions & 4 deletions mithril-test-lab/mithril-end-to-end/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::{
fs,
path::{Path, PathBuf},
sync::Arc,
thread::sleep,
time::Duration,
};
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -174,6 +173,11 @@ async fn main() -> StdResult<()> {
work_dir.canonicalize().unwrap()
}
};
let artifacts_dir = {
let path = work_dir.join("artifacts");
fs::create_dir(&path).expect("Artifacts dir creation failure");
path
};
let run_only_mode = args.run_only;
let use_p2p_network_mode = args.use_p2p_network;
let use_p2p_passive_relays = args.use_p2p_passive_relays;
Expand All @@ -193,6 +197,7 @@ async fn main() -> StdResult<()> {
let mut infrastructure = MithrilInfrastructure::start(&MithrilInfrastructureConfig {
server_port,
devnet: devnet.clone(),
artifacts_dir,
work_dir,
bin_dir: args.bin_directory,
cardano_node_version: args.cardano_node_version,
Expand Down Expand Up @@ -224,33 +229,39 @@ async fn main() -> StdResult<()> {
};

match runner {
Ok(_) if run_only_mode => run_until_cancelled(devnet).await,
Ok(_) if run_only_mode => run_until_cancelled(infrastructure, devnet).await,
Ok(_) => {
infrastructure.stop_nodes().await?;
devnet.stop().await?;
Ok(())
}
Err(error) => {
let has_written_logs = infrastructure.tail_logs(40).await;
error!("Mithril End to End test in failed: {}", error);
infrastructure.stop_nodes().await?;
devnet.stop().await?;
has_written_logs?;
Err(error)
}
}
}

async fn run_until_cancelled(devnet: Devnet) -> StdResult<()> {
async fn run_until_cancelled(
mut mithril_infrastructure: MithrilInfrastructure,
devnet: Devnet,
) -> StdResult<()> {
let cancellation_token = CancellationToken::new();
let cloned_token = cancellation_token.clone();

tokio::select! {
_ = tokio::spawn(async move {
while !cloned_token.is_cancelled() {
info!("Mithril end to end is running and will remain active until manually stopped...");
sleep(Duration::from_secs(5));
tokio::time::sleep(Duration::from_secs(5)).await;
}
}) => {}
_ = tokio::signal::ctrl_c() => {
mithril_infrastructure.stop_nodes().await?;
cancellation_token.cancel();
devnet.stop().await?;
}
Expand Down
15 changes: 13 additions & 2 deletions mithril-test-lab/mithril-end-to-end/src/mithril/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
use anyhow::{anyhow, Context};
use mithril_common::era::SupportedEra;
use mithril_common::{entities, StdResult};
use slog_scope::info;
use std::cmp;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
Expand All @@ -18,6 +19,7 @@ pub struct AggregatorConfig<'a> {
pub pool_node: &'a PoolNode,
pub cardano_cli_path: &'a Path,
pub work_dir: &'a Path,
pub artifacts_dir: &'a Path,
pub bin_dir: &'a Path,
pub cardano_node_version: &'a str,
pub mithril_run_interval: u32,
Expand Down Expand Up @@ -62,6 +64,10 @@ impl Aggregator {
("URL_SNAPSHOT_MANIFEST", ""),
("SNAPSHOT_STORE_TYPE", "local"),
("SNAPSHOT_UPLOADER_TYPE", "local"),
(
"SNAPSHOT_DIRECTORY",
aggregator_config.artifacts_dir.to_str().unwrap(),
),
("NETWORK_MAGIC", &magic_id),
("DATA_STORES_DIRECTORY", "./stores/aggregator"),
(
Expand Down Expand Up @@ -139,8 +145,11 @@ impl Aggregator {
}

pub async fn bootstrap_genesis(&mut self) -> StdResult<()> {
let exit_status = self
.command
// Clone the command so we can alter it without affecting the original
let mut command = self.command.clone();
command.set_log_name("mithril-aggregator-genesis-bootstrap");

let exit_status = command
.start(&["genesis".to_string(), "bootstrap".to_string()])?
.wait()
.await
Expand All @@ -162,10 +171,12 @@ impl Aggregator {

pub async fn stop(&mut self) -> StdResult<()> {
if let Some(process) = self.process.as_mut() {
info!("Stopping aggregator");
process
.kill()
.await
.with_context(|| "Could not kill aggregator")?;
self.process = None;
}
Ok(())
}
Expand Down
53 changes: 40 additions & 13 deletions mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
assertions, Aggregator, AggregatorConfig, Client, Devnet, PoolNode, RelayAggregator,
RelayPassive, RelaySigner, Signer, DEVNET_MAGIC_ID,
};
use anyhow::Context;
use mithril_common::chain_observer::{ChainObserver, PallasChainObserver};
use mithril_common::entities::{Epoch, PartyId, ProtocolParameters};
use mithril_common::{CardanoNetwork, StdResult};
Expand All @@ -11,12 +8,18 @@ use std::fs;
use std::path::PathBuf;
use std::sync::Arc;

use crate::{
assertions, Aggregator, AggregatorConfig, Client, Devnet, PoolNode, RelayAggregator,
RelayPassive, RelaySigner, Signer, DEVNET_MAGIC_ID,
};

use super::signer::SignerConfig;

pub struct MithrilInfrastructureConfig {
pub server_port: u64,
pub devnet: Devnet,
pub work_dir: PathBuf,
pub artifacts_dir: PathBuf,
pub bin_dir: PathBuf,
pub cardano_node_version: String,
pub mithril_run_interval: u32,
Expand All @@ -30,7 +33,7 @@ pub struct MithrilInfrastructureConfig {
}

pub struct MithrilInfrastructure {
work_dir: PathBuf,
artifacts_dir: PathBuf,
bin_dir: PathBuf,
devnet: Devnet,
aggregator: Aggregator,
Expand Down Expand Up @@ -77,8 +80,8 @@ impl MithrilInfrastructure {
));

Ok(Self {
work_dir: config.work_dir.to_path_buf(),
bin_dir: config.bin_dir.to_path_buf(),
artifacts_dir: config.artifacts_dir.to_path_buf(),
devnet: config.devnet.clone(),
aggregator,
signers,
Expand Down Expand Up @@ -137,11 +140,22 @@ impl MithrilInfrastructure {
pool_node: &PoolNode,
chain_observer_type: &str,
) -> StdResult<Aggregator> {
let aggregator_artifacts_directory = config.artifacts_dir.join("mithril-aggregator");
if !aggregator_artifacts_directory.exists() {
fs::create_dir_all(&aggregator_artifacts_directory).with_context(|| {
format!(
"Could not create artifacts directory '{}'",
aggregator_artifacts_directory.display()
)
})?;
}

let mut aggregator = Aggregator::new(&AggregatorConfig {
server_port: config.server_port,
pool_node,
cardano_cli_path: &config.devnet.cardano_cli_path(),
work_dir: &config.work_dir,
artifacts_dir: &aggregator_artifacts_directory,
bin_dir: &config.bin_dir,
cardano_node_version: &config.cardano_node_version,
mithril_run_interval: config.mithril_run_interval,
Expand Down Expand Up @@ -275,6 +289,18 @@ impl MithrilInfrastructure {
Ok(signers)
}

pub async fn stop_nodes(&mut self) -> StdResult<()> {
// Note: The aggregator should be stopped *last* since signers depends on it
info!("Stopping Mithril infrastructure");
for signer in self.signers.as_mut_slice() {
signer.stop().await?;
}

self.aggregator.stop().await?;

Ok(())
}

pub fn devnet(&self) -> &Devnet {
&self.devnet
}
Expand Down Expand Up @@ -312,15 +338,16 @@ impl MithrilInfrastructure {
}

pub fn build_client(&self) -> StdResult<Client> {
let work_dir = if self.use_era_specific_work_dir {
let era_work_dir = self.work_dir.join(format!("era.{}", self.current_era));
if !era_work_dir.exists() {
fs::create_dir(&era_work_dir)?;
let work_dir = {
let mut artifacts_dir = self.artifacts_dir.join("mithril-client");
if self.use_era_specific_work_dir {
artifacts_dir = artifacts_dir.join(format!("era.{}", self.current_era));
}
if !artifacts_dir.exists() {
fs::create_dir_all(&artifacts_dir)?;
}

era_work_dir
} else {
self.work_dir.clone()
artifacts_dir
};

Client::new(self.aggregator.endpoint(), &work_dir, &self.bin_dir)
Expand Down
21 changes: 18 additions & 3 deletions mithril-test-lab/mithril-end-to-end/src/mithril/signer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::devnet::PoolNode;
use crate::utils::MithrilCommand;
use crate::{DEVNET_MAGIC_ID, ERA_MARKERS_VERIFICATION_KEY};
use anyhow::Context;
use mithril_common::entities::PartyId;
use mithril_common::StdResult;
use slog_scope::info;
use std::collections::HashMap;
use std::path::Path;
use tokio::process::Child;
Expand All @@ -24,6 +26,7 @@ pub struct SignerConfig<'a> {

#[derive(Debug)]
pub struct Signer {
name: String,
party_id: PartyId,
command: MithrilCommand,
process: Option<Child>,
Expand Down Expand Up @@ -103,11 +106,11 @@ impl Signer {
env,
&args,
)?;
command.set_log_name(
format!("mithril-signer-{}-{party_id}", signer_config.signer_number).as_str(),
);
let name = format!("mithril-signer-{}-{party_id}", signer_config.signer_number);
command.set_log_name(&name);

Ok(Self {
name,
party_id,
command,
process: None,
Expand All @@ -119,6 +122,18 @@ impl Signer {
Ok(())
}

pub async fn stop(&mut self) -> StdResult<()> {
if let Some(process) = self.process.as_mut() {
let name = self.name.as_str();
info!("Stopping {name}");
process
.kill()
.await
.with_context(|| "Could not kill signer")?;
self.process = None;
}
Ok(())
}
pub async fn tail_logs(&self, number_of_line: u64) -> StdResult<()> {
self.command
.tail_logs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub async fn bootstrap_aggregator(
pool_node: &args.pool_node,
cardano_cli_path: &args.cardano_cli_path,
work_dir: &args.work_dir,
artifacts_dir: &args.work_dir,
bin_dir: &args.bin_dir,
cardano_node_version: "1.2.3",
mithril_run_interval: 1000,
Expand Down
Loading