Skip to content

Commit

Permalink
config for batch timeout (#540)
Browse files Browse the repository at this point in the history
* config for batch timeout

* typo
  • Loading branch information
carlomazzaferro authored Oct 16, 2024
1 parent a7202b5 commit 6dd8a64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
25 changes: 17 additions & 8 deletions iris-mpc-upgrade/src/bin/tcp_ssl_upgrade_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ async fn main() -> eyre::Result<()> {
install_tracing();
let args = UpgradeClientConfig::parse();

let batch_timeout = if let Some(batch_timeout) = args.batch_timeout_secs {
batch_timeout
} else {
BATCH_TIMEOUT_SECONDS
};

if args.party_id > 1 {
panic!("Party id must be 0, 1");
}
Expand Down Expand Up @@ -186,6 +192,7 @@ async fn main() -> eyre::Result<()> {
);
send_batch_and_wait_for_ack(
args.party_id,
batch_timeout,
&mut server1,
&mut server2,
&mut server3,
Expand All @@ -202,6 +209,7 @@ async fn main() -> eyre::Result<()> {
tracing::info!("Sending final batch of size {}", batch.len());
send_batch_and_wait_for_ack(
args.party_id,
batch_timeout,
&mut server1,
&mut server2,
&mut server3,
Expand All @@ -211,17 +219,18 @@ async fn main() -> eyre::Result<()> {
batch.clear();
}
tracing::info!("Final batch sent, waiting for acks");
wait_for_ack(&mut server1).await?;
wait_for_ack(&mut server1, batch_timeout).await?;
tracing::info!("Server 1 ack received");
wait_for_ack(&mut server2).await?;
wait_for_ack(&mut server2, batch_timeout).await?;
tracing::info!("Server 2 ack received");
wait_for_ack(&mut server3).await?;
wait_for_ack(&mut server3, batch_timeout).await?;
tracing::info!("Server 3 ack received");
Ok(())
}

async fn send_batch_and_wait_for_ack(
party_id: u8,
batch_timeout: u64,
server1: &mut TlsStream<TcpStream>,
server2: &mut TlsStream<TcpStream>,
server3: &mut TlsStream<TcpStream>,
Expand Down Expand Up @@ -312,14 +321,14 @@ async fn send_batch_and_wait_for_ack(
}

// Handle acknowledgment from all servers
wait_for_ack(server1).await?;
wait_for_ack(server2).await?;
wait_for_ack(server3).await?;
wait_for_ack(server1, batch_timeout).await?;
wait_for_ack(server2, batch_timeout).await?;
wait_for_ack(server3, batch_timeout).await?;
Ok(())
}

async fn wait_for_ack(server: &mut TlsStream<TcpStream>) -> eyre::Result<()> {
match timeout(Duration::from_secs(BATCH_TIMEOUT_SECONDS), server.read_u8()).await {
async fn wait_for_ack(server: &mut TlsStream<TcpStream>, batch_timeout: u64) -> eyre::Result<()> {
match timeout(Duration::from_secs(batch_timeout), server.read_u8()).await {
Ok(Ok(BATCH_SUCCESSFUL_ACK)) => {
// Ack received successfully
tracing::info!("ACK received for batch");
Expand Down
5 changes: 4 additions & 1 deletion iris-mpc-upgrade/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
str::FromStr,
};

pub const BATCH_TIMEOUT_SECONDS: u64 = 30;
pub const BATCH_TIMEOUT_SECONDS: u64 = 60;
pub const BATCH_SUCCESSFUL_ACK: u8 = 1;
pub const FINAL_BATCH_SUCCESSFUL_ACK: u8 = 42;

Expand Down Expand Up @@ -98,6 +98,9 @@ pub struct UpgradeClientConfig {

#[clap(long)]
pub masks_db_url: String,

#[clap(long)]
pub batch_timeout_secs: Option<u64>,
}

impl fmt::Debug for UpgradeClientConfig {
Expand Down

0 comments on commit 6dd8a64

Please sign in to comment.