From c887b6810b9b85f2df21e4fee451bdefc7fa1ff3 Mon Sep 17 00:00:00 2001 From: Sebastian Geisler Date: Mon, 7 Jan 2019 05:31:12 -0800 Subject: [PATCH] Enable DynamicHoneyBadgers to rejoin after connection loss (#366) Implementing an epoch setter for the `DynamicHoneyBadgerBuilder` enables the creation of a `DynamicHoneyBadger` that will join the consensus at a given epoch. --- src/dynamic_honey_badger/builder.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/dynamic_honey_badger/builder.rs b/src/dynamic_honey_badger/builder.rs index 1bf57002..61aacb14 100644 --- a/src/dynamic_honey_badger/builder.rs +++ b/src/dynamic_honey_badger/builder.rs @@ -15,6 +15,8 @@ use crate::{Contribution, NetworkInfo, NodeIdT}; pub struct DynamicHoneyBadgerBuilder { /// Start in this era. era: u64, + /// Start in this epoch. + epoch: u64, /// Parameters controlling Honey Badger's behavior and performance. params: Params, _phantom: PhantomData<(C, N)>, @@ -24,6 +26,7 @@ impl Default for DynamicHoneyBadgerBuilder { fn default() -> Self { DynamicHoneyBadgerBuilder { era: 0, + epoch: 0, params: Params::default(), _phantom: PhantomData, } @@ -47,6 +50,12 @@ where self } + /// Sets the starting era 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: u64) -> &mut Self { self.params.max_future_epochs = max_future_epochs; @@ -78,6 +87,7 @@ where pub fn build(&mut self, netinfo: NetworkInfo) -> DynamicHoneyBadger { let DynamicHoneyBadgerBuilder { era, + epoch, params, _phantom, } = self; @@ -85,6 +95,7 @@ where let honey_badger = HoneyBadger::builder(arc_netinfo.clone()) .session_id(*era) + .epoch(*epoch) .params(params.clone()) .build();