Docs
  • ClishaChain
  • Quick Start
    • Whats is ClishaChain
    • Install
    • Start Node
    • How To
    • Genesis File
  • Consensus
    • Proof of Authority (PoA)
    • QBFT
    • Validators
    • Bootnodes
  • Transactions
    • Transaction pool
    • Transaction types
    • Transaction Validation
  • Operate a node
    • Data storage formats
    • Events and logs
    • Backup/restore node instance
    • Add and remove validators without voting
  • JSON RPC Commands
    • Access Logs
    • Authenticate
    • Graphql
    • JSON RPC
    • RPC Pub/Sub
Powered by GitBook
On this page
  • Extra data
  • Block time
  • Add and remove validators
  • Add and remove validators using block headers
  • Add and remove validators using a smart contract
  • Minimum number of validators
  • Transitions
  • Configure block time on an existing network
  • Configure block rewards on an existing network deployment
  • Swap validator management methods
  • Configure the mining beneficiary on an existing network deployment
  1. Consensus

QBFT

ClishaChain QBFT proof of authority (PoA) consensus protocol implementation

PreviousProof of Authority (PoA)NextValidators

Last updated 10 months ago

ClishaChain 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 .

Extra data

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.

When using contract validator selection to manage validators, the list of validators is configured in the `alloc`
property's `storage` section.
[View the example smart contract] for more information on how to generate the `storage` section.

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

RLP encoding is a space-efficient object serialization scheme used in Ethereum.

Block time

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.

Add and remove validators

QBFT provides two methods to manage validators:

Add and remove validators using block headers

The methods to add or remove validators are:

!!! note

If network conditions render it impossible to add and remove validators by voting, you can
[add and remove validators without voting](add-validators-without-voting.md).

Add a validator

!!! example "JSON-RPC qbft_proposeValidatorVote request example"

```bash
curl -X POST --data '{"jsonrpc":"2.0","method":"qbft_proposeValidatorVote","params":["0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73", true], "id":1}' <JSON-RPC-endpoint:port>
```

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"

```bash
curl -X POST --data '{"jsonrpc":"2.0","method":"qbft_getValidatorsByBlockNumber","params":["latest"], "id":1}' <JSON-RPC-endpoint:port>
```

!!! example "JSON-RPC qbft_discardValidatorVote request example"

```bash
curl -X POST --data '{"jsonrpc":"2.0","method":"qbft_discardValidatorVote","params":["0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73"], "id":1}' <JSON-RPC-endpoint:port>
```

Remove a validator

Epoch transition

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.

Add and remove validators using a smart contract

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.

Minimum number of validators

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.

Transitions

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.

Configure block time on an existing network

To update an existing network with a new blockperiodseconds:

  1. 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"

     === "Syntax"
    
         ```bash
         {
           "config": {
             ...
             "qbft": {
               "blockperiodseconds": 2,
               "epochlength": 30000,
               "requesttimeoutseconds": 4
             },
             "transitions": {
               "qbft": [
                 {
                   "block": <FutureBlockNumber>,
                   "blockperiodseconds": <NewValue>
                 }
               ]
             }
           },
           ...
         }
         ```
    
     === "Example"
    
         ```bash
         {
           "config": {
             ...
             "qbft": {
               "blockperiodseconds": 2,
               "epochlength": 30000,
               "requesttimeoutseconds": 4
             },
             "transitions": {
               "qbft": [
                 {
                   "block": 1240,
                   "blockperiodseconds": 4
                 }
               ]
             }
           },
           ...
         }
         ```
  2. Restart all nodes in the network using the updated genesis file.

Configure block rewards on an existing network deployment

To update an existing network with a new blockreward:

  1. 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"

     === "Syntax"
    
         ```bash
         {
           "config": {
             ...
             "qbft": {
               "blockperiodseconds": 2,
               "epochlength": 30000,
               "requesttimeoutseconds": 4
               "blockreward": "5000000000000000"
             },
             "transitions": {
               "qbft": [
                 {
                   "block": <FutureBlockNumber>,
                   "blockreward": <NewValue>
                 },
                 {
                   "block": <FutureBlockNumber>,
                   "blockreward": <NewValue>
                 },
                 {
                   "block": <FutureBlockNumber>,
                   "blockreward": <NewValue>
                 }
               ]
             }
           },
           ...
         }
         ```
    
     === "Example"
    
         ```bash
         {
           "config": {
             ...
             "qbft": {
               "blockperiodseconds": 2,
               "epochlength": 30000,
               "requesttimeoutseconds": 4
               "blockreward": "5000000000000000"
             },
             "transitions": {
               "qbft": [
                 {
                   "block": 10,
                   "blockreward": "6000000000000000"
                 },
                 {
                   "block": 15,
                   "blockreward": "75000000000000000"
                 },
                 {
                   "block": 20,
                   "blockreward": "0"
                 }
               ]
             }
           },
           ...
         }
         ```

    !!! note

     You can add multiple `blockreward` updates in one transition object by specifying multiple future blocks.
  2. Restart all nodes in the network using the updated genesis file.

Swap validator management methods

To swap between block header validator selection and contract validator selection methods in an existing network:

  1. 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"

     === "Syntax"
    
         ```bash
         {
           "config": {
             ...
             "qbft": {
               "blockperiodseconds": 5,
               "epochlength": 30000,
               "requesttimeoutseconds": 10
             },
             "transitions": {
               "qbft": [
                 {
                   "block": <FutureBlockNumber>,
                   "validatorselectionmode": <SelectionMode>,
                   "validatorcontractaddress": <ContractAddress>
                 }
               ]
             }
           },
           ...
         }
         ```
    
     === "Example"
    
         ```bash
         {
           "config": {
             ...
             "qbft": {
               "blockperiodseconds": 5,
               "epochlength": 30000,
               "requesttimeoutseconds": 10
             },
             "transitions": {
               "qbft": [
               {
                 "block": 102885,
                 "validatorselectionmode": "contract",
                 "validatorcontractaddress": "0x0000000000000000000000000000000000007777"
               }
               ]
             }
           },
           ...
         }
         ```
  2. Restart all nodes in the network using the updated genesis file.

Configure the mining beneficiary on an existing network deployment

To update an existing network with a new mining beneficiary:

  1. 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"

     === "Syntax"
    
         ```bash
         {
           "config": {
             ...
             "qbft": {
               "blockperiodseconds": 5,
               "epochlength": 30000,
               "requesttimeoutseconds": 10
             },
             "transitions": {
               "qbft": [
               {
                 "block": <FutureBlockNumber>,
                 "miningbeneficiary": <NewAddress>
               },
               {
                 "block": <FutureBlockNumber>,
                 "miningbeneficiary": <NewAddress>
               }
               ]
             }
           },
           ...
         }
         ```
    
     === "Example"
    
         ```bash
         {
           "config": {
             ...
             "qbft": {
               "blockperiodseconds": 5,
               "epochlength": 30000,
               "requesttimeoutseconds": 10
             },
             "transitions": {
               "qbft": [
               {
                 "block": 10000,
                 "miningbeneficiary": "0x0000000000000000000000000000000000000002",
               },
               {
                 "block": 20000,
                 "miningbeneficiary": "",
               }
               ]
             }
           },
           ...
         }
         ```

    !!! note

     Setting the `miningbeneficiary` to an empty value clears out any override so that block rewards go to the
     block producer rather than a global override address.
  2. 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:

--rpc-http-enabled
--rpc-ws-enabled
--rpc-http-api
--rpc-ws-api
qbft_getPendingVotes
qbft_proposeValidatorVote
qbft_discardValidatorVote
qbft_getSignerMetrics
qbft_proposeValidatorVote
qbft_proposeValidatorVote
qbft_getValidatorsByBlockNumber
qbft_discardValidatorVote
qbft_proposeValidatorVote
qbft_getValidatorsByBlockNumber
consensus protocol
add or remove validators
transitions
validator management methods
extraData
extra data
Block header validator selection
Contract validator selection
Block header validator selection
Contract validator selection
transitions
extraData
genesis file
block time
block reward
validator management method
mining beneficiary
genesis file
genesis file
genesis file
genesis file
override smart contract validators