Quorum
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
| Name | Type | Description |
|---|---|---|
validators | address[] | 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
| Name | Type | Description |
|---|---|---|
appContract | address | The application contract address |
claim | bytes32 | The 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
| Name | Type | Description |
|---|---|---|
validator | address | The 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
| Name | Type | Description |
|---|---|---|
id | uint256 | The validator ID |
numOfValidatorsInFavorOf
Get the number of validators in favor of a claim.
function numOfValidatorsInFavorOf(address appContract, bytes32 claim) external view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
appContract | address | The application contract address |
claim | bytes32 | The output Merkle root hash |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Number 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
| Name | Type | Description |
|---|---|---|
appContract | address | The application contract address |
claim | bytes32 | The output Merkle root hash |
id | uint256 | The ID of the validator |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | Whether 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
| Name | Type | Description |
|---|---|---|
appContract | address | The application contract address |
claim | bytes32 | The output Merkle root hash |
Returns
| Name | Type | Description |
|---|---|---|
<none> | Votes | The 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
| Name | Type | Description |
|---|---|---|
inFavorCount | uint256 | The number of validators in favor of the claim |
inFavorById | BitMaps.BitMap | The set of validators in favor of the claim |