@@ -7,7 +7,6 @@ use anyhow::Context;
77use axum:: { extract:: State , response:: Json } ;
88use elastic_elgamal:: { group:: Ristretto , sharing:: PublicKeySet } ;
99use futures:: FutureExt ;
10- // use futures::FutureExt;
1110use reqwest:: Client ;
1211use serde:: { Deserialize , Serialize } ;
1312use std:: sync:: Arc ;
@@ -97,17 +96,14 @@ pub async fn hamming_distance(
9796 // Remix
9897 tracing:: trace!( "remix self" ) ;
9998 let ( mut x_code, mut y_code) = {
100- let inner_state = Arc :: clone ( & state) ;
99+ let state = Arc :: clone ( & state) ;
101100 rokio:: spawn ( move || -> Result < _ , CryptoError > {
102- crypto:: remix (
103- & mut x_code,
104- & mut y_code,
105- inner_state. pub_key_set ( ) . shared_key ( ) ,
106- ) ?;
101+ crypto:: remix ( & mut x_code, & mut y_code, state. pub_key_set ( ) . shared_key ( ) ) ?;
107102 Ok ( ( x_code, y_code) )
108103 } )
109104 . await ?
110105 } ;
106+ // This algorithm runs serially and it's not fast to serialize and deserialize 2*25600 bits
111107 tracing:: trace!( "remix participants" ) ;
112108 for node in & state. crypto . participants {
113109 ( x_code, y_code) = request_remix (
@@ -120,23 +116,30 @@ pub async fn hamming_distance(
120116 . unwrap_or ( ( x_code, y_code) ) ;
121117 tracing:: trace!( id = ?node, "remix participant" ) ;
122118 }
123- let ( x_code, y_code) = ( Arc :: new ( x_code) , Arc :: new ( y_code) ) ;
119+
120+ let x_code = Arc :: new ( x_code) ;
121+ let y_code = Arc :: new ( y_code) ;
124122
125123 // Decrypt
126124 tracing:: trace!( "request shares" ) ;
127125 let ( x_shares, y_shares) = {
128- let ( x_state, y_state) = ( Arc :: clone ( & state) , Arc :: clone ( & state) ) ;
129126 let ( x_inner_code, y_inner_code) = ( Arc :: clone ( & x_code) , Arc :: clone ( & y_code) ) ;
130127
131128 let ( mut x_shares, mut y_shares, x_self_share, y_self_share) = tokio:: join!(
132129 request_all_shares( & x_code, & state) ,
133130 request_all_shares( & y_code, & state) ,
134- rokio:: spawn( move || {
135- crypto:: decryption_share_for( & x_state. crypto. active_participant, & x_inner_code)
136- } ) ,
137- rokio:: spawn( move || {
138- crypto:: decryption_share_for( & y_state. crypto. active_participant, & y_inner_code)
139- } )
131+ {
132+ let state = Arc :: clone( & state) ;
133+ rokio:: spawn( move || {
134+ crypto:: decryption_share_for( & state. crypto. active_participant, & x_inner_code)
135+ } )
136+ } ,
137+ {
138+ let state = Arc :: clone( & state) ;
139+ rokio:: spawn( move || {
140+ crypto:: decryption_share_for( & state. crypto. active_participant, & y_inner_code)
141+ } )
142+ }
140143 ) ;
141144 x_shares. push ( x_self_share) ;
142145 y_shares. push ( y_self_share) ;
0 commit comments