diff --git a/crates/protocol/src/execute_protocol.rs b/crates/protocol/src/execute_protocol.rs index a6f127995..faacf151a 100644 --- a/crates/protocol/src/execute_protocol.rs +++ b/crates/protocol/src/execute_protocol.rs @@ -18,7 +18,7 @@ use num::bigint::BigUint; use rand_core::{CryptoRngCore, OsRng}; use sp_core::{sr25519, Pair}; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, RwLock}; use subxt::utils::AccountId32; use synedrion::{ ecdsa::VerifyingKey, @@ -108,11 +108,11 @@ pub async fn execute_protocol_generic( // Channel for receiving results of processing messages let (process_tx, mut process_rx) = mpsc::unbounded_channel(); let current_round = session.current_round(); - let session_arc = Arc::new(Mutex::new(session)); + let session_arc = Arc::new(RwLock::new(session)); loop { { - let session = session_arc.lock().unwrap(); + let session = session_arc.read().unwrap(); if session.can_finalize(&accum)? { break; } @@ -127,7 +127,7 @@ pub async fn execute_protocol_generic( if let ProtocolMessagePayload::MessageBundle(payload) = message.payload.clone() { if payload.session_id() == &session_id { let preprocessed = { - let session = session_arc.lock().unwrap(); + let session = session_arc.read().unwrap(); // Perform quick checks before proceeding with the verification. session.preprocess_message(&mut accum, &message.from, *payload)? }; @@ -136,7 +136,7 @@ pub async fn execute_protocol_generic( let session_clone = session_arc.clone(); let tx_clone = process_tx.clone(); tokio::spawn(async move { - let session = session_clone.lock().unwrap(); + let session = session_clone.read().unwrap(); let result = session.process_message(&mut OsRng, preprocessed).unwrap(); tx_clone.send(result).unwrap(); });