Skip to content

Commit 9b8bd3c

Browse files
committed
refactor(e2e): use signer relay modes in e2e test
1 parent 13ea666 commit 9b8bd3c

File tree

5 files changed

+99
-45
lines changed

5 files changed

+99
-45
lines changed

Diff for: Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: mithril-test-lab/mithril-end-to-end/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ clap = { version = "4.5.28", features = ["derive"] }
2121
indicatif = { version = "0.17.11", features = ["tokio"] }
2222
mithril-common = { path = "../../mithril-common", features = ["full"] }
2323
mithril-doc = { path = "../../internal/mithril-doc" }
24+
mithril-relay = { path = "../../mithril-relay"}
2425
reqwest = { version = "0.12.12", features = ["json"] }
2526
serde = { version = "1.0.217", features = ["derive"] }
2627
serde_json = "1.0.138"

Diff for: mithril-test-lab/mithril-end-to-end/src/main.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anyhow::{anyhow, Context};
22
use clap::{CommandFactory, Parser, Subcommand};
3+
use mithril_relay::SignerRelayMode;
34
use slog::{Drain, Level, Logger};
45
use slog_scope::{error, info};
56
use std::{
@@ -107,11 +108,19 @@ pub struct Args {
107108
#[clap(long)]
108109
run_only: bool,
109110

110-
/// Enable P2P network mode
111+
/// Use Mithril relays
111112
#[clap(long)]
112-
use_p2p_network: bool,
113+
use_relays: bool,
113114

114-
/// Enable P2P passive relays in P2P mode
115+
/// Signer registration relay mode (used only when 'use_relays' is set)
116+
#[clap(long, value_enum, default_value_t = SignerRelayMode::Passthrough)]
117+
relay_signer_registration_mode: SignerRelayMode,
118+
119+
/// Signature registration relay mode (used only when 'use_relays' is set)
120+
#[clap(long, value_enum, default_value_t = SignerRelayMode::P2P)]
121+
relay_signature_registration_mode: SignerRelayMode,
122+
123+
/// Enable P2P passive relays in P2P mode (used only when 'use_relays' is set)
115124
#[clap(long, default_value = "true")]
116125
use_p2p_passive_relays: bool,
117126

@@ -147,9 +156,9 @@ impl Args {
147156
if self.number_of_signers == 0 {
148157
return Err(anyhow!("At least one signer is required"));
149158
}
150-
if !self.use_p2p_network && self.number_of_aggregators >= 2 {
159+
if !self.use_relays && self.number_of_aggregators >= 2 {
151160
return Err(anyhow!(
152-
"The P2P mode must be activated to run more than one aggregator"
161+
"The 'use_relays' parameter must be activated to run more than one aggregator"
153162
));
154163
}
155164

@@ -324,7 +333,10 @@ impl App {
324333
let server_port = 8080;
325334
args.validate()?;
326335
let run_only_mode = args.run_only;
327-
let use_p2p_network_mode = args.use_p2p_network;
336+
let use_relays = args.use_relays;
337+
let relay_signer_registration_mode = args.relay_signer_registration_mode;
338+
let relay_signature_registration_mode = args.relay_signature_registration_mode;
339+
328340
let use_p2p_passive_relays = args.use_p2p_passive_relays;
329341

330342
let devnet = Devnet::bootstrap(&DevnetBootstrapArgs {
@@ -355,7 +367,9 @@ impl App {
355367
mithril_era_reader_adapter: args.mithril_era_reader_adapter,
356368
signed_entity_types: args.signed_entity_types.clone(),
357369
run_only_mode,
358-
use_p2p_network_mode,
370+
use_relays,
371+
relay_signer_registration_mode,
372+
relay_signature_registration_mode,
359373
use_p2p_passive_relays,
360374
use_era_specific_work_dir: args.mithril_next_era.is_some(),
361375
})
@@ -519,7 +533,7 @@ mod tests {
519533
"validate should fail with more than one aggregator if p2p network is not used",
520534
);
521535

522-
let args = Args::parse_from(["", "--use-p2p-network", "--number-of-aggregators", "2"]);
536+
let args = Args::parse_from(["", "--use-relays", "--number-of-aggregators", "2"]);
523537
args.validate()
524538
.expect("validate should succeed with more than one aggregator if p2p network is used");
525539
}

Diff for: mithril-test-lab/mithril-end-to-end/src/mithril/infrastructure.rs

+33-19
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
use crate::mithril::relay_signer::RelaySignerConfiguration;
2+
use crate::{
3+
assertions, Aggregator, AggregatorConfig, Client, Devnet, PoolNode, RelayAggregator,
4+
RelayPassive, RelaySigner, Signer, DEVNET_MAGIC_ID,
5+
};
16
use mithril_common::chain_observer::{ChainObserver, PallasChainObserver};
27
use mithril_common::entities::{Epoch, PartyId, ProtocolParameters};
38
use mithril_common::{CardanoNetwork, StdResult};
9+
use mithril_relay::SignerRelayMode;
410
use slog_scope::info;
511
use std::fs;
612
use std::path::PathBuf;
713
use std::sync::Arc;
814
use tokio::sync::RwLock;
915

10-
use crate::{
11-
assertions, Aggregator, AggregatorConfig, Client, Devnet, PoolNode, RelayAggregator,
12-
RelayPassive, RelaySigner, Signer, DEVNET_MAGIC_ID,
13-
};
14-
1516
use super::signer::SignerConfig;
1617

1718
pub struct MithrilInfrastructureConfig {
@@ -29,7 +30,9 @@ pub struct MithrilInfrastructureConfig {
2930
pub mithril_era_reader_adapter: String,
3031
pub signed_entity_types: Vec<String>,
3132
pub run_only_mode: bool,
32-
pub use_p2p_network_mode: bool,
33+
pub use_relays: bool,
34+
pub relay_signer_registration_mode: SignerRelayMode,
35+
pub relay_signature_registration_mode: SignerRelayMode,
3336
pub use_p2p_passive_relays: bool,
3437
pub use_era_specific_work_dir: bool,
3538
}
@@ -64,6 +67,8 @@ impl MithrilInfrastructure {
6467
.iter()
6568
.map(|s| s.party_id())
6669
.collect::<StdResult<Vec<PartyId>>>()?;
70+
let relay_signer_registration_mode = &config.relay_signer_registration_mode;
71+
let relay_signature_registration_mode = &config.relay_signature_registration_mode;
6772

6873
let aggregators =
6974
Self::start_aggregators(config, aggregator_cardano_nodes, chain_observer_type).await?;
@@ -73,8 +78,13 @@ impl MithrilInfrastructure {
7378
.collect::<Vec<_>>();
7479
let master_aggregator_endpoint = aggregator_endpoints[0].to_owned();
7580

76-
let (relay_aggregators, relay_signers, relay_passives) =
77-
Self::start_relays(config, &aggregator_endpoints, &signer_party_ids)?;
81+
let (relay_aggregators, relay_signers, relay_passives) = Self::start_relays(
82+
config,
83+
&aggregator_endpoints,
84+
&signer_party_ids,
85+
relay_signer_registration_mode.to_owned(),
86+
relay_signature_registration_mode.to_owned(),
87+
)?;
7888

7989
let signers = Self::start_signers(
8090
config,
@@ -219,8 +229,10 @@ impl MithrilInfrastructure {
219229
config: &MithrilInfrastructureConfig,
220230
aggregator_endpoints: &[String],
221231
signers_party_ids: &[PartyId],
232+
relay_signer_registration_mode: SignerRelayMode,
233+
relay_signature_registration_mode: SignerRelayMode,
222234
) -> StdResult<(Vec<RelayAggregator>, Vec<RelaySigner>, Vec<RelayPassive>)> {
223-
if !config.use_p2p_network_mode {
235+
if !config.use_relays {
224236
return Ok((vec![], vec![], vec![]));
225237
}
226238

@@ -249,15 +261,17 @@ impl MithrilInfrastructure {
249261
}
250262

251263
for (index, party_id) in signers_party_ids.iter().enumerate() {
252-
let mut relay_signer = RelaySigner::new(
253-
config.server_port + index as u64 + 200,
254-
config.server_port + index as u64 + 300,
255-
bootstrap_peer_addr.clone(),
256-
master_aggregator_endpoint,
257-
party_id.clone(),
258-
&config.work_dir,
259-
&config.bin_dir,
260-
)?;
264+
let mut relay_signer = RelaySigner::new(&RelaySignerConfiguration {
265+
listen_port: config.server_port + index as u64 + 200,
266+
server_port: config.server_port + index as u64 + 300,
267+
dial_to: bootstrap_peer_addr.clone(),
268+
relay_signer_registration_mode: relay_signer_registration_mode.clone(),
269+
relay_signature_registration_mode: relay_signature_registration_mode.clone(),
270+
aggregator_endpoint: master_aggregator_endpoint,
271+
party_id: party_id.clone(),
272+
work_dir: &config.work_dir,
273+
bin_dir: &config.bin_dir,
274+
})?;
261275
relay_signer.start()?;
262276

263277
relay_signers.push(relay_signer);
@@ -308,7 +322,7 @@ impl MithrilInfrastructure {
308322
// Or 100% of signers otherwise
309323
let enable_certification =
310324
index % 2 == 0 || cfg!(not(feature = "allow_skip_signer_certification"));
311-
let aggregator_endpoint = if config.use_p2p_network_mode {
325+
let aggregator_endpoint = if config.use_relays {
312326
relay_signers[index].endpoint()
313327
} else {
314328
master_aggregator_endpoint.clone()

Diff for: mithril-test-lab/mithril-end-to-end/src/mithril/relay_signer.rs

+41-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
use crate::utils::MithrilCommand;
22
use mithril_common::entities::PartyId;
33
use mithril_common::StdResult;
4+
use mithril_relay::SignerRelayMode;
45
use std::collections::HashMap;
56
use std::path::Path;
67
use tokio::process::Child;
78

9+
pub struct RelaySignerConfiguration<'a> {
10+
pub listen_port: u64,
11+
pub server_port: u64,
12+
pub dial_to: Option<String>,
13+
pub relay_signer_registration_mode: SignerRelayMode,
14+
pub relay_signature_registration_mode: SignerRelayMode,
15+
pub aggregator_endpoint: &'a str,
16+
pub party_id: PartyId,
17+
pub work_dir: &'a Path,
18+
pub bin_dir: &'a Path,
19+
}
20+
821
#[derive(Debug)]
922
pub struct RelaySigner {
1023
listen_port: u64,
@@ -15,35 +28,45 @@ pub struct RelaySigner {
1528
}
1629

1730
impl RelaySigner {
18-
pub fn new(
19-
listen_port: u64,
20-
server_port: u64,
21-
dial_to: Option<String>,
22-
aggregator_endpoint: &str,
23-
party_id: PartyId,
24-
work_dir: &Path,
25-
bin_dir: &Path,
26-
) -> StdResult<Self> {
27-
let listen_port_str = format!("{listen_port}");
28-
let server_port_str = format!("{server_port}");
31+
pub fn new(configuration: &RelaySignerConfiguration) -> StdResult<Self> {
32+
let listen_port_str = format!("{}", configuration.listen_port);
33+
let server_port_str = format!("{}", configuration.server_port);
34+
let relay_signer_registration_mode =
35+
configuration.relay_signer_registration_mode.to_string();
36+
let relay_signature_registration_mode =
37+
configuration.relay_signature_registration_mode.to_string();
2938
let mut env = HashMap::from([
3039
("LISTEN_PORT", listen_port_str.as_str()),
3140
("SERVER_PORT", server_port_str.as_str()),
32-
("AGGREGATOR_ENDPOINT", aggregator_endpoint),
41+
("AGGREGATOR_ENDPOINT", configuration.aggregator_endpoint),
3342
("SIGNER_REPEATER_DELAY", "100"),
43+
(
44+
"SIGNER_REGISTRATION_MODE",
45+
relay_signer_registration_mode.as_str(),
46+
),
47+
(
48+
"SIGNATURE_REGISTRATION_MODE",
49+
relay_signature_registration_mode.as_str(),
50+
),
3451
]);
35-
if let Some(dial_to) = &dial_to {
52+
if let Some(dial_to) = &configuration.dial_to {
3653
env.insert("DIAL_TO", dial_to);
3754
}
3855
let args = vec!["-vvv", "signer"];
3956

40-
let mut command = MithrilCommand::new("mithril-relay", work_dir, bin_dir, env, &args)?;
41-
command.set_log_name(format!("mithril-relay-signer-{party_id}").as_str());
57+
let mut command = MithrilCommand::new(
58+
"mithril-relay",
59+
configuration.work_dir,
60+
configuration.bin_dir,
61+
env,
62+
&args,
63+
)?;
64+
command.set_log_name(format!("mithril-relay-signer-{}", configuration.party_id).as_str());
4265

4366
Ok(Self {
44-
listen_port,
45-
server_port,
46-
party_id,
67+
listen_port: configuration.listen_port,
68+
server_port: configuration.server_port,
69+
party_id: configuration.party_id.to_owned(),
4770
command,
4871
process: None,
4972
})

0 commit comments

Comments
 (0)