Skip to content

Commit 4895fd6

Browse files
committed
Offload verification work to dedicated pool.
1 parent 3278412 commit 4895fd6

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

timeboost-sequencer/src/decrypt.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -777,12 +777,8 @@ impl Worker {
777777
return Ok(());
778778
}
779779

780-
let key_store = {
781-
let guard = self.key_stores.read();
782-
guard
783-
.get(*committee_id)
784-
.ok_or(DecrypterError::NoCommittee(*committee_id))?
785-
.clone()
780+
let Some(key_store) = self.key_stores.read().get(*committee_id).cloned() else {
781+
return Err(DecrypterError::NoCommittee(*committee_id));
786782
};
787783

788784
let acc = if is_resharing {
@@ -797,6 +793,7 @@ impl Worker {
797793
};
798794

799795
acc.try_add(bundle)
796+
.await
800797
.map_err(|e| DecrypterError::Dkg(format!("failed to add bundle: {e}")))?;
801798

802799
// for initial DKG, try to finalize if we have enough bundles
@@ -982,7 +979,7 @@ impl Worker {
982979
Ok(Some(self.finalize_hatch(round, incl).await?))
983980
}
984981

985-
/// Get the current decryption key
982+
/// Get the current decryption key.
986983
fn decryption_key(&self) -> Result<DecryptionKey> {
987984
match &self.state {
988985
WorkerState::Running => self.dec_key.get().ok_or_else(|| {
@@ -994,7 +991,7 @@ impl Worker {
994991
}
995992
}
996993

997-
/// Get the current key store for the committee.
994+
/// Get the key store for the current committee.
998995
fn current_store(&self) -> Result<KeyStore> {
999996
let guard = self.key_stores.read();
1000997
guard

timeboost-types/src/decryption.rs

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use timeboost_crypto::{
2323
vess::VessError,
2424
};
2525
use tokio::sync::Notify;
26+
use tokio::task::spawn_blocking;
2627

2728
use crate::DkgBundle;
2829

@@ -409,41 +410,48 @@ impl DkgAccumulator {
409410
}
410411

411412
/// 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> {
413414
// caller should ensure that no bundles are added after finalization
414415
if self.bundles().contains(&bundle) || self.complete {
415416
return Ok(());
416417
}
417418

418419
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+
}
445451
}
446-
}
452+
})
453+
.await
454+
.map_err(|_| VessError::FailedVerification)??;
447455

448456
self.bundles.push(bundle);
449457
// only store the necessary amount of bundles in the accumulator

0 commit comments

Comments
 (0)