Skip to content

Commit

Permalink
Use spawn_blocking when processing synedrion messages (#1285)
Browse files Browse the repository at this point in the history
Use spawn_blocking when processing synedrion messages
  • Loading branch information
ameba23 authored Feb 11, 2025
1 parent 4e24d77 commit 4a2bce4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions crates/protocol/src/execute_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use synedrion::{
AuxInfo, KeyResharingInputs, KeyShare, NewHolder, OldHolder, PrehashedMessage,
RecoverableSignature, ThresholdKeyShare,
};
use tokio::sync::mpsc;
use tokio::{sync::mpsc, task::spawn_blocking};

use crate::{
errors::{GenericProtocolError, ProtocolExecutionErr},
Expand Down Expand Up @@ -100,7 +100,7 @@ where
let tx = tx.clone();
let my_id = my_id.clone();
let destination = destination.clone();
tokio::spawn(async move {
spawn_blocking(move || {
session_arc
.make_message(&mut OsRng, &destination)
.map(|(message, artifact)| {
Expand All @@ -125,7 +125,7 @@ where
// Process cached messages
let join_handles = cached_messages.into_iter().map(|preprocessed| {
let session_arc = session_arc.clone();
tokio::spawn(async move { session_arc.process_message(&mut OsRng, preprocessed) })
spawn_blocking(move || session_arc.process_message(&mut OsRng, preprocessed))
});

for result in try_join_all(join_handles).await? {
Expand Down Expand Up @@ -154,7 +154,8 @@ where
let tx = process_tx.clone();
tokio::spawn(async move {
let result = session_arc.process_message(&mut OsRng, preprocessed);
if tx.send(result).await.is_err() {

if futures::executor::block_on(tx.send(result)).is_err() {
tracing::error!("Protocol finished before message processing result sent");
}
});
Expand Down

0 comments on commit 4a2bce4

Please sign in to comment.