Skip to content

Commit

Permalink
Merge pull request #1588 from input-output-hk/jpraynaud/1587-relay-si…
Browse files Browse the repository at this point in the history
…gner-registrations-p2p

Mithril relay broadcasts signer registrations in P2P
  • Loading branch information
jpraynaud committed Apr 18, 2024
2 parents 2d3b463 + 07c14d8 commit 0f094fb
Show file tree
Hide file tree
Showing 18 changed files with 578 additions and 124 deletions.
100 changes: 95 additions & 5 deletions Cargo.lock

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

Expand Up @@ -89,6 +89,7 @@ services:
- SERVER_PORT=${SIGNER_RELAY_SERVER_PORT}
- AGGREGATOR_ENDPOINT=http://${AGGREGATOR_CREDENTIALS}mithril-aggregator:8080/aggregator
- DIAL_TO=/dns4/mithril-aggregator-relay/tcp/${AGGREGATOR_RELAY_LISTEN_PORT}
- SIGNER_REPEATER_DELAY=${SIGNER_RELAY_REGISTRATION_REPEATER_DELAY}
ports:
- "${SIGNER_RELAY_LISTEN_PORT}:${SIGNER_RELAY_LISTEN_PORT}"
- "${SIGNER_RELAY_SERVER_PORT}:${SIGNER_RELAY_SERVER_PORT}"
Expand Down
Expand Up @@ -147,6 +147,7 @@ services:
- SERVER_PORT=${SIGNER_RELAY_SERVER_PORT}
- AGGREGATOR_ENDPOINT=http://${AGGREGATOR_CREDENTIALS}mithril-aggregator:8080/aggregator
- DIAL_TO=/dns4/mithril-aggregator-relay/tcp/${AGGREGATOR_RELAY_LISTEN_PORT}
- SIGNER_REPEATER_DELAY=${SIGNER_RELAY_REGISTRATION_REPEATER_DELAY}
ports:
- "${SIGNER_RELAY_LISTEN_PORT}:${SIGNER_RELAY_LISTEN_PORT}"
- "${SIGNER_RELAY_SERVER_PORT}:${SIGNER_RELAY_SERVER_PORT}"
Expand Down
2 changes: 1 addition & 1 deletion mithril-infra/assets/infra.version
@@ -1 +1 @@
0.2.14
0.2.15
1 change: 1 addition & 0 deletions mithril-infra/mithril.signer.tf
Expand Up @@ -85,6 +85,7 @@ EOT
"export AGGREGATOR_RELAY_LISTEN_PORT='${local.mithril_aggregator_relay_mithril_listen_port}'",
"export SIGNER_RELAY_LISTEN_PORT='${local.mithril_signers_relay_listen_port[each.key]}'",
"export SIGNER_RELAY_SERVER_PORT='${local.mithril_signers_relay_server_port[each.key]}'",
"export SIGNER_RELAY_REGISTRATION_REPEATER_DELAY='${var.mithril_p2p_signer_registration_repeat_delay}'",
"export ENABLE_METRICS_SERVER=true",
"export METRICS_SERVER_IP=0.0.0.0",
"export METRICS_SERVER_PORT=9090",
Expand Down
6 changes: 6 additions & 0 deletions mithril-infra/variables.tf
Expand Up @@ -178,6 +178,12 @@ variable "mithril_use_p2p_network" {
default = false
}

variable "mithril_p2p_signer_registration_repeat_delay" {
type = number
description = "The repeat delay in milliseconds for the signer registration when operating in P2P mode (defaults to 1 hour)"
default = 3600 * 1000
}

locals {
mithril_network_type_suffix = var.mithril_use_p2p_network ? "-p2p" : ""
}
Expand Down
8 changes: 6 additions & 2 deletions mithril-relay/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "mithril-relay"
version = "0.1.15"
version = "0.1.16"
description = "A Mithril relay"
authors = { workspace = true }
edition = { workspace = true }
Expand All @@ -24,7 +24,11 @@ libp2p = { version = "0.53.2", features = [
"noise",
"ping",
"pnet",
"quic",
"tcp",
"tls",
"websocket-websys",
"websocket",
"yamux",
] }
mithril-common = { path = "../mithril-common", features = ["full"] }
Expand All @@ -42,5 +46,5 @@ slog-bunyan = "2.5.0"
slog-scope = "4.4.0"
slog-term = "2.9.0"
thiserror = "1.0.56"
tokio = { version = "1.35.1", features = ["full"] }
tokio = { version = "1.37.0", features = ["full"] }
warp = "0.3.6"
2 changes: 1 addition & 1 deletion mithril-relay/src/commands/passive.rs
Expand Up @@ -23,7 +23,7 @@ impl PassiveCommand {
let dial_to = self.dial_to.to_owned();
let addr: Multiaddr = format!("/ip4/0.0.0.0/tcp/{}", self.listen_port).parse()?;

let mut relay = PassiveRelay::new(&addr).start().await?;
let mut relay = PassiveRelay::start(&addr).await?;
if let Some(dial_to_address) = dial_to {
relay.dial_peer(dial_to_address.clone())?;
}
Expand Down
17 changes: 15 additions & 2 deletions mithril-relay/src/commands/signer.rs
@@ -1,3 +1,5 @@
use std::time::Duration;

use clap::Parser;
use config::{builder::DefaultState, ConfigBuilder};
use libp2p::Multiaddr;
Expand All @@ -23,6 +25,10 @@ pub struct SignerCommand {
/// Aggregator endpoint URL.
#[clap(long, env = "AGGREGATOR_ENDPOINT")]
aggregator_endpoint: String,

/// Interval at which a signer registration should be repeated in milliseconds (defaults to 1 hour)
#[clap(long, env = "SIGNER_REPEATER_DELAY", default_value_t = 3_600 * 1_000)]
signer_repeater_delay: u64,
}

impl SignerCommand {
Expand All @@ -32,8 +38,15 @@ impl SignerCommand {
let dial_to = self.dial_to.to_owned();
let addr: Multiaddr = format!("/ip4/0.0.0.0/tcp/{}", self.listen_port).parse()?;
let aggregator_endpoint = self.aggregator_endpoint.to_owned();

let mut relay = SignerRelay::start(&addr, &server_port, &aggregator_endpoint).await?;
let signer_repeater_delay = Duration::from_millis(self.signer_repeater_delay);

let mut relay = SignerRelay::start(
&addr,
&server_port,
&aggregator_endpoint,
&signer_repeater_delay,
)
.await?;
if let Some(dial_to_address) = dial_to {
relay.dial_peer(dial_to_address.clone())?;
}
Expand Down
11 changes: 9 additions & 2 deletions mithril-relay/src/lib.rs
Expand Up @@ -5,12 +5,19 @@ mod commands;
/// Peer to peer module
pub mod p2p;
mod relay;
mod repeater;

pub use commands::Args;
pub use commands::RelayCommands;
pub use relay::AggregatorRelay;
pub use relay::PassiveRelay;
pub use relay::SignerRelay;

/// The topic name where signatures are published
pub const MITHRIL_SIGNATURES_TOPIC_NAME: &str = "mithril/signatures";
/// The P2P topic names used by Mithril
pub mod mithril_p2p_topic {
/// The topic name where signer registrations are published
pub const SIGNERS: &str = "mithril/signers";

/// The topic name where signatures are published
pub const SIGNATURES: &str = "mithril/signatures";
}

0 comments on commit 0f094fb

Please sign in to comment.