Skip to content

Commit

Permalink
Move cursed match up to the caller
Browse files Browse the repository at this point in the history
This way we have access to the `api` which we can use to submit an offline report on-chain.
  • Loading branch information
HCastano committed Dec 19, 2024
1 parent 3d88af1 commit 69a97cc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
28 changes: 2 additions & 26 deletions crates/threshold-signature-server/src/helpers/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
40 changes: 34 additions & 6 deletions crates/threshold-signature-server/src/user/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 69a97cc

Please sign in to comment.