pub trait VotingPowerCalculator: Send + Sync {
    // Required methods
    fn voting_power_in(
        &self,
        signed_header: &SignedHeader,
        validator_set: &Set,
        trust_threshold: TrustThresholdFraction
    ) -> Result<VotingPowerTally, VerificationError>;
    fn voting_power_in_sets(
        &self,
        signed_header: &SignedHeader,
        first_set: (&Set, TrustThresholdFraction),
        second_set: (&Set, TrustThresholdFraction)
    ) -> Result<(VotingPowerTally, VotingPowerTally), VerificationError>;

    // Provided methods
    fn total_power_of(&self, validator_set: &Set) -> u64 { ... }
    fn check_enough_trust_and_signers(
        &self,
        untrusted_header: &SignedHeader,
        trusted_validators: &Set,
        trust_threshold: TrustThresholdFraction,
        untrusted_validators: &Set
    ) -> Result<(), VerificationError> { ... }
    fn check_signers_overlap(
        &self,
        untrusted_header: &SignedHeader,
        untrusted_validators: &Set
    ) -> Result<(), VerificationError> { ... }
}
Expand description

Computes the voting power in a commit against a validator set.

This trait provides default implementation of some helper functions.

Required Methods§

source

fn voting_power_in( &self, signed_header: &SignedHeader, validator_set: &Set, trust_threshold: TrustThresholdFraction ) -> Result<VotingPowerTally, VerificationError>

Compute the voting power in a header and its commit against a validator set.

Note that the returned tally may be lower than actual tally so long as it meets the trust_threshold. Furthermore, the method isn’t guaranteed to verify all the signatures present in the signed header. If there are invalid signatures, the method may or may not return an error depending on which validators those signatures correspond to.

If you have two separate sets of validators and need to check voting power for both of them, prefer Self::voting_power_in_sets method.

source

fn voting_power_in_sets( &self, signed_header: &SignedHeader, first_set: (&Set, TrustThresholdFraction), second_set: (&Set, TrustThresholdFraction) ) -> Result<(VotingPowerTally, VotingPowerTally), VerificationError>

Compute the voting power in a header and its commit against two separate validator sets.

This is equivalent to calling Self::voting_power_in on each set separately but may be more optimised. Implementators are encouraged to write a properly optimised method which avoids checking the same signature twice but for a simple unoptimised implementation the following works:

    fn voting_power_in_sets(
        &self,
        signed_header: &SignedHeader,
        first_set: (&ValidatorSet, TrustThreshold),
        second_set: (&ValidatorSet, TrustThreshold),
    ) -> Result<(VotingPowerTally, VotingPowerTally), VerificationError> {
        let first_tally = self.voting_power_in(
            signed_header,
            first_set.0,
            first_set.1,
        )?;
        let second_tally = self.voting_power_in(
            signed_header,
            first_set.0,
            first_set.1,
        )?;
        Ok((first_tally, second_tally))
    }

Provided Methods§

source

fn total_power_of(&self, validator_set: &Set) -> u64

Compute the total voting power in a validator set

source

fn check_enough_trust_and_signers( &self, untrusted_header: &SignedHeader, trusted_validators: &Set, trust_threshold: TrustThresholdFraction, untrusted_validators: &Set ) -> Result<(), VerificationError>

Check that there is enough trust between an untrusted header and given trusted and untrusted validator sets.

First of all, checks that enough validators from the trusted_validators set signed the untrusted_header to reach given trust_threshold.

Second of all, checks that enough validators from the untrusted_validators set signed the untrusted_header to reach a trust threshold of ⅔.

If both of those conditions aren’t met, it’s unspecified which error is returned.

source

fn check_signers_overlap( &self, untrusted_header: &SignedHeader, untrusted_validators: &Set ) -> Result<(), VerificationError>

Check if there is 2/3rd overlap between an untrusted header and untrusted validator set

Implementors§