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.
# 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.
docker build -t hashgraph_node .
docker run -it --rm hashgraph_node /hashgraph/build/hashgraph <PATH_TO>/settings.yaml
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.
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.
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:
- It signs the transaction and submits it to a node.
- The node forwards the transaction into the network which gets further distributed via the gossip protocol.
- The client can continuously request a node for the affected balance and will see an updated one if the transaction was succesful.
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:
- The node receives the transaction from a client.
- 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.)
- The node adds this event to its own hashgraph.
- The node signs the event and shares it with the network via the gossip protocol.
- All receiving nodes verify the signatures and hashes.
- If correct, they also add the event to their own hashgraph.
- 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.