Skip to content

StellaPetronio/Accountable-HotStuff

Repository files navigation

Accountable HotStuff

To achieve the accountability of the HotStuff protocol, the consensus.h, consensus.cpp, hotstuff.h and hotstuff.cpp scripts present some additional members, methods and structures with respect to the original version.

-Two new structures, ChainCommitted and Proof, have been declared and defined in the consensus.h script.

-Two structures representing two new network messages format, MsgCommitted and MsgProof, have been declared and defined, respectively, in the hotstuff.h and hotstuff.cpp.

-Two new methods do_broadcast_committed and do_broadcast_proof are present in the the hotstuff.h and hotstuff.cpp scripts.

-Four new methods on_received_chain, on_received_proof, on_received_chain and on_received_proof have been declared and defined in the consensus.h and consensus.cpp script, respectiely.

-Two void methods periodicalCheck_conflicting and periodicalCheck_invalid_unlocking are defined in the hotstuff.cpp script and declared as an overridding methods.

-Two boolean methods conflicting and invalid_unlocking, to check if an unwanted scenario occurs, are declared and defined, respectiely, in the hotstuff.h and hotstuff.cpp script.

-The safety condition part in the update method of the consensus.cpp script has been commented.

-Two new handle methods, committed_handler and proof_handler are declared and defined in the hotstuff.h and hotstuff.cpp script.

-A new unordered_map blk_received has been declared as a private memeber of the HotStuffBase class in the hotstuff.h script.

-Two new members, receive_chain_waiting and receive_proof_waiting, of type promise_t have been declared in the HotStuffCore class of the consensus.h script.

A detailed explanation can be found in the "Implementation" section of the report attached. Moreover, any additional part necessary for accountability is preceded by the comment '/* For accountability */'.

libhotstuff

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

Paper

This repo 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 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.

Features

  • Simplicity. The protocol core logic implementation is as simple as the one specified in our paper. See consensus.h and consensus.cpp.
  • Modular design. You can use abstraction from the lowest level (the core protocol logic) to the highest level (the state machine replication service with network implementation) in your application, or override/redefine the detailed behavior to customize your own consensus.
  • Liveness decoupled from safety. The liveness logic is entirely decoupled from safety. By defining your own liveness gadget ("PaceMaker"), you can implement your own liveness heuristics/algorithm. The actual performance varies depending on your liveness implementation, but the safety is always intact.
  • Friendly to blockchain systems. A PaceMaker could potentially be PoW-based and it makes it easier to build a hybrid consensus system, or use it at the core of some cryptocurrencies.
  • Minimal. The project strives to keep code base small and implement just the basic functionality of state machine replication: to deliver a consistent command sequence to the library user. Application-specific parts are not included, but demonstrated in the demo program.

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...)

  • Rewrite this minimal code base in Rust: this time, with all the experience, without C++ template kung-fu, I plan to have a ready-to-use, blackbox-like libhotstuff implementation as a full library with better encapsulation and interface. The new goal would be any engineer without knowledge of BFT should be able to use it for his/her own application, without changing the library code. Ping me if you like this re-writing idea or you'd like to be part of it.
  • Limit the async event callback depth (otherwise in the demo a fresh replica could overflow its callback stack when trying to catch up)
  • Add a PoW-based Pacemaker example
  • Branch pruning & swapping (the current implementation stores the entire chain in memory)
  • Persistent protocol state (recovery?)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published