Skip to content

Commit e19d586

Browse files
committed
feat: support Mithril era reader adapter configuration in end to end test
1 parent b266e54 commit e19d586

File tree

7 files changed

+72
-47
lines changed

7 files changed

+72
-47
lines changed

mithril-test-lab/mithril-end-to-end/src/assertions/exec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub async fn register_era_marker(
2727

2828
info!("> generating era marker tx datum...");
2929
let tx_datum_file_path = devnet
30-
.artifacts_dir
30+
.artifacts_dir()
3131
.join(PathBuf::from("era-tx-datum.txt".to_string()));
3232
aggregator
3333
.era_generate_tx_datum(&tx_datum_file_path, mithril_era)

mithril-test-lab/mithril-end-to-end/src/devnet/runner.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tokio::process::Command;
1010

1111
#[derive(Debug, Clone, Default)]
1212
pub struct Devnet {
13-
pub artifacts_dir: PathBuf,
13+
artifacts_dir: PathBuf,
1414
number_of_bft_nodes: u8,
1515
number_of_pool_nodes: u8,
1616
}
@@ -148,6 +148,10 @@ impl Devnet {
148148
}
149149
}
150150

151+
pub fn artifacts_dir(&self) -> PathBuf {
152+
self.artifacts_dir.clone()
153+
}
154+
151155
pub fn mithril_era_marker_address_path(&self) -> PathBuf {
152156
self.artifacts_dir
153157
.join("addresses")

mithril-test-lab/mithril-end-to-end/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ pub struct Args {
6262
#[clap(long, default_value = "thales")]
6363
mithril_era: String,
6464

65+
/// Mithril era reader adapter
66+
#[clap(long, default_value = "cardano-chain")]
67+
mithril_era_reader_adapter: String,
68+
6569
/// Signed entity types parameters (discriminants names in an ordered comma separated list).
6670
#[clap(long, value_delimiter = ',', default_value = "")]
6771
signed_entity_types: Vec<String>,
@@ -140,6 +144,7 @@ async fn main() -> StdResult<()> {
140144
work_dir,
141145
bin_dir: args.bin_directory,
142146
mithril_era: args.mithril_era,
147+
mithril_era_reader_adapter: args.mithril_era_reader_adapter,
143148
signed_entity_types: args.signed_entity_types,
144149
run_only_mode,
145150
use_p2p_network_mode,

mithril-test-lab/mithril-end-to-end/src/mithril/aggregator.rs

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct AggregatorConfig<'a> {
2020
pub work_dir: &'a Path,
2121
pub bin_dir: &'a Path,
2222
pub mithril_era: &'a str,
23+
pub mithril_era_reader_adapter: &'a str,
2324
pub mithril_era_marker_address: &'a str,
2425
pub signed_entity_types: &'a [String],
2526
pub chain_observer_type: &'a str,
@@ -37,10 +38,18 @@ impl Aggregator {
3738
pub fn new(aggregator_config: &AggregatorConfig) -> StdResult<Self> {
3839
let magic_id = DEVNET_MAGIC_ID.to_string();
3940
let server_port_parameter = aggregator_config.server_port.to_string();
40-
let era_reader_adapter_params = format!(
41-
r#"{{"address": "{}", "verification_key": "{}"}}"#,
42-
aggregator_config.mithril_era_marker_address, ERA_MARKERS_VERIFICATION_KEY
43-
);
41+
let era_reader_adapter_params =
42+
if aggregator_config.mithril_era_reader_adapter == "cardano-chain" {
43+
format!(
44+
r#"{{"address": "{}", "verification_key": "{}"}}"#,
45+
aggregator_config.mithril_era_marker_address, ERA_MARKERS_VERIFICATION_KEY
46+
)
47+
} else {
48+
format!(
49+
r#"{{"markers": [{{"name": "{}", "epoch": 0}}]}}"#,
50+
aggregator_config.mithril_era
51+
)
52+
};
4453
let signed_entity_types = aggregator_config.signed_entity_types.join(",");
4554
let env = HashMap::from([
4655
("NETWORK", "devnet"),
@@ -63,7 +72,10 @@ impl Aggregator {
6372
),
6473
("GENESIS_VERIFICATION_KEY", GENESIS_VERIFICATION_KEY),
6574
("GENESIS_SECRET_KEY", GENESIS_SECRET_KEY),
66-
("ERA_READER_ADAPTER_TYPE", "cardano-chain"),
75+
(
76+
"ERA_READER_ADAPTER_TYPE",
77+
aggregator_config.mithril_era_reader_adapter,
78+
),
6779
("ERA_READER_ADAPTER_PARAMS", &era_reader_adapter_params),
6880
("SIGNED_ENTITY_TYPES", &signed_entity_types),
6981
("CARDANO_NODE_VERSION", "8.7.3"),
@@ -145,44 +157,30 @@ impl Aggregator {
145157
Ok(())
146158
}
147159

148-
// TODO: This works only for the current epoch, and needs to be fixed
149160
pub async fn era_generate_tx_datum(
150161
&mut self,
151162
target_path: &Path,
152163
mithril_era: &str,
153164
) -> StdResult<()> {
154-
let mithril_eras = SupportedEra::eras();
155-
let args = if mithril_eras
156-
.iter()
157-
.position(|&era| era.to_string() == mithril_era)
158-
== Some(0)
159-
{
160-
// Current era
161-
vec![
162-
"era".to_string(),
163-
"generate-tx-datum".to_string(),
164-
"--current-era-epoch".to_string(),
165-
"0".to_string(),
166-
"--era-markers-secret-key".to_string(),
167-
ERA_MARKERS_SECRET_KEY.to_string(),
168-
"--target-path".to_string(),
169-
target_path.to_str().unwrap().to_string(),
170-
]
171-
} else {
172-
// Next era
173-
vec![
174-
"era".to_string(),
175-
"generate-tx-datum".to_string(),
176-
"--current-era-epoch".to_string(),
177-
"0".to_string(),
178-
"--next-era-epoch".to_string(),
179-
"1".to_string(),
180-
"--era-markers-secret-key".to_string(),
181-
ERA_MARKERS_SECRET_KEY.to_string(),
182-
"--target-path".to_string(),
183-
target_path.to_str().unwrap().to_string(),
184-
]
185-
};
165+
let is_not_first_era =
166+
SupportedEra::eras().first().map(|e| e.to_string()) != Some(mithril_era.to_string());
167+
168+
let mut args = vec![
169+
"era".to_string(),
170+
"generate-tx-datum".to_string(),
171+
"--current-era-epoch".to_string(),
172+
"0".to_string(),
173+
"--era-markers-secret-key".to_string(),
174+
ERA_MARKERS_SECRET_KEY.to_string(),
175+
"--target-path".to_string(),
176+
target_path.to_str().unwrap().to_string(),
177+
];
178+
179+
// If only the first available era is targeted we have no "next-era" to activate
180+
if is_not_first_era {
181+
args.push("--next-era-epoch".to_string());
182+
args.push("1".to_string());
183+
}
186184

187185
let exit_status = self
188186
.command

mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct MithrilInfrastructureConfig {
2121
pub work_dir: PathBuf,
2222
pub bin_dir: PathBuf,
2323
pub mithril_era: String,
24+
pub mithril_era_reader_adapter: String,
2425
pub signed_entity_types: Vec<String>,
2526
pub run_only_mode: bool,
2627
pub use_p2p_network_mode: bool,
@@ -54,6 +55,7 @@ impl MithrilInfrastructure {
5455
work_dir: &config.work_dir,
5556
bin_dir: &config.bin_dir,
5657
mithril_era: &config.mithril_era,
58+
mithril_era_reader_adapter: &config.mithril_era_reader_adapter,
5759
mithril_era_marker_address: &config.devnet.mithril_era_marker_address()?,
5860
signed_entity_types: &config.signed_entity_types,
5961
chain_observer_type,
@@ -63,8 +65,10 @@ impl MithrilInfrastructure {
6365
m: 100,
6466
phi_f: 0.95,
6567
});
66-
assertions::register_era_marker(&mut aggregator, &config.devnet, &config.mithril_era)
67-
.await?;
68+
if config.mithril_era_reader_adapter == "cardano-chain" {
69+
assertions::register_era_marker(&mut aggregator, &config.devnet, &config.mithril_era)
70+
.await?;
71+
}
6872
aggregator.serve()?;
6973

7074
let mut relay_aggregators: Vec<RelayAggregator> = vec![];
@@ -116,6 +120,7 @@ impl MithrilInfrastructure {
116120
work_dir: &config.work_dir,
117121
bin_dir: &config.bin_dir,
118122
mithril_era: &config.mithril_era,
123+
mithril_era_reader_adapter: &config.mithril_era_reader_adapter,
119124
mithril_era_marker_address: &config.devnet.mithril_era_marker_address()?,
120125
enable_certification,
121126
})?;

mithril-test-lab/mithril-end-to-end/src/mithril/signer.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub struct SignerConfig<'a> {
1515
pub work_dir: &'a Path,
1616
pub bin_dir: &'a Path,
1717
pub mithril_era: &'a str,
18+
pub mithril_era_reader_adapter: &'a str,
1819
pub mithril_era_marker_address: &'a str,
1920
pub enable_certification: bool,
2021
}
@@ -31,10 +32,18 @@ impl Signer {
3132
let party_id = signer_config.pool_node.party_id()?;
3233
let magic_id = DEVNET_MAGIC_ID.to_string();
3334
let data_stores_path = format!("./stores/signer-{party_id}");
34-
let era_reader_adapter_params = format!(
35-
r#"{{"address": "{}", "verification_key": "{}"}}"#,
36-
signer_config.mithril_era_marker_address, ERA_MARKERS_VERIFICATION_KEY
37-
);
35+
let era_reader_adapter_params =
36+
if signer_config.mithril_era_reader_adapter == "cardano-chain" {
37+
format!(
38+
r#"{{"address": "{}", "verification_key": "{}"}}"#,
39+
signer_config.mithril_era_marker_address, ERA_MARKERS_VERIFICATION_KEY
40+
)
41+
} else {
42+
format!(
43+
r#"{{"markers": [{{"name": "{}", "epoch": 0}}]}}"#,
44+
signer_config.mithril_era
45+
)
46+
};
3847
let mut env = HashMap::from([
3948
("NETWORK", "devnet"),
4049
("RUN_INTERVAL", "100"),
@@ -53,7 +62,10 @@ impl Signer {
5362
"CARDANO_CLI_PATH",
5463
signer_config.cardano_cli_path.to_str().unwrap(),
5564
),
56-
("ERA_READER_ADAPTER_TYPE", "cardano-chain"),
65+
(
66+
"ERA_READER_ADAPTER_TYPE",
67+
signer_config.mithril_era_reader_adapter,
68+
),
5769
("ERA_READER_ADAPTER_PARAMS", &era_reader_adapter_params),
5870
]);
5971
if signer_config.enable_certification {

mithril-test-lab/mithril-end-to-end/src/stress_test/aggregator_helpers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub async fn bootstrap_aggregator(
2626
bin_dir: &args.bin_dir,
2727
mithril_era: &args.mithril_era,
2828
mithril_era_marker_address: "",
29+
mithril_era_reader_adapter: "dummy",
2930
signed_entity_types: &signed_entity_types,
3031
chain_observer_type,
3132
})

0 commit comments

Comments
 (0)