Allowed building a HB with a non-0 starting epoch (#237)

* include the starting epoch in the HB builder

* added DHB starting epoch
This commit is contained in:
Vladimir Komendantskiy 2018-10-17 13:28:19 +01:00 committed by GitHub
parent 8a84109c88
commit f8bf552165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -15,6 +15,8 @@ use {Contribution, NetworkInfo, NodeIdT};
/// A Dynamic Honey Badger builder, to configure the parameters and create new instances of
/// `DynamicHoneyBadger`.
pub struct DynamicHoneyBadgerBuilder<C, N> {
/// Start in this epoch.
epoch: u64,
/// The maximum number of future epochs for which we handle messages simultaneously.
max_future_epochs: usize,
/// Random number generator passed on to algorithm instance for key generation. Also used to
@ -29,6 +31,7 @@ impl<C, N> Default for DynamicHoneyBadgerBuilder<C, N> {
fn default() -> Self {
// TODO: Use the defaults from `HoneyBadgerBuilder`.
DynamicHoneyBadgerBuilder {
epoch: 0,
max_future_epochs: 3,
rng: Box::new(rand::thread_rng()),
subset_handling_strategy: SubsetHandlingStrategy::Incremental,
@ -48,6 +51,12 @@ where
Self::default()
}
/// Sets the starting epoch to the given value.
pub fn epoch(&mut self, epoch: u64) -> &mut Self {
self.epoch = epoch;
self
}
/// Sets the maximum number of future epochs for which we handle messages simultaneously.
pub fn max_future_epochs(&mut self, max_future_epochs: usize) -> &mut Self {
self.max_future_epochs = max_future_epochs;
@ -72,11 +81,13 @@ where
/// Creates a new Dynamic Honey Badger instance with an empty buffer.
pub fn build(&mut self, netinfo: NetworkInfo<N>) -> DynamicHoneyBadger<C, N> {
let DynamicHoneyBadgerBuilder {
epoch,
max_future_epochs,
rng,
subset_handling_strategy,
_phantom,
} = self;
let epoch = *epoch;
let max_future_epochs = *max_future_epochs;
let arc_netinfo = Arc::new(netinfo.clone());
let honey_badger = HoneyBadger::builder(arc_netinfo.clone())
@ -87,7 +98,7 @@ where
DynamicHoneyBadger {
netinfo,
max_future_epochs,
start_epoch: 0,
start_epoch: epoch,
vote_counter: VoteCounter::new(arc_netinfo, 0),
key_gen_msg_buffer: Vec::new(),
honey_badger,

View File

@ -14,6 +14,8 @@ use {Contribution, NetworkInfo, NodeIdT};
pub struct HoneyBadgerBuilder<C, N> {
/// Shared network data.
netinfo: Arc<NetworkInfo<N>>,
/// Start in this epoch.
epoch: u64,
/// The maximum number of future epochs for which we handle messages simultaneously.
max_future_epochs: usize,
/// Random number generator passed on to algorithm instance for signing and encrypting.
@ -33,6 +35,7 @@ where
pub fn new(netinfo: Arc<NetworkInfo<N>>) -> Self {
HoneyBadgerBuilder {
netinfo,
epoch: 0,
max_future_epochs: 3,
rng: Box::new(rand::thread_rng()),
subset_handling_strategy: SubsetHandlingStrategy::Incremental,
@ -46,6 +49,12 @@ where
self
}
/// Sets the starting epoch to the given value.
pub fn epoch(&mut self, epoch: u64) -> &mut Self {
self.epoch = epoch;
self
}
/// Sets the maximum number of future epochs for which we handle messages simultaneously.
pub fn max_future_epochs(&mut self, max_future_epochs: usize) -> &mut Self {
self.max_future_epochs = max_future_epochs;
@ -65,7 +74,7 @@ where
pub fn build(&mut self) -> HoneyBadger<C, N> {
HoneyBadger {
netinfo: self.netinfo.clone(),
epoch: 0,
epoch: self.epoch,
has_input: false,
epochs: BTreeMap::new(),
max_future_epochs: self.max_future_epochs as u64,