# Aphelion Consensus Algorithm

## Summary


A lot of research has been carried out regarding Artificial Intelligence (AI) and its application in the real world. Blockchain also emerged as an important technology in the 2010s. Blockchain's decentralized architecture presents a lot of complex issues, but with AI as the basis of a consensus algorithm, the blockchain system can be redefined to have much higher real-world scalability, decentralization and security. An AI-enabled blockchain can even solve a long-present problem—seamless connection between different blockchains, private and public.

Aphelion is an **AI-governed autonomous blockchain consensus engine**. It's responsible for running many tasks while governing the blockchain, starting from simple ones like extracting features and categorizing nodes that join the network, and ending with detecting security attacks and adjusting network's parameters through time to guarantee the best performance and efficiency at all times.

## Discussion

### What are the key values of decentralized technology?

Three key values of blockchain technology are scalability, decentralization and security. However, blockchain has struggled to strive in all three areas simultaneously. Most of the blockchains right now are trade-off systems. 

**Scalability** defines how fast blockchain is in a real-world environment in terms of transactions per second and block finality. Most of the blockchains today are too slow to sustain the use cases and expand.

**Decentralization** is a process of distributing decision-making power from a central authority to the network participants. The main reasons that affect a network's decentralization are governance setup, utility, update model, knowledge and investment requirement, and reward system.

**Security** reflects on 51% attack, double spending, DDOS, poorly written code, off-chain implementations and other issues. Solutions that blockchains propose are very complex. Therefore, many blockchains still face security breaches.

**Interoperability** is another core value. It's the ability of blockchains to communicate with one another. Making transactions from one blockchain to another is a huge milestone, but till now it's not been possible in a decentralized manner, without the use of atomic swap, offline signatures or central authoritative control. 


### How is Aphelion solving the blockchain problems?

Aphelion, a concept in blockchain technology that emerged in 2020, is an AI-governed autonomous blockchain consensus engine. With the inclusion of AI in the consensus engine, it enables blockchain to be performant with respect to scalability, decentralization and security.

Aphelion is involved in many tasks, first of which occurs right when nodes join the network. AI evaluates node prior contribution as well as technical characteristics that typically include computing power, disk space, and network speed. This information is combined to understand the nature of the nodes that helps the engine to classify them into different node pools.

Node pools are used to improve the system's efficiency by dividing the workload among them. After each dataset, Aphelion consensus records the performance and learns. Thus in future, it's able to make better predictions on how to split the workload and further increase the efficiency of the system. 


### What are other benefits of utilizing Aphelion in blockchain?

Current blockchains lack a fair distribution of nodes in the network. There's always a bottleneck in terms of performance. With multiple pools, Aphelion presents a new mechanism for the blockchain. It accommodates high-performance and low-performance systems, thus not just improving the blockchain's scalability, but also network's decentralization as all nodes on the system, even mobile ones, have a fair chance at contributing and earning rewards. 

It's also important to highlight that the major difficulty in utilizing AI in decentralized networks is that artificial agents need to be decentralized as well. Earlier systems lacked this capability and therefore couldn't achieve full decentralization. Aphelion fills that gap successfully with the introduction of an AI-based consensus engine that's completely decentralized.


### What information is gathered from nodes?

To mitigate the issue of taking control of the network and throughput of the blockchain, a feature extraction agent is used to extract system information that can be used to predict not only the performance of the system but also its overall effect on the network in terms of scalability and security. A feature extraction engine extracts node features at the time of their initialization and communicates the extracted data to all the classification agents running on the network. 

The four major features that are required for the classification agent includes the node's computing power, bandwidth, contribution and life of a node. For these features, the extraction algorithm, after extracting the data, tags the data with the node's key to remove any kind of duplication and prepares the feature matrix `M = {X1, X2, X3}`:

    + `X1 = {Power Ratio, Life-time, Contribution}`
    + `X2 = {Latency, Connections, Bandwidth}`
    + `X3 = {Assignment probability, Removal probability}`Aphelion uses these features to classify each node to one of the four pools: Power Pool, Exploit Finding Pool, Audit Pool, and Maintenance Pool. 


### What else is important for the feature extraction?

**Dataset cleansing**: Once the features are extracted and are received by the classification agent, the dataset for the agent is prepared. The cleansing process includes data detecting and correcting corrupt or inaccurate records, which will be modified according to a specific use case.

**Normalization**: After cleansing the data, it's normalized to avoid any inaccurate learning. Normalization is one of the most important steps before the data is given to any ML or AI algorithm. To normalize the dataset linear scaling formula is used.

**Splitting dataset**: Dataset is split into three portions. 70% of the data will be used for training, 15% of the data will be used for testing and the remaining 15% will be used for validation. 


### What is the Power pool?

Power pool is where all the transactions and activities take place. Nodes here are differentiated into three different classes named Lightning nodes, Medium nodes and Lower nodes. With the inclusion of pools and their subclasses Aphelion protocol gives the blockchain an ability to accommodate any kind of node to join the network and participate in validating the transactions. 


### What is the Exploit-Finding (EF) pool?

Exploit finding pool serves as the security layer for the blockchain - to save the blockchain from any kind of exploit that could disrupt the whole system. Nodes in the EF pool work collectively to verify and index the blocks included by the power pool. 

When any vulnerabilities are exposed, the decision agent is reported and the necessary steps are taken to secure the system beforehand. The dataset is constantly being provided to the decision agent, which predicts the behavior of the nodes in complex scenarios. Exploiting attempts are carried by the algorithm on the isolated copy of the current blockchain, to ensure if there is any kind of vulnerability present and calculate the steps that can be taken by the system for it to behave as it is intended to. 


### What is the Audit pool?

Due to inclusion of multi-pool architecture and the decision agent, there is a possibility that invalid data can be provided to the agent. To overcome this issue, an audit pool is included in the system. It serves as the audit layer for the blockchain. The audit pool overlooks the overall working of the pools in the network. To join the audit pool, the node must satisfy the threshold to be regarded as trustworthy, and be a subject to stake in the protocol.

There is also a possibility that a node secretly behaves as a trustful node but after joining the pool it can feed invalid data. To mitigate this issue, the Aphelion protocol includes randomized round trip and multi-layered gossip mechanism. Through this process, nodes are randomly appointed to participate and no node at any instant gets to know whether or not it's the one being appointed. 


### How does Audit pool work?

To make a decision, votes are collected by the nodes, but to reduce cost and to be fair, the votes are also cast without the knowledge of the nodes. The multi-layered gossip includes the nested data approach, where the node's data communicated is indexed over the swarm.

By extracting the history of the nodes' index and unmarshalling the data, the protocol calculates the node's acceptance on the data and feeds the calculated value to the decision agent, where the rest of the steps are taken by the decision agent. This ensures privacy, fairness, truthfulness and security. After the round, the extracted data is useless because the algorithm is also programmed with redundancy removal.

After the decision agent takes the necessary steps, audit nodes are programmed to broadcast the rules over the whole network. Firewalls and state machine of each pool are updated with the new rules. This may include an increase in threshold, removal of a node or banning a node from the whole network. 


### What is the Maintenance pool?

According to the analysis on computer performance, it's concluded that a system consistently conducting complex operations can reduce its efficiency and life span. The maintenance pool ensures steady performance to save nodes from long and high computation, reduce cost, ensure system's reliability, increase life span and ensure high throughput.

If a node leaves or is removed from the network due to malicious activity, a node from the maintenance pool can be used as a replacement in order to keep the resources intact.

Maintenance pool doesn't refer to a permanent position for nodes. As the Aphelion protocol resolves the issues of fairness, trustfulness and decentralization, each node in the network is given a chance to contribute to the network. The protocol includes the mechanism of randomized round trip and time slots. Whenever a node has processed some amount of transaction and the time slot assigned has been finished, the node is replaced with another node from the maintenance pool. Replacement and movement doesn't make the node to be kept waiting for multiple hours. Instead, nodes are replaced with other nodes in the threshold of 2-3 seconds. 


### How does Aphelion ensure fast communication?

For the Aphelion protocol to run as it is intended, it is necessary that the network layer of the protocol supports fast communication and can scale over time.

There is high communication among the nodes and the machine learning models. The whole protocol can be badly affected if uncompressed data is communicated over the network and the same channel is utilized by the nodes. To solve this problem, at the network layer Aphelion utilizes **multi-layered gossip swarming with compression mechanisms**. Nodes interact with one another through the swarm and share the compressed data in the streams of packets.

The gossip communication involves the multi-layered gossip or the nested gossip mechanism, which means that the gossip is layered not only at the swarm level but also at the node level. The protocol is being implemented in Libonomy blockchain, but can allow any blockchain solution to utilize Aphelion network channel. 

## Milestones

May  
2020

Launch of public Testnet. 

Aug  
2020

Multi-pool consensus is added to Aphelion algorithm. 

Oct  
2020

Launch of public Main-net. 

Nov  
2020

LBY, the main asset of Libonomy blockchain, is released. This uses Aphelion consensus.