ProposerSelector

Trait ProposerSelector 

Source
pub trait ProposerSelector<A: ValidatorAddress>:
    Clone
    + Send
    + Sync {
    // Required method
    fn select_proposer<'a>(
        &self,
        validator_set: &'a ValidatorSet<A>,
        height: u64,
        round: u32,
    ) -> &'a Validator<A>;
}
Expand description

A trait for selecting the proposer for a given height and round.

This trait allows consumers to provide custom proposer selection logic instead of using the default round-robin approach. This is useful for implementing more sophisticated proposer selection algorithms like VRF-based selection, weighted selection, or other custom logic.

§Example Implementation

use pathfinder_consensus::*;

struct RoundRobinProposerSelector;

impl<A: ValidatorAddress> ProposerSelector<A> for RoundRobinProposerSelector {
    fn select_proposer<'a>(
        &self,
        validator_set: &'a ValidatorSet<A>,
        height: u64,
        round: u32,
    ) -> &'a Validator<A> {
        let index = round as usize % validator_set.count();
        &validator_set.validators[index]
    }
}

Required Methods§

Source

fn select_proposer<'a>( &self, validator_set: &'a ValidatorSet<A>, height: u64, round: u32, ) -> &'a Validator<A>

Select the proposer for the given height and round.

§Arguments
  • validator_set: The set of validators eligible to propose
  • height: The blockchain height
  • round: The consensus round number
§Returns

Returns a reference to the selected validator who should propose for the given height and round.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§