1
1
use async_trait:: async_trait;
2
2
use chrono:: prelude:: * ;
3
3
use hex:: ToHex ;
4
- use slog_scope:: { debug, trace , warn} ;
4
+ use slog_scope:: { debug, warn} ;
5
5
use std:: sync:: Arc ;
6
6
use thiserror:: Error ;
7
7
@@ -211,9 +211,6 @@ pub struct MultiSignerImpl {
211
211
/// Signing start datetime of current message
212
212
current_initiated_at : Option < DateTime < Utc > > ,
213
213
214
- /// Clerk used for verifying the single signatures
215
- clerk : Option < ProtocolClerk > ,
216
-
217
214
/// Created multi signature for message signed
218
215
multi_signature : Option < ProtocolMultiSignature > ,
219
216
@@ -243,7 +240,6 @@ impl MultiSignerImpl {
243
240
current_message : None ,
244
241
current_beacon : None ,
245
242
current_initiated_at : None ,
246
- clerk : None ,
247
243
multi_signature : None ,
248
244
verification_key_store,
249
245
stake_store,
@@ -354,31 +350,6 @@ impl MultiSigner for MultiSignerImpl {
354
350
debug ! ( "Update current_message" ; "protocol_message" => #?message, "signed message" => message. compute_hash( ) . encode_hex:: <String >( ) ) ;
355
351
356
352
self . multi_signature = None ;
357
- let signers_with_stake = self . get_signers_with_stake ( ) . await ?;
358
- let protocol_parameters = self
359
- . get_protocol_parameters ( )
360
- . await ?
361
- . ok_or_else ( ProtocolError :: UnavailableProtocolParameters ) ?;
362
- match self
363
- . create_clerk ( & signers_with_stake, & protocol_parameters)
364
- . await
365
- {
366
- Ok ( Some ( clerk) ) => {
367
- trace ! ( "update_current_message::new_clerk_created" ) ;
368
- self . clerk = Some ( clerk)
369
- }
370
- Ok ( None ) => {
371
- warn ! (
372
- "update_current_message::no_clerk_created: probably not enough signers with valid verification keys" ;
373
- "signers" => ?signers_with_stake
374
- ) ;
375
- self . clerk = None
376
- }
377
- Err ( ProtocolError :: Beacon ( err) ) => {
378
- warn ! ( "update_current_message::error" ; "error" => ?err) ;
379
- }
380
- Err ( e) => return Err ( e) ,
381
- }
382
353
self . current_initiated_at = Some ( Utc :: now ( ) ) ;
383
354
self . current_message = Some ( message) ;
384
355
Ok ( ( ) )
@@ -585,15 +556,17 @@ impl MultiSigner for MultiSignerImpl {
585
556
. await ?
586
557
. ok_or_else ( ProtocolError :: UnavailableProtocolParameters ) ?;
587
558
588
- let clerk = self
589
- . clerk
590
- . as_ref ( )
591
- . ok_or_else ( ProtocolError :: UnavailableClerk ) ?;
592
-
593
559
let signature = signatures
594
560
. to_protocol_signature ( )
595
561
. map_err ( ProtocolError :: Codec ) ?;
596
562
563
+ let signers_with_stakes = self . get_signers_with_stake ( ) . await ?;
564
+
565
+ let clerk = self
566
+ . create_clerk ( & signers_with_stakes, & protocol_parameters)
567
+ . await ?
568
+ . ok_or_else ( ProtocolError :: UnavailableClerk ) ?;
569
+
597
570
let avk = clerk. compute_avk ( ) ;
598
571
599
572
// If there is no reg_party, then we simply received a signature from a non-registered
@@ -649,6 +622,11 @@ impl MultiSigner for MultiSignerImpl {
649
622
. current_beacon
650
623
. as_ref ( )
651
624
. ok_or_else ( ProtocolError :: UnavailableBeacon ) ?;
625
+ let protocol_parameters = self
626
+ . get_protocol_parameters ( )
627
+ . await ?
628
+ . ok_or_else ( ProtocolError :: UnavailableProtocolParameters ) ?;
629
+
652
630
let signatures: Vec < ProtocolSingleSignature > = self
653
631
. single_signature_store
654
632
. get_single_signatures ( beacon)
@@ -663,10 +641,13 @@ impl MultiSigner for MultiSignerImpl {
663
641
} )
664
642
. collect :: < Vec < _ > > ( ) ;
665
643
644
+ let signers_with_stakes = self . get_signers_with_stake ( ) . await ?;
645
+
666
646
let clerk = self
667
- . clerk
668
- . as_ref ( )
647
+ . create_clerk ( & signers_with_stakes , & protocol_parameters )
648
+ . await ?
669
649
. ok_or_else ( ProtocolError :: UnavailableClerk ) ?;
650
+
670
651
match clerk. aggregate ( & signatures, message. compute_hash ( ) . as_bytes ( ) ) {
671
652
Ok ( multi_signature) => {
672
653
self . multi_signature = Some ( multi_signature. clone ( ) ) ;
0 commit comments