QBFT
KalyChain QBFT proof of authority (PoA) consensus protocol implementation
Last updated
KalyChain QBFT proof of authority (PoA) consensus protocol implementation
Last updated
KalyChain implements the QBFT proof of authority (PoA) . QBFT is the recommended enterprise-grade consensus protocol for private networks.
In QBFT networks, approved accounts, known as validators, validate transactions and blocks. Validators take turns to create the next block. Before inserting the block onto the chain, a super-majority (greater than or equal to 2/3) of validators must first sign the block.
Existing validators propose and vote to .
The QBFT properties are:
blockperiodseconds
- The minimum block time, in seconds.
epochlength
- The number of blocks after which to reset all votes.
requesttimeoutseconds
- The timeout for each consensus round before a round change, in seconds.
blockreward
- Optional reward amount in Wei to reward the beneficiary. Defaults to zero (0). Can be specified as a hexadecimal (with 0x prefix) or decimal string value. If set, then all nodes on the network must use the identical value.
validatorcontractaddress
- Address of the validator smart contract. Required only if using a contract validator selection. The address must be identical to the address in the alloc
section. This option can also be used in the configuration item if swapping in an existing network.
miningbeneficiary
- Optional beneficiary of the blockreward
. Defaults to the validator that proposes the block. If set, then all nodes on the network must use the same beneficiary.
- RLP encoded .
The extraData
property is an RLP encoding of:
32 bytes of vanity data.
If using:
, a list of validator addresses.
, no validators.
Any validator votes. No vote is included in the genesis block.
The round the block was created on. The round in the genesis block is 0.
A list of seals of the validators (signed block hashes). No seals are included in the genesis block.
When using block header validator selection, the important information in the genesis block extra data is the list of validators. All other details have empty values in the genesis block.
Formally, extraData
in the genesis block contains:
If using block header validator selection: RLP([32 bytes Vanity, List<Validators>, No Vote, Round=Int(0), 0 Seals])
.
If using contract validator selection: RLP([32 bytes Vanity, 0 Validators, No Vote, Round=Int(0), 0 Seals])
.
!!! info
When the protocol receives a new chain head, the block time (blockperiodseconds
) timer starts. When blockperiodseconds
expires, the round timeout (requesttimeoutseconds
) timer starts and the protocol proposes a new block.
If requesttimeoutseconds
expires before adding the proposed block, a round change occurs, with the block time and timeout timers reset. The timeout period for the new round is two times requesttimeoutseconds
. The timeout period continues to double each time a round fails to add a block.
Usually, the protocol adds the proposed block before reaching requesttimeoutseconds
. A new round then starts, resetting the block time and round timeout timers. When blockperiodseconds
expires, the protocol proposes the next new block.
Once blockperiodseconds
is over, the time from proposing a block to adding the block is small (usually around one second) even in networks with geographically dispersed validators.
QBFT provides two methods to manage validators:
The methods to add or remove validators are:
!!! note
!!! example "JSON-RPC qbft_proposeValidatorVote
request example"
When more than 50% of the existing validators have published a matching proposal, the protocol adds the proposed validator to the validator pool and the validator can begin validating blocks.
!!! example "JSON-RPC qbft_getValidatorsByBlockNumber
request example"
!!! example "JSON-RPC qbft_discardValidatorVote
request example"
At each epoch transition, QBFT discards all pending votes collected from received blocks. Existing proposals remain in effect and validators re-add their vote the next time they create a block.
An epoch transition occurs every epochLength
blocks. Define epochlength
in the QBFT genesis file.
You can't use the JSON-RPC methods to add or remove validators when using a smart contract to manage nodes. You must interact with the contract functions using transactions.
QBFT requires four validators to be Byzantine fault tolerant. Byzantine fault tolerance is the ability for a blockchain network to function correctly and reach consensus despite nodes failing or propagating incorrect information to peers.
Do not specify a transition block in the past. Specifying a transition block in the past could result in unexpected behavior, such as causing the network to fork.
To update an existing network with a new blockperiodseconds
:
Stop all nodes in the network.
<FutureBlockNumber>
is the upcoming block at which to change blockperiodseconds
.
<NewValue>
is the updated value for blockperiodseconds
.
!!! example "Transitions configuration"
Restart all nodes in the network using the updated genesis file.
To update an existing network with a new blockreward
:
Stop all nodes in the network.
<FutureBlockNumber>
is the upcoming block at which to change blockreward
.
<NewValue>
is the updated value for blockreward
.
!!! example "Transitions configuration"
!!! note
Restart all nodes in the network using the updated genesis file.
To swap between block header validator selection and contract validator selection methods in an existing network:
Stop all nodes in the network.
<FutureBlockNumber>
is the upcoming block at which to change the validator selection method.
<SelectionMode>
is the validator selection mode to switch to. Valid options are contract
and blockheader
.
<ContractAddress>
is the smart contract address, if switching to the contract validator selection method.
!!! example "Transitions configuration"
Restart all nodes in the network using the updated genesis file.
To update an existing network with a new mining beneficiary:
Stop all nodes in the network.
<FutureBlockNumber>
is the upcoming block at which to change miningbeneficiary
.
<NewAddress>
is the updated 20-byte address for miningbeneficiary
. Starting at <FutureBlockNumber>
, block rewards go to this address.
!!! example "Transitions configuration"
!!! note
Restart all nodes in the network using the updated genesis file.
*[vanity data]: Validators can include anything they like as vanity data. *[RLP]: Recursive Length Prefix
- Existing validators propose and vote to add or remove validators using the QBFT JSON-RPC API methods.
- Use a smart contract to specify the validators used to propose and validate blocks.
You can use to swap between block header validator selection and contract validator selection in an existing network.
For block header validator selection, initial validators are configured in the genesis file's property, whereas the initial validators when using the contract validator selection method are configured in the genesis file's storage
section.
Enable the HTTP interface with or the WebSockets interface with .
The QBFT API methods are disabled by default. To enable them, specify the or option and include QBFT
.
.
.
.
To view validator metrics for a specified block range, use .
To propose adding a validator, call , specifying the address of the proposed validator and true
. A majority of validators must execute the call.
When the validator proposes the next block, the protocol inserts one proposal received from into the block. If blocks include all proposals, subsequent blocks proposed by the validator will not contain a vote.
To return a list of validators and confirm the addition of a proposed validator, use .
To discard your proposal after confirming the addition of a validator, call , specifying the address of the proposed validator.
The process for removing a validator is the same as adding a validator except you specify false
as the second parameter of .
In a new QBFT network by specifying the contract details in the .
If network conditions render it impossible to add and remove validators using a smart contract, you can .
The transitions
genesis configuration item allows you to specify a future block number at which to change QBFT network configuration in an existing network. For example, you can update the , , , or .
In the , add the transitions
configuration item where:
To verify the changes after the transition block, call , specifying latest
.
In the , add the transitions
configuration item where:
In the , add the transitions
configuration item where:
In the , add the transitions
configuration item where: