Skip to content

Commit

Permalink
Merge pull request #16 from dusk-network/fix-parallel
Browse files Browse the repository at this point in the history
Fix the `parallel` feature
  • Loading branch information
Eduardo Leegwater Simões authored Jun 27, 2024
2 parents 948f1b8 + 28d05a2 commit 0399f80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/dusk_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ jobs:
uses: dusk-network/.github/.github/workflows/run-tests.yml@main
with:
test_flags: --features=rkyv-impl,rkyv/size_16

test_parallel:
name: Nightly std tests parallel
uses: dusk-network/.github/.github/workflows/run-tests.yml@main
with:
test_flags: --features=parallel,rkyv-impl,rkyv/size_16
34 changes: 20 additions & 14 deletions src/keys/apk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,33 @@ impl APK {
/// The aggregation errors when one of the [`PublicKey`]s is made of the
/// identity or an otherwise invalid point.
pub fn aggregate(&mut self, pks: &[PublicKey]) -> Result<(), Error> {
#[cfg(not(feature = "parallel"))]
let valid_iter = pks.iter();
#[cfg(feature = "parallel")]
let iter = pks.par_iter();
let valid_iter = pks.par_iter();

#[cfg(not(feature = "parallel"))]
let iter = pks.iter();

let mut is_valid = self.0.is_valid();
let sum: G2Projective = iter
.map(|pk| {
if !pk.is_valid() {
is_valid = false;
}
G2Projective::from(pk.pk_t())
})
.sum();

if !is_valid {
let pks_valid =
valid_iter.fold(true, |acc, next| acc & next.is_valid());
#[cfg(feature = "parallel")]
let pks_valid = valid_iter
.map(PublicKey::is_valid)
.reduce(|| true, |acc, next| acc & next);

if !(self.0.is_valid() & pks_valid) {
return Err(Error::InvalidPoint);
}

#[cfg(not(feature = "parallel"))]
let sum_iter = pks.iter();
#[cfg(feature = "parallel")]
let sum_iter = pks.par_iter();

let sum: G2Projective =
sum_iter.map(|pk| G2Projective::from(pk.pk_t())).sum();

self.0 .0 = (self.0 .0 + sum).into();

Ok(())
}

Expand Down

0 comments on commit 0399f80

Please sign in to comment.