Skip to content

Simple implementation of the consensus algorithm Hashgraph

Notifications You must be signed in to change notification settings

c3ai-lab/hashgraph

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chrysós Hashgraph C++ Node

An implementation of a node for the hashgraph consensus algorithm.

For a better theoretical understanding of this consensus algorithm, we recommend you to read the original paper The Swirlds Hashgraph Consensus Algorithm: Fair, Fast, Byzantine Fault Tolerance or this Medium article Understand Hashgraph which summarizes and visualizes the consensus in a more digestable way.

How to build

# clone repo including submodules
git clone --recurse-submodules https://github.com/c3ai-lab/hashgraph
cd hashgraph/
 
# build everything
mkdir build
cd build/
cmake ..
make

If you want to start a fresh building process, we recommend you to delete all untracked folders and files from this project, especially the build folder.

Build Docker Image

docker build -t hashgraph_node .

Run with Docker

docker run -it --rm hashgraph_node /hashgraph/build/hashgraph <PATH_TO>/settings.yaml

Configuration

During the build process, cryptographic material and configuration files are generated for all nodes specified within tests/nodes.txt. By modifying this file, you are able to control the size of the network as well as prepare it for a remote deployment.

Client

To be able to interact with the nodes (i.e. trigger transactions or query the ledger), a client is required. You can find a python version here.

Flow with a client

The following diagram outlies the basic flow together with a client for the application of a value transaction. Please note that the ownership transaction is not implemented yet.

The process from the perspective of the client is straight forward:

  1. It signs the transaction and submits it to a node.
  2. The node forwards the transaction into the network which gets further distributed via the gossip protocol.
  3. The client can continuously request a node for the affected balance and will see an updated one if the transaction was succesful.

Flow between nodes

Let us now have a closer look at what happens on the node and network side, once a node receives a signed transaction by a client:

  1. The node receives the transaction from a client.
  2. The node creates a new event which includes the timestamp and ideally aggregates multiple transactions into a tx_set[] (Note: aggregating transactions into a tx_set[] is currently not implemented yet, instead a new event is created for every transaction.)
  3. The node adds this event to its own hashgraph.
  4. The node signs the event and shares it with the network via the gossip protocol.
  5. All receiving nodes verify the signatures and hashes.
  6. If correct, they also add the event to their own hashgraph.
  7. Now the virtual voting commences where the nodes verify the transaction depth of the event and thereby are able to report on the immutability of the transaction.

About

Simple implementation of the consensus algorithm Hashgraph

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 89.4%
  • CMake 4.7%
  • Shell 2.8%
  • Thrift 2.6%
  • Dockerfile 0.5%