mirror of https://github.com/poanetwork/hbbft.git
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.
This commit is contained in:
parent
742ad7b83a
commit
c887b6810b
|
@ -15,6 +15,8 @@ use crate::{Contribution, NetworkInfo, NodeIdT};
|
||||||
pub struct DynamicHoneyBadgerBuilder<C, N> {
|
pub struct DynamicHoneyBadgerBuilder<C, N> {
|
||||||
/// Start in this era.
|
/// Start in this era.
|
||||||
era: u64,
|
era: u64,
|
||||||
|
/// Start in this epoch.
|
||||||
|
epoch: u64,
|
||||||
/// Parameters controlling Honey Badger's behavior and performance.
|
/// Parameters controlling Honey Badger's behavior and performance.
|
||||||
params: Params,
|
params: Params,
|
||||||
_phantom: PhantomData<(C, N)>,
|
_phantom: PhantomData<(C, N)>,
|
||||||
|
@ -24,6 +26,7 @@ impl<C, N: Ord> Default for DynamicHoneyBadgerBuilder<C, N> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
DynamicHoneyBadgerBuilder {
|
DynamicHoneyBadgerBuilder {
|
||||||
era: 0,
|
era: 0,
|
||||||
|
epoch: 0,
|
||||||
params: Params::default(),
|
params: Params::default(),
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
|
@ -47,6 +50,12 @@ where
|
||||||
self
|
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.
|
/// 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 {
|
pub fn max_future_epochs(&mut self, max_future_epochs: u64) -> &mut Self {
|
||||||
self.params.max_future_epochs = max_future_epochs;
|
self.params.max_future_epochs = max_future_epochs;
|
||||||
|
@ -78,6 +87,7 @@ where
|
||||||
pub fn build(&mut self, netinfo: NetworkInfo<N>) -> DynamicHoneyBadger<C, N> {
|
pub fn build(&mut self, netinfo: NetworkInfo<N>) -> DynamicHoneyBadger<C, N> {
|
||||||
let DynamicHoneyBadgerBuilder {
|
let DynamicHoneyBadgerBuilder {
|
||||||
era,
|
era,
|
||||||
|
epoch,
|
||||||
params,
|
params,
|
||||||
_phantom,
|
_phantom,
|
||||||
} = self;
|
} = self;
|
||||||
|
@ -85,6 +95,7 @@ where
|
||||||
|
|
||||||
let honey_badger = HoneyBadger::builder(arc_netinfo.clone())
|
let honey_badger = HoneyBadger::builder(arc_netinfo.clone())
|
||||||
.session_id(*era)
|
.session_id(*era)
|
||||||
|
.epoch(*epoch)
|
||||||
.params(params.clone())
|
.params(params.clone())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue