@@ -23,6 +23,7 @@ use timeboost_crypto::{
23
23
vess:: VessError ,
24
24
} ;
25
25
use tokio:: sync:: Notify ;
26
+ use tokio:: task:: spawn_blocking;
26
27
27
28
use crate :: DkgBundle ;
28
29
@@ -409,41 +410,48 @@ impl DkgAccumulator {
409
410
}
410
411
411
412
/// Try to add a bundle to the accumulator.
412
- pub fn try_add ( & mut self , bundle : DkgBundle ) -> Result < ( ) , VessError > {
413
+ pub async fn try_add ( & mut self , bundle : DkgBundle ) -> Result < ( ) , VessError > {
413
414
// caller should ensure that no bundles are added after finalization
414
415
if self . bundles ( ) . contains ( & bundle) || self . complete {
415
416
return Ok ( ( ) ) ;
416
417
}
417
418
418
419
let aad: & [ u8 ; 3 ] = b"dkg" ;
419
- let committee = self . store . committee ( ) ;
420
- let vess = Vess :: new_fast ( ) ;
421
-
422
- // verify the bundle based on the mode
423
- match & self . mode {
424
- AccumulatorMode :: Dkg => {
425
- vess. verify_shares (
426
- committee,
427
- self . store . sorted_keys ( ) ,
428
- bundle. vess_ct ( ) ,
429
- bundle. comm ( ) ,
430
- aad,
431
- ) ?;
432
- }
433
- AccumulatorMode :: Resharing ( combkey) => {
434
- let Some ( pub_share) = combkey. get_pub_share ( bundle. origin ( ) . 0 . into ( ) ) else {
435
- return Err ( VessError :: FailedVerification ) ;
436
- } ;
437
- vess. verify_reshares (
438
- committee,
439
- self . store . sorted_keys ( ) ,
440
- bundle. vess_ct ( ) ,
441
- bundle. comm ( ) ,
442
- aad,
443
- * pub_share,
444
- ) ?;
420
+ let committee = self . store . committee ( ) . clone ( ) ;
421
+ let sorted_keys: Vec < DkgEncKey > = self . store . sorted_keys ( ) . cloned ( ) . collect ( ) ;
422
+ let mode = self . mode . clone ( ) ;
423
+
424
+ spawn_blocking ( {
425
+ let bundle = bundle. clone ( ) ;
426
+ move || {
427
+ let vess = Vess :: new_fast ( ) ;
428
+ match mode {
429
+ AccumulatorMode :: Dkg => vess. verify_shares (
430
+ & committee,
431
+ sorted_keys. iter ( ) ,
432
+ bundle. vess_ct ( ) ,
433
+ bundle. comm ( ) ,
434
+ aad,
435
+ ) ,
436
+ AccumulatorMode :: Resharing ( combkey) => {
437
+ let Some ( pub_share) = combkey. get_pub_share ( bundle. origin ( ) . 0 . into ( ) )
438
+ else {
439
+ return Err ( VessError :: FailedVerification ) ;
440
+ } ;
441
+ vess. verify_reshares (
442
+ & committee,
443
+ sorted_keys. iter ( ) ,
444
+ bundle. vess_ct ( ) ,
445
+ bundle. comm ( ) ,
446
+ aad,
447
+ * pub_share,
448
+ )
449
+ }
450
+ }
445
451
}
446
- }
452
+ } )
453
+ . await
454
+ . map_err ( |_| VessError :: FailedVerification ) ??;
447
455
448
456
self . bundles . push ( bundle) ;
449
457
// only store the necessary amount of bundles in the accumulator
0 commit comments