@@ -56,10 +56,10 @@ pub struct Output<V: Variant> {
5656 pub public : poly:: Public < V > ,
5757
5858 /// `2f + 1` commitments used to derive group polynomial.
59- pub commitments : HashMap < u32 , poly:: Public < V > > ,
59+ pub commitments : BTreeMap < u32 , poly:: Public < V > > ,
6060
6161 /// Reveals published by dealers of selected commitments.
62- pub reveals : HashMap < u32 , Vec < Share > > ,
62+ pub reveals : BTreeMap < u32 , Vec < Share > > ,
6363}
6464
6565/// Gather commitments, acknowledgements, and reveals from all dealers.
@@ -233,58 +233,47 @@ impl<P: PublicKey, V: Variant> Arbiter<P, V> {
233233
234234 // If there exist more than `2f + 1` commitments, take the first `2f + 1`
235235 // sorted by dealer index.
236- let selected = self
237- . commitments
238- . into_iter ( )
239- . take ( dealer_threshold)
240- . collect :: < Vec < _ > > ( ) ;
236+ let mut commitments = BTreeMap :: new ( ) ;
237+ let mut reveals = BTreeMap :: new ( ) ;
238+ for ( dealer_idx, ( commitment, _, shares) ) in
239+ self . commitments . into_iter ( ) . take ( dealer_threshold)
240+ {
241+ commitments. insert ( dealer_idx, commitment) ;
242+
243+ // If there are no reveals for dealer, skip
244+ if shares. is_empty ( ) {
245+ continue ;
246+ }
247+ reveals. insert ( dealer_idx, shares) ;
248+ }
241249
242250 // Recover group
243251 let public = match self . previous {
244252 Some ( previous) => {
245- let mut commitments = BTreeMap :: new ( ) ;
246- for ( dealer_idx, ( commitment, _, _) ) in & selected {
247- commitments. insert ( * dealer_idx, commitment. clone ( ) ) ;
248- }
249253 match recover_public :: < V > (
250254 & previous,
251- commitments,
255+ & commitments,
252256 self . player_threshold ,
253257 self . concurrency ,
254258 ) {
255259 Ok ( public) => public,
256260 Err ( e) => return ( Err ( e) , self . disqualified ) ,
257261 }
258262 }
259- None => {
260- let mut commitments = Vec :: new ( ) ;
261- for ( _, ( commitment, _, _) ) in & selected {
262- commitments. push ( commitment. clone ( ) ) ;
263- }
264- match construct_public :: < V > ( commitments, self . player_threshold ) {
265- Ok ( public) => public,
266- Err ( e) => return ( Err ( e) , self . disqualified ) ,
267- }
268- }
269- } ;
270-
271- // Generate output
272- let mut commitments = HashMap :: new ( ) ;
273- let mut reveals = HashMap :: new ( ) ;
274- for ( dealer_idx, ( commitment, _, shares) ) in selected {
275- commitments. insert ( dealer_idx, commitment) ;
276- if shares. is_empty ( ) {
277- continue ;
278- }
279- reveals. insert ( dealer_idx, shares) ;
280- }
281- let output = Output {
282- public,
283- commitments,
284- reveals,
263+ None => match construct_public :: < V > ( commitments. values ( ) , self . player_threshold ) {
264+ Ok ( public) => public,
265+ Err ( e) => return ( Err ( e) , self . disqualified ) ,
266+ } ,
285267 } ;
286268
287269 // Return output
288- ( Ok ( output) , self . disqualified )
270+ (
271+ Ok ( Output {
272+ public,
273+ commitments,
274+ reveals,
275+ } ) ,
276+ self . disqualified ,
277+ )
289278 }
290279}
0 commit comments