pub struct BatchVerifier<V: Variant, D: Digest> { /* private fields */ }
Expand description
BatchVerifier
is a utility for tracking and batch verifying consensus messages.
In consensus, verifying multiple signatures at the same time can be much more efficient than verifying them one by one. This struct collects messages from participants in consensus and signals they are ready to be verified when certain conditions are met (e.g., enough messages to potentially reach a quorum, or when a leader’s message is received).
To avoid unnecessary verification, it also tracks the number of already verified messages (ensuring we no longer attempt to verify messages after a quorum of valid messages have already been verified).
Implementations§
Source§impl<V: Variant, D: Digest> BatchVerifier<V, D>
impl<V: Variant, D: Digest> BatchVerifier<V, D>
Sourcepub fn new(quorum: Option<u32>) -> Self
pub fn new(quorum: Option<u32>) -> Self
Creates a new BatchVerifier
.
§Arguments
quorum
- An optionalu32
specifying the number of votes (2f+1) required to reach a quorum. IfNone
, batch verification readiness checks based on quorum size are skipped.
Sourcepub fn add(&mut self, msg: Voter<V, D>, verified: bool)
pub fn add(&mut self, msg: Voter<V, D>, verified: bool)
Adds a Voter message to the batch for later verification.
If the message has already been verified (e.g., we built it), it increments the count of verified messages directly. Otherwise, it adds the message to the appropriate pending queue.
If a leader is known and the message is a Voter::Notarize from that leader,
this method may trigger set_leader_proposal
.
Recovered messages (e.g., Voter::Notarization, Voter::Nullification, Voter::Finalization) are not expected here and will cause a panic.
§Arguments
msg
- The Voter message to add.verified
- A boolean indicating if the message has already been verified.
Sourcepub fn set_leader(&mut self, leader: u32)
pub fn set_leader(&mut self, leader: u32)
Sets the leader for the current consensus view.
If the leader is found, we may call set_leader_proposal
to clear any pending
messages that are not for the leader’s proposal and to force verification of said
proposal.
§Arguments
leader
- Theu32
identifier of the leader.
Sourcepub fn verify_notarizes(
&mut self,
namespace: &[u8],
polynomial: &[V::Public],
) -> (Vec<Voter<V, D>>, Vec<u32>)
pub fn verify_notarizes( &mut self, namespace: &[u8], polynomial: &[V::Public], ) -> (Vec<Voter<V, D>>, Vec<u32>)
Verifies a batch of pending Voter::Notarize messages.
It uses Notarize::verify_multiple
for efficient batch verification against
the provided polynomial
.
§Arguments
namespace
- The namespace for signature domain separation.polynomial
- The public polynomial (Poly<V::Public>
) of the DKG.
§Returns
A tuple containing:
- A
Vec<Voter<V, D>>
of successfully verified Voter::Notarize messages (wrapped as Voter). - A
Vec<u32>
of signer indices for whom verification failed.
Sourcepub fn ready_notarizes(&self) -> bool
pub fn ready_notarizes(&self) -> bool
Checks if there are Voter::Notarize messages ready for batch verification.
Verification is considered “ready” if:
notarizes_force
is true (e.g., after a leader’s proposal is set).- A leader and their proposal are known, and: a. The quorum (if set) has not yet been met by verified messages. b. The sum of verified and pending messages is enough to potentially reach the quorum.
- There are pending Voter::Notarize messages to verify.
§Returns
true
if Voter::Notarize messages should be verified, false
otherwise.
Sourcepub fn verify_nullifies(
&mut self,
namespace: &[u8],
polynomial: &[V::Public],
) -> (Vec<Voter<V, D>>, Vec<u32>)
pub fn verify_nullifies( &mut self, namespace: &[u8], polynomial: &[V::Public], ) -> (Vec<Voter<V, D>>, Vec<u32>)
Verifies a batch of pending Voter::Nullify messages.
It uses Nullify::verify_multiple
for efficient batch verification against
the provided polynomial
.
§Arguments
namespace
- The namespace for signature domain separation.polynomial
- The public polynomial (Poly<V::Public>
) of the DKG.
§Returns
A tuple containing:
- A
Vec<Voter<V, D>>
of successfully verified Voter::Nullify messages (wrapped as Voter). - A
Vec<u32>
of signer indices for whom verification failed.
Sourcepub fn ready_nullifies(&self) -> bool
pub fn ready_nullifies(&self) -> bool
Checks if there are Voter::Nullify messages ready for batch verification.
Verification is considered “ready” if:
- The quorum (if set) has not yet been met by verified messages.
- The sum of verified and pending messages is enough to potentially reach the quorum.
- There are pending Voter::Nullify messages to verify.
§Returns
true
if Voter::Nullify messages should be verified, false
otherwise.
Sourcepub fn verify_finalizes(
&mut self,
namespace: &[u8],
polynomial: &[V::Public],
) -> (Vec<Voter<V, D>>, Vec<u32>)
pub fn verify_finalizes( &mut self, namespace: &[u8], polynomial: &[V::Public], ) -> (Vec<Voter<V, D>>, Vec<u32>)
Verifies a batch of pending Voter::Finalize messages.
It uses Finalize::verify_multiple
for efficient batch verification against
the provided polynomial
.
§Arguments
namespace
- The namespace for signature domain separation.polynomial
- The public polynomial (Poly<V::Public>
) of the DKG.
§Returns
A tuple containing:
- A
Vec<Voter<V, D>>
of successfully verified Voter::Finalize messages (wrapped as Voter). - A
Vec<u32>
of signer indices for whom verification failed.
Sourcepub fn ready_finalizes(&self) -> bool
pub fn ready_finalizes(&self) -> bool
Checks if there are Voter::Finalize messages ready for batch verification.
Verification is considered “ready” if:
- A leader and their proposal are known (finalizes are proposal-specific).
- The quorum (if set) has not yet been met by verified messages.
- The sum of verified and pending messages is enough to potentially reach the quorum.
- There are pending Voter::Finalize messages to verify.
§Returns
true
if Voter::Finalize messages should be verified, false
otherwise.
Auto Trait Implementations§
impl<V, D> Freeze for BatchVerifier<V, D>where
D: Freeze,
impl<V, D> RefUnwindSafe for BatchVerifier<V, D>
impl<V, D> Send for BatchVerifier<V, D>
impl<V, D> Sync for BatchVerifier<V, D>
impl<V, D> Unpin for BatchVerifier<V, D>
impl<V, D> UnwindSafe for BatchVerifier<V, D>
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 with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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