semi sure of these changes, also a bit WIP

This commit is contained in:
Logan Collins 2018-10-21 15:47:44 -05:00
parent 813a76bb5f
commit fabd725851
3 changed files with 39 additions and 10 deletions

View File

@ -303,7 +303,7 @@ where
// If there is a new change, restart DKG. Inform the user about the current change.
step.extend(match change {
Change::Add(_,_) | Change::Remove(_) => self.update_key_gen(batch_epoch + 1, &change)?,
Change::EncryptionSchedule(_) => Step::default(), // TODO: Should this `step` contain something?
Change::EncryptionSchedule(_) => self.update_encryption_schedule(batch_epoch + 1, &change)?,
});
ChangeState::InProgress(change)
} else {
@ -326,6 +326,20 @@ where
Ok(step)
}
pub(super) fn update_encryption_schedule(&mut self, epoch: u64, change: &Change<N>) -> Result<Step<C, N>> {
// TODO: verify this implementation
self.restart_honey_badger(epoch);
if let Change::EncryptionSchedule(schedule) = change {
self.honey_badger.encryption_schedule = *schedule;
}
if self.netinfo().is_validator() {
Ok(Step::default())
// self.send_transaction() TODO: commit a message about changing schedule
} else {
Ok(Step::default())
}
}
/// If the winner of the vote has changed, restarts Key Generation for the set of nodes implied
/// by the current change.
pub(super) fn update_key_gen(&mut self, epoch: u64, change: &Change<N>) -> Result<Step<C, N>> {
@ -367,6 +381,7 @@ where
self.honey_badger = HoneyBadger::builder(netinfo)
.max_future_epochs(self.max_future_epochs)
.rng(self.rng.sub_rng())
.encryption_schedule(self.honey_badger.encryption_schedule)
.build();
}

View File

@ -34,7 +34,7 @@ pub struct HoneyBadger<C, N: Rand> {
/// Represents the optimization strategy to use for output of the `Subset` algorithm.
pub(super) subset_handling_strategy: SubsetHandlingStrategy,
/// The schedule for which rounds we should use threshold encryption.
pub(super) encryption_schedule: EncryptionSchedule,
pub(crate) encryption_schedule: EncryptionSchedule,
}
impl<C, N> fmt::Debug for HoneyBadger<C, N>
@ -103,15 +103,18 @@ where
return Ok(Step::default());
}
self.has_input = true;
let ser_prop =
bincode::serialize(&proposal).map_err(|err| ErrorKind::ProposeBincode(*err))?;
let ciphertext = self
.netinfo
.public_key_set()
.public_key()
.encrypt_with_rng(&mut self.rng, ser_prop);
let epoch = self.epoch;
let mut step = self.epoch_state_mut(epoch)?.propose(&ciphertext)?;
let ser_prop = bincode::serialize(&proposal).map_err(|err| ErrorKind::ProposeBincode(*err))?;
let mut step = if self.encryption_schedule.use_on_epoch(self.epoch) {
let ciphertext = self
.netinfo
.public_key_set()
.public_key()
.encrypt_with_rng(&mut self.rng, ser_prop);
self.epoch_state_mut(epoch)?.propose(&ciphertext)?
} else {
self.epoch_state_mut(epoch)?.propose_plain(ser_prop)?
};
step.extend(self.try_output_batches()?);
Ok(step)
}

View File

@ -27,6 +27,17 @@ pub enum EncryptionSchedule {
TickTock(u32, u32),
}
impl EncryptionSchedule {
pub fn use_on_epoch(self, epoch: u64) -> bool {
match self {
EncryptionSchedule::Always => true,
EncryptionSchedule::Never => false,
EncryptionSchedule::EveryNthEpoch(n) => (epoch % n as u64) == 0,
EncryptionSchedule::TickTock(on, off) => (epoch % (on + off) as u64) <= on as u64,
}
}
}
/// A threshold decryption error.
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
pub enum Error {