Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
finiteprods committed Aug 20, 2020
1 parent 196e7e9 commit df294d6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
5 changes: 3 additions & 2 deletions rust/src/client/participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ impl Participant {
mask_len: usize,
) -> Result<MessageOwned, PetError> {
let mask_seeds = self.get_seeds(seed_dict)?;
let (model_mask, scalar_mask) = self.compute_global_mask(mask_seeds, mask_len, dummy_config())?;
let (model_mask, scalar_mask) =
self.compute_global_mask(mask_seeds, mask_len, dummy_config())?;
let payload = Sum2Owned {
sum_signature: self.sum_signature,
model_mask,
Expand Down Expand Up @@ -220,7 +221,7 @@ impl Participant {
}

/// Compute a global mask from local mask seeds.
fn compute_global_mask( // TODO rename aggregate_masks
fn compute_global_mask(
&self,
mask_seeds: Vec<MaskSeed>,
mask_len: usize,
Expand Down
4 changes: 2 additions & 2 deletions rust/src/mask/seed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ impl MaskSeed {
EncryptedMaskSeed::from_slice_unchecked(pk.encrypt(self.as_slice()).as_slice())
}

// TODO separate config for scalar mask
// TODO separate config for scalar mask - future refactoring
/// Derives a mask of given length from this seed wrt the masking configuration.
pub fn derive_mask(&self, len: usize, config: MaskConfig) -> (MaskObject, MaskObject) { // TODO rename derive_masks
pub fn derive_mask(&self, len: usize, config: MaskConfig) -> (MaskObject, MaskObject) {
let mut prng = ChaCha20Rng::from_seed(self.as_array());
let rand_ints = iter::repeat_with(|| generate_integer(&mut prng, &config.order()))
.take(len)
Expand Down
12 changes: 9 additions & 3 deletions rust/src/message/payload/sum2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,12 @@ where
fn to_bytes<T: AsMut<[u8]>>(&self, buffer: &mut T) {
let mut writer = Sum2Buffer::new_unchecked(buffer.as_mut());
self.sum_signature.to_bytes(&mut writer.sum_signature_mut());
self.model_mask.borrow().to_bytes(&mut writer.model_mask_mut());
self.scalar_mask.borrow().to_bytes(&mut writer.scalar_mask_mut());
self.model_mask
.borrow()
.to_bytes(&mut writer.model_mask_mut());
self.scalar_mask
.borrow()
.to_bytes(&mut writer.scalar_mask_mut());
}
}

Expand Down Expand Up @@ -252,7 +256,9 @@ pub(in crate::message) mod tests {
.copy_from_slice(&helpers::signature().1[..]);
let expected = helpers::mask().1;
buffer.model_mask_mut()[..expected.len()].copy_from_slice(&expected[..]);
buffer.scalar_mask_mut().copy_from_slice(&helpers::mask_1().1[..]);
buffer
.scalar_mask_mut()
.copy_from_slice(&helpers::mask_1().1[..]);
}
assert_eq!(&bytes[..], &helpers::sum2().1[..]);
}
Expand Down
8 changes: 1 addition & 7 deletions rust/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,7 @@ pub fn fetcher(event_subscriber: &EventSubscriber) -> impl Fetcher + Sync + Send
.concurrency_limit(100)
.service(SeedDictService::new(event_subscriber));

FetcherService::new(
round_params,
sum_dict,
seed_dict,
mask_length,
model,
)
FetcherService::new(round_params, sum_dict, seed_dict, mask_length, model)
}

/// Construct a [`PetMessageHandler`] service
Expand Down
7 changes: 5 additions & 2 deletions rust/src/state_machine/phases/sum2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl PhaseState<Sum2> {
shared: Shared,
sum_dict: SumDict,
model_agg: Aggregation,
scalar_agg: Aggregation
scalar_agg: Aggregation,
) -> Self {
info!("state transition");
Self {
Expand Down Expand Up @@ -206,7 +206,10 @@ impl PhaseState<Sum2> {
let sum1 = self.inner.model_mask_dict.values().sum();
let sum2: usize = self.inner.scalar_mask_dict.values().sum();
if sum1 != sum2 {
warn!("unexpected difference in mask sum count: {} vs {}", sum1, sum2);
warn!(
"unexpected difference in mask sum count: {} vs {}",
sum1, sum2
);
}
sum1
}
Expand Down
2 changes: 1 addition & 1 deletion rust/src/state_machine/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct Sum2Request {
/// The model mask computed by the participant.
pub model_mask: MaskObject,
/// The scalar mask computed by the participant.
pub scalar_mask: MaskObject
pub scalar_mask: MaskObject,
}

/// A [`StateMachine`] request.
Expand Down

0 comments on commit df294d6

Please sign in to comment.