Skip to content

Commit

Permalink
feat: add timeout handling for latency between parties
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaMasych committed Aug 21, 2024
1 parent 2fcddbf commit 890026c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/party.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub struct BPConConfig {

/// Timeout before finalization stage is launched.
pub finalize_timeout: Duration,

/// Timeout for a graceful period to help parties with latency.
pub grace_period: Duration,
}

/// Party status defines the statuses of the ballot for the particular participant
Expand Down Expand Up @@ -341,6 +344,7 @@ impl<V: Value, VS: ValueSelector<V>> Party<V, VS> {
finalize_fired = true;
},
msg_wire = self.msg_in_receiver.recv() => {
tokio::time::sleep(self.cfg.grace_period).await;
if let Some(msg_wire) = msg_wire {
if let Err(err) = self.update_state(msg_wire.content_bytes, msg_wire.routing) {
self.status = PartyStatus::Failed;
Expand All @@ -352,6 +356,7 @@ impl<V: Value, VS: ValueSelector<V>> Party<V, VS> {
}
},
event = self.event_receiver.recv() => {
tokio::time::sleep(self.cfg.grace_period).await;
if let Some(event) = event {
if let Err(err) = self.follow_event(event) {
self.status = PartyStatus::Failed;
Expand Down Expand Up @@ -756,6 +761,7 @@ mod tests {
launch2av_timeout: Duration::from_secs(30),
launch2b_timeout: Duration::from_secs(40),
finalize_timeout: Duration::from_secs(50),
grace_period: Duration::from_secs(1),
}
}

Expand Down

0 comments on commit 890026c

Please sign in to comment.