The following article will describe the Proof of Authority (PoA) consensus algorithm Aura. It is expected that the reader is familiar with the basic structures and algorithms of blockchain technology.
Because the blockchain is distributed in a peer-to-peer network, every node needs to come to an agreement on what is the truth. The network participants send transactions, which need to be accepted into a new block. To ensure that everyone is having the same blocks, the blockchain is governed by a consensus algorithm that dictates which block is valid. Most commonly known is the Proof of Work algorithm. This algorithm relies on a mathematical function that requires the miner (the person trying to create a new block) to find a hash value with certain criteria. If he found the hash, he has proof that he did the work, required to publish a new block of transactions.
There are many other consensus algorithms. The Energy Web test chain "Tobalaba" will run on a proof of authority based on an algorithm named Aura.
Aura - Overview
Instead of allowing everyone to create a new block, this algorithm relies on a group of nodes to create new blocks. These nodes are know as authority nodes or validators. In Tobalaba validators are recorded in a smart contract that governs them.
The signing of blocks is done in rounds. Every validator gets a time slot per round in which he can create and sign one new block. In case a validator is offline or not responding, he will be skipped. The validator signing a block is called the primary. To decide who the primary is at a current time, each node keeps track of a step. A step is a value based on the unix timestamp. The current step is calculated by dividing the timestamp through the step duration (block time). Now at each step, the primary is chosen by step modulo number of validators.
Lets look at an example:
The step-duration or block time in Tobalaba will be 3 seconds. The step would now be calculated by taking the current unix timestamp 1504857547 and divide it by 3 which is 501619182. Taken an amount of 6 validators, the primary would be chosen by 501619182 % 6 = 0. Validator 0 (index of array starts with 0) is now able to sign one block. One block time later (3 seconds) the unix timestamp would be 1504857550 and divided by 3 equal 501619183 which would declare validator 1 to be the primary (501619183%6).
Aura - Chain scoring
To ensure that everyone is on the same chain, a chain scoring determines which chain is the correct one to be on. It can happen that validators go offline or looses connection. The disconnected validator still follows the protocol and produces blocks, however, when it wants to connect back to the network it needs to decide if his chain or the chain of the network is the correct one. Chain scoring is the way to determine that. The math looks like this: U128_max * h - s. The of the chain is h and s is the step of the highest block. U128_max ensures that the will always take precedence over the step. The chain that is disconnected from the mainchain (the chain with more validators) produces less blocks. During reconnect it, the mainchains is higher and will be chosen as the canonical one.
The step s in the formula is to prevent malicious behavior. If a validator decides to ignore the previous block and instead builds on top of another, his block will be rejected because his step is higher. The following figure shows how this could look like. To make it easier to read we replaced the U128_max with 1000, which still serves the same purpose in this example.
If a validator now receives Block 2 and Block 3 at the same time, Block 2 would be accepted.
Aura - Finality
To be certain that transactions will stay valid and do not get discarded because of chain reorganizations, the user should wait until the chain reaches finality. Finality is defined in a way that at least 51% of the validators sign on the chain, and then sign it again. This ensures that those blocks are set and not changeable.
Other Proof of Authority algorithms
While Aura is the most reliable implemented PoA algorithm, there are others in development. These algorithms however are not as stable as Aura. During the testing phase of Tobalaba, there might be changes or improvements to the consensus algorithm as needed.
For further reading on consensus algorithms in Parity, please see https://wiki.parity.io/Pluggable-Consensus
Q: How do I become a validator?
A: To become a validator on the Energy Web an organization needs to join the Energy Web Foundation as an affiliate. Affiliates may run "authority" nodes, which means they are entitled to validate and sign blocks.
Q: What happens when a fork occurs?
A: Please read the section on Chain scoring.
Q: Can I participate in the network without being a validator?
A: Yes. Non-validator nodes can use the functionality of the Energy Web. They can call or deploy smart contracts or make simply transfers.
Q: What happens if all validators are offline?
A: No transactions can be executed and the blockchain comes to a halt.