hot-stuff / libhotstuff

A general-purpose BFT state machine replication library with modularity and simplicity, suitable for building hybrid consensus cryptocurrencies.
Apache License 2.0
236 stars 81 forks source link

libhotstuff

libhotstuff is a general-purpose BFT state machine replication library with modularity and simplicity, suitable for building hybrid consensus cryptocurrencies.

Paper

This repository includes the prototype implementation evaluated in our HotStuff: BFT Consensus in the Lens of Blockchain paper. The consensus protocol is also used by Facebook in Libra_ (now rebranded to "Diem") project.

Feel free to contact us if you'd like to reproduce the results in the paper, or tweak the code for your own project/product.

Heads Up

Although we don't know why, many developers seem to be stuck with those intermediate algorithms in the paper (e.g. Basic HotStuff) that are only for theory/research purpose. As already noted in the paper, we recommend the last algorithm ("Event-Driven HotStuff") as it is simple, elegant (there is no "view" at all in the core protocol and only one generic type of QCs) and very close to an actual implementation. It is also the original algorithm we came up with, before adding in Basic/Chained HotStuff that may help some researchers understand its theoretical relation to PBFT, etc.

TL;DR: read the spec (and the proof) of the algorithm in "Implementation" section, if you're only curious about using HotStuff in your system/work.

.. _Libra: https://github.com/libra

Features

Try the Current Version

NOTICE: the project is still in-progress. Try at your own risk, and this section may be incomplete and subject to changes.

::

# install from the repo
git clone https://github.com/hot-stuff/libhotstuff.git
cd libhotstuff/
git submodule update --init --recursive

# ensure openssl and libevent are installed on your machine, more
# specifically, you need:
#
# CMake >= 3.9 (cmake)
# C++14 (g++)
# libuv >= 1.10.0 (libuv1-dev)
# openssl >= 1.1.0 (libssl-dev)
#
# on Ubuntu: sudo apt-get install libssl-dev libuv1-dev cmake make

cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED=ON -DHOTSTUFF_PROTO_LOG=ON
make

# start 4 demo replicas with scripts/run_demo.sh
# then, start the demo client with scripts/run_demo_client.sh

# Fault tolerance:
# Try to run the replicas as in run_demo.sh first and then run_demo_client.sh.
# Use Ctrl-C to terminate the proposing replica (e.g. replica 0). Leader
# rotation will be scheduled. Try to kill and run run_demo_client.sh again, new
# commands should still get through (be replicated) once the new leader becomes
# stable. Or try the following script:
# scripts/faulty_leader_demo.sh

Try to Reproduce Our Basic Results

See here_.

TODO (When I get some free time...)

.. _here: https://github.com/hot-stuff/libhotstuff/tree/master/scripts/deploy