Quorum

Git Source

Inherits: AbstractConsensus

A consensus model controlled by a small, immutable set of n validators.

You can know the value of n by calling the numOfValidators function.

Upon construction, each validator is assigned a unique number between 1 and n. These numbers are used internally instead of addresses for gas optimization reasons.

You can list the validators in the quorum by calling the validatorById function for each ID from 1 to n.

State Variables

_numOfValidators

The total number of validators.

See the numOfValidators function.

uint256 private immutable _numOfValidators;

_validatorId

Validator IDs indexed by address.

See the validatorId function.

Non-validators are assigned to ID zero.

Validators have IDs greater than zero.

mapping(address => uint256) private _validatorId;

_validatorById

Validator addresses indexed by ID.

See the validatorById function.

Invalid IDs map to address zero.

mapping(uint256 => address) private _validatorById;

_votes

Votes indexed by application contract address and claim.

See the numOfValidatorsInFavorOf and isValidatorInFavorOf functions.

mapping(address => mapping(bytes32 => Votes)) private _votes;

Functions

constructor

Duplicates in the validators array are ignored.

constructor(address[] memory validators);

Parameters

NameTypeDescription
validatorsaddress[]The array of validator addresses

submitClaim

Submit a claim.

Fires a ClaimSubmission event if the message sender is a validator.

Fires a ClaimAcceptance event if the claim reaches a majority.

Can only be called by a validator.

function submitClaim(address appContract, bytes32 claim) external;

Parameters

NameTypeDescription
appContractaddressThe application contract address
claimbytes32The output Merkle root hash

numOfValidators

Get the number of validators.

function numOfValidators() external view returns (uint256);

validatorId

Get the ID of a validator.

Validators have IDs greater than zero.

Non-validators are assigned to ID zero.

function validatorId(address validator) external view returns (uint256);

Parameters

NameTypeDescription
validatoraddressThe validator address

validatorById

Get the address of a validator by its ID.

Validator IDs range from 1 to N, the total number of validators.

Invalid IDs map to address zero.

function validatorById(uint256 id) external view returns (address);

Parameters

NameTypeDescription
iduint256The validator ID

numOfValidatorsInFavorOf

Get the number of validators in favor of a claim.

function numOfValidatorsInFavorOf(address appContract, bytes32 claim) external view returns (uint256);

Parameters

NameTypeDescription
appContractaddressThe application contract address
claimbytes32The output Merkle root hash

Returns

NameTypeDescription
<none>uint256Number of validators in favor of claim

isValidatorInFavorOf

Check whether a validator is in favor of a claim.

Assumes the provided ID is valid.

function isValidatorInFavorOf(address appContract, bytes32 claim, uint256 id) external view returns (bool);

Parameters

NameTypeDescription
appContractaddressThe application contract address
claimbytes32The output Merkle root hash
iduint256The ID of the validator

Returns

NameTypeDescription
<none>boolWhether validator is in favor of claim

_getVotes

Get a Votes structure from storage from a given claim.

function _getVotes(address appContract, bytes32 claim) internal view returns (Votes storage);

Parameters

NameTypeDescription
appContractaddressThe application contract address
claimbytes32The output Merkle root hash

Returns

NameTypeDescription
<none>VotesThe Votes structure related to a given claim

Structs

Votes

Votes in favor of a particular claim.

inFavorById is a bitmap indexed by validator IDs.

struct Votes {
    uint256 inFavorCount;
    BitMaps.BitMap inFavorById;
}

Properties

NameTypeDescription
inFavorCountuint256The number of validators in favor of the claim
inFavorByIdBitMaps.BitMapThe set of validators in favor of the claim