BatchVerifier

Struct BatchVerifier 

Source
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>

Source

pub fn new(quorum: Option<u32>) -> Self

Creates a new BatchVerifier.

§Arguments
  • quorum - An optional u32 specifying the number of votes (2f+1) required to reach a quorum. If None, batch verification readiness checks based on quorum size are skipped.
Source

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.
Source

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 - The u32 identifier of the leader.
Source

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.
Source

pub fn ready_notarizes(&self) -> bool

Checks if there are Voter::Notarize messages ready for batch verification.

Verification is considered “ready” if:

  1. notarizes_force is true (e.g., after a leader’s proposal is set).
  2. 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.
  3. There are pending Voter::Notarize messages to verify.
§Returns

true if Voter::Notarize messages should be verified, false otherwise.

Source

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.
Source

pub fn ready_nullifies(&self) -> bool

Checks if there are Voter::Nullify messages ready for batch verification.

Verification is considered “ready” if:

  1. The quorum (if set) has not yet been met by verified messages.
  2. The sum of verified and pending messages is enough to potentially reach the quorum.
  3. There are pending Voter::Nullify messages to verify.
§Returns

true if Voter::Nullify messages should be verified, false otherwise.

Source

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.
Source

pub fn ready_finalizes(&self) -> bool

Checks if there are Voter::Finalize messages ready for batch verification.

Verification is considered “ready” if:

  1. A leader and their proposal are known (finalizes are proposal-specific).
  2. The quorum (if set) has not yet been met by verified messages.
  3. The sum of verified and pending messages is enough to potentially reach the quorum.
  4. 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>
where D: Unpin, <V as Variant>::Signature: Unpin,

§

impl<V, D> UnwindSafe for BatchVerifier<V, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,