diff --git a/crates/threshold-signature-server/src/helpers/signing.rs b/crates/threshold-signature-server/src/helpers/signing.rs index f8e17b5ba..609dde2f2 100644 --- a/crates/threshold-signature-server/src/helpers/signing.rs +++ b/crates/threshold-signature-server/src/helpers/signing.rs @@ -82,38 +82,14 @@ pub async fn do_signing( .map_err(|_| ProtocolErr::SessionError("Error getting lock".to_string()))? .insert(session_id.clone(), listener); - let result = open_protocol_connections( + open_protocol_connections( &sign_context.sign_init.validators_info, &session_id, signer, state, &x25519_secret_key, ) - .await; - - match result { - Ok(_) => (), - Err(e) - if matches!( - e, - ProtocolErr::ConnectionError { .. } - | ProtocolErr::EncryptedConnection { .. } - | ProtocolErr::BadSubscribeMessage { .. } - | ProtocolErr::Subscribe { .. } - ) => - { - let _account_id = match e { - ProtocolErr::ConnectionError { ref account_id, .. } => account_id, - ProtocolErr::EncryptedConnection { ref account_id, .. } => account_id, - ProtocolErr::BadSubscribeMessage { ref account_id, .. } => account_id, - ProtocolErr::Subscribe { ref account_id, .. } => account_id, - _ => unreachable!(), - }.clone(); - - return Err(e); - }, - Err(e) => return Err(e), - } + .await?; let channels = { let ready = timeout(Duration::from_secs(SETUP_TIMEOUT_SECONDS), rx_ready).await?; diff --git a/crates/threshold-signature-server/src/user/api.rs b/crates/threshold-signature-server/src/user/api.rs index c9397de91..98c0689a6 100644 --- a/crates/threshold-signature-server/src/user/api.rs +++ b/crates/threshold-signature-server/src/user/api.rs @@ -41,6 +41,7 @@ use x25519_dalek::StaticSecret; use super::UserErr; use crate::chain_api::entropy::runtime_types::pallet_registry::pallet::RegisteredInfo; +use crate::signing_client::ProtocolErr; use crate::{ chain_api::{entropy, get_api, get_rpc, EntropyConfig}, helpers::{ @@ -351,14 +352,41 @@ pub async fn sign_tx( request_limit, derivation_path, ) - .await - .map(|signature| { - ( + .await; + + let signing_protocol_output = match signing_protocol_output { + Ok(signature) => Ok(( BASE64_STANDARD.encode(signature.to_rsv_bytes()), signer.signer().sign(&signature.to_rsv_bytes()), - ) - }) - .map_err(|error| error.to_string()); + )), + Err(e) + if matches!( + e, + ProtocolErr::ConnectionError { .. } + | ProtocolErr::EncryptedConnection { .. } + | ProtocolErr::BadSubscribeMessage { .. } + | ProtocolErr::Subscribe { .. } + ) => + { + let account_id = match e { + ProtocolErr::ConnectionError { ref account_id, .. } => account_id, + ProtocolErr::EncryptedConnection { ref account_id, .. } => account_id, + ProtocolErr::BadSubscribeMessage { ref account_id, .. } => account_id, + ProtocolErr::Subscribe { ref account_id, .. } => account_id, + _ => unreachable!(), + } + .clone(); + + let report_unstable_peer_tx = + entropy::tx().staking_extension().report_unstable_peer(account_id); + submit_transaction(&api, &rpc, &signer, &report_unstable_peer_tx, None) + .await + .expect("TODO"); + + Err(e.to_string()) + }, + Err(e) => Err(e.to_string()), + }; // This response chunk is sent later with the result of the signing protocol if response_tx.try_send(serde_json::to_string(&signing_protocol_output)).is_err() {