pub struct Voter<H, N, E: Environment<H, N>, GlobalIn, GlobalOut>where
H: Clone + Eq + Ord + Debug,
N: Copy + BlockNumberOps + Debug,
GlobalIn: Stream<Item = Result<CommunicationIn<H, N, E::Signature, E::Id>, E::Error>> + Unpin,
GlobalOut: Sink<CommunicationOut<H, N, E::Signature, E::Id>, Error = E::Error> + Unpin,{ /* private fields */ }
Expand description
A future that maintains and multiplexes between different rounds, and caches votes.
This voter also implements the commit protocol. The commit protocol allows a node to broadcast a message that finalizes a given block and includes a set of precommits as proof.
- When a round is completable and we precommitted we start a commit timer and start accepting commit messages;
- When we receive a commit message if it targets a block higher than what we’ve finalized we validate it and import its precommits if valid;
- When our commit timer triggers we check if we’ve received any commit message for a block equal to what we’ve finalized, if we haven’t then we broadcast a commit.
Additionally, we also listen to commit messages from rounds that aren’t currently running, we validate the commit and dispatch a finalization notification (if any) to the environment.
Implementations§
Source§impl<'a, H, N, E, GlobalIn, GlobalOut> Voter<H, N, E, GlobalIn, GlobalOut>where
H: Clone + Ord + Debug + Sync + Send + 'a,
N: BlockNumberOps + Sync + Send,
E: Environment<H, N> + Sync + Send + 'a,
GlobalIn: Stream<Item = Result<CommunicationIn<H, N, E::Signature, E::Id>, E::Error>> + Unpin,
GlobalOut: Sink<CommunicationOut<H, N, E::Signature, E::Id>, Error = E::Error> + Unpin,
impl<'a, H, N, E, GlobalIn, GlobalOut> Voter<H, N, E, GlobalIn, GlobalOut>where
H: Clone + Ord + Debug + Sync + Send + 'a,
N: BlockNumberOps + Sync + Send,
E: Environment<H, N> + Sync + Send + 'a,
GlobalIn: Stream<Item = Result<CommunicationIn<H, N, E::Signature, E::Id>, E::Error>> + Unpin,
GlobalOut: Sink<CommunicationOut<H, N, E::Signature, E::Id>, Error = E::Error> + Unpin,
Sourcepub fn voter_state(&self) -> Box<dyn VoterState<E::Id> + Send + Sync + 'a>where
<E as Environment<H, N>>::Signature: Send,
<E as Environment<H, N>>::Id: Hash + Send,
<E as Environment<H, N>>::Timer: Send,
<E as Environment<H, N>>::Out: Send,
<E as Environment<H, N>>::In: Send,
pub fn voter_state(&self) -> Box<dyn VoterState<E::Id> + Send + Sync + 'a>where
<E as Environment<H, N>>::Signature: Send,
<E as Environment<H, N>>::Id: Hash + Send,
<E as Environment<H, N>>::Timer: Send,
<E as Environment<H, N>>::Out: Send,
<E as Environment<H, N>>::In: Send,
Returns an object allowing to query the voter state.
Source§impl<H, N, E: Environment<H, N>, GlobalIn, GlobalOut> Voter<H, N, E, GlobalIn, GlobalOut>
impl<H, N, E: Environment<H, N>, GlobalIn, GlobalOut> Voter<H, N, E, GlobalIn, GlobalOut>
Sourcepub fn new(
env: Arc<E>,
voters: VoterSet<E::Id>,
global_comms: (GlobalIn, GlobalOut),
last_round_number: u64,
last_round_votes: Vec<SignedMessage<H, N, E::Signature, E::Id>>,
last_round_base: (H, N),
last_finalized: (H, N),
) -> Self
pub fn new( env: Arc<E>, voters: VoterSet<E::Id>, global_comms: (GlobalIn, GlobalOut), last_round_number: u64, last_round_votes: Vec<SignedMessage<H, N, E::Signature, E::Id>>, last_round_base: (H, N), last_finalized: (H, N), ) -> Self
Create new Voter
tracker with given round number and base block.
Provide data about the last completed round. If there is no known last completed round, the genesis state (round number 0, no votes, genesis base), should be provided. When available, all messages required to complete the last round should be provided.
The input stream for commit messages should provide commits which correspond to known blocks only (including all its precommits). It is also responsible for validating the signature data in commit messages.
Trait Implementations§
Source§impl<H, N, E: Environment<H, N>, GlobalIn, GlobalOut> Future for Voter<H, N, E, GlobalIn, GlobalOut>
impl<H, N, E: Environment<H, N>, GlobalIn, GlobalOut> Future for Voter<H, N, E, GlobalIn, GlobalOut>
impl<H, N, E: Environment<H, N>, GlobalIn, GlobalOut> Unpin for Voter<H, N, E, GlobalIn, GlobalOut>
Auto Trait Implementations§
impl<H, N, E, GlobalIn, GlobalOut> Freeze for Voter<H, N, E, GlobalIn, GlobalOut>
impl<H, N, E, GlobalIn, GlobalOut> !RefUnwindSafe for Voter<H, N, E, GlobalIn, GlobalOut>
impl<H, N, E, GlobalIn, GlobalOut> Send for Voter<H, N, E, GlobalIn, GlobalOut>where
N: Send + Sync,
GlobalIn: Send,
E: Sync + Send,
GlobalOut: Send,
H: Send + Sync,
<E as Environment<H, N>>::In: Send,
<E as Environment<H, N>>::Id: Send,
<E as Environment<H, N>>::Out: Send,
<E as Environment<H, N>>::Timer: Send,
<E as Environment<H, N>>::Signature: Send,
impl<H, N, E, GlobalIn, GlobalOut> Sync for Voter<H, N, E, GlobalIn, GlobalOut>where
N: Sync + Send,
GlobalIn: Sync,
E: Sync + Send,
GlobalOut: Sync,
H: Sync + Send,
<E as Environment<H, N>>::In: Send,
<E as Environment<H, N>>::Id: Sync + Send,
<E as Environment<H, N>>::Out: Send,
<E as Environment<H, N>>::Timer: Send,
<E as Environment<H, N>>::Signature: Send + Sync,
impl<H, N, E, GlobalIn, GlobalOut> !UnwindSafe for Voter<H, N, E, GlobalIn, GlobalOut>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
Source§fn map_into<U>(self) -> MapInto<Self, U>
fn map_into<U>(self) -> MapInto<Self, U>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
f
. Read moreSource§fn left_future<B>(self) -> Either<Self, B>
fn left_future<B>(self) -> Either<Self, B>
Source§fn right_future<A>(self) -> Either<A, Self>
fn right_future<A>(self) -> Either<A, Self>
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll
will never again be called once it has
completed. This method can be used to turn any Future
into a
FusedFuture
. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
()
on completion and sends
its output to another future on a separate task. Read moreSource§fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
Source§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where
Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = ()
>.Source§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where
Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = Never
>.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more