Skip to content

Commit

Permalink
Enable DynamicHoneyBadgers to rejoin after connection loss (#366)
Browse files Browse the repository at this point in the history
Implementing an epoch setter for the `DynamicHoneyBadgerBuilder` enables the creation of a `DynamicHoneyBadger` that will join the consensus at a given epoch.
  • Loading branch information
sgeisler authored and vkomenda committed Jan 7, 2019
1 parent 742ad7b commit c887b68
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/dynamic_honey_badger/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use crate::{Contribution, NetworkInfo, NodeIdT};
pub struct DynamicHoneyBadgerBuilder<C, N> {
/// 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)>,
Expand All @@ -24,6 +26,7 @@ impl<C, N: Ord> Default for DynamicHoneyBadgerBuilder<C, N> {
fn default() -> Self {
DynamicHoneyBadgerBuilder {
era: 0,
epoch: 0,
params: Params::default(),
_phantom: PhantomData,
}
Expand All @@ -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;
Expand Down Expand Up @@ -78,13 +87,15 @@ where
pub fn build(&mut self, netinfo: NetworkInfo<N>) -> DynamicHoneyBadger<C, N> {
let DynamicHoneyBadgerBuilder {
era,
epoch,
params,
_phantom,
} = self;
let arc_netinfo = Arc::new(netinfo.clone());

let honey_badger = HoneyBadger::builder(arc_netinfo.clone())
.session_id(*era)
.epoch(*epoch)
.params(params.clone())
.build();

Expand Down

0 comments on commit c887b68

Please sign in to comment.