|
| 1 | +# hotstuff |
| 2 | + |
| 3 | +[](https://pkg.go.dev/github.com/relab/hotstuff) |
| 4 | + |
| 5 | + |
| 6 | +[](https://codecov.io/gh/relab/hotstuff) |
| 7 | + |
| 8 | +`relab/hotstuff` is a framework for experimenting with HotStuff and similar consensus protocols. |
| 9 | +It provides a set of modules and interfaces that make it easy to test different algorithms. |
| 10 | +It also provides a tool for deploying and running experiments on multiple servers via SSH. |
| 11 | + |
| 12 | +## Contents |
| 13 | + |
| 14 | +- [hotstuff](#hotstuff) |
| 15 | + - [Contents](#contents) |
| 16 | + - [Build Dependencies](#build-dependencies) |
| 17 | + - [Getting Started](#getting-started) |
| 18 | + - [Linux and macOS](#linux-and-macos) |
| 19 | + - [Windows](#windows) |
| 20 | + - [Running Experiments](#running-experiments) |
| 21 | + - [Safety Testing with Twins](#safety-testing-with-twins) |
| 22 | + - [Modules](#modules) |
| 23 | + - [Consensus Interfaces](#consensus-interfaces) |
| 24 | + - [Crypto Interfaces](#crypto-interfaces) |
| 25 | + - [References](#references) |
| 26 | + |
| 27 | +## Build Dependencies |
| 28 | + |
| 29 | +- [Go](https://go.dev) (at least version 1.18) |
| 30 | + |
| 31 | +If you modify any of the protobuf files, you will need the following to compile them: |
| 32 | + |
| 33 | +- [Protobuf compiler](https://github.com/protocolbuffers/protobuf) (at least version 3.15) |
| 34 | + |
| 35 | +- The gRPC and gorums plugins for protobuf. |
| 36 | + - Linux and macOS users can run `make tools` to install these. |
| 37 | + - The Windows build script downloads them automatically. |
| 38 | + - They can also be installed manually: |
| 39 | + - `go install github.com/relab/gorums/cmd/protoc-gen-gorums` |
| 40 | + - `go install google.golang.org/protobuf/cmd/protoc-gen-go` |
| 41 | + |
| 42 | +## Getting Started |
| 43 | + |
| 44 | +### Linux and macOS |
| 45 | + |
| 46 | +- Compile command line utilities by running `make`. |
| 47 | + |
| 48 | +### Windows |
| 49 | + |
| 50 | +- Run `.\build.ps1` with PowerShell. |
| 51 | + |
| 52 | +**NOTE**: you should use `./hotstuff.exe` instead of `./hotstuff` when running commands. |
| 53 | + |
| 54 | +## Running Experiments |
| 55 | + |
| 56 | +See the [experimentation documentation](docs/experimentation.md) for details. |
| 57 | + |
| 58 | +The `hotstuff` command line utility can be used to run experiments locally, or on remote servers using SSH. |
| 59 | +For a list of options, run `./hotstuff help run`. |
| 60 | + |
| 61 | +The `plot` command line utility can be used to create graphs from measurements. |
| 62 | +Run `./plot --help` for a list of options. |
| 63 | + |
| 64 | +## Safety Testing with Twins |
| 65 | + |
| 66 | +We have implemented the Twins strategy [6] for testing the safety of the consensus implementations. |
| 67 | +See the [twins documentation](docs/twins.md) for details. |
| 68 | + |
| 69 | +## Modules |
| 70 | + |
| 71 | +The following components are modular: |
| 72 | + |
| 73 | +- Consensus |
| 74 | + - The "core" of the consensus protocol, which decides when a replica should vote for a proposal, |
| 75 | + and when a block should be committed. |
| 76 | + - 3 implementations: |
| 77 | + - `chainedhotstuff`: The three-phase pipelined HotStuff protocol presented in the HotStuff paper [1]. |
| 78 | + - `fasthotstuff`: A two-chain version of HotStuff designed to prevent forking attacks [3]. |
| 79 | + - `simplehotstuff`: A simplified version of chainedhotstuff [4]. |
| 80 | +- Crypto |
| 81 | + - Implements the cryptographic primitives used by HotStuff, namely quorum certificates. |
| 82 | + - 2 implementations: |
| 83 | + - `ecdsa`: A very simple implementation where quorum certificates are represented by arrays of ECDSA signatures. |
| 84 | + - `bls12`: An implementation of threshold signatures based on BLS12-381 aggregated signatures. |
| 85 | +- Synchronizer |
| 86 | + - Implements a view-synchronization algorithm. It is responsible for synchronizing replicas to the same view number. |
| 87 | + - Current implementation based on [DiemBFT's RoundState](https://github.com/diem/diem/tree/main/consensus/src/liveness) [5]. |
| 88 | +- Blockchain |
| 89 | + - Implements storage for the block chain. Currently we have an in-memory cache of a fixed size. |
| 90 | +- Leader rotation |
| 91 | + - Decides which replica should be the leader of a view. |
| 92 | + - Currently either a fixed leader or round-robin. |
| 93 | +- Networking/Backend |
| 94 | + - Using [Gorums](https://github.com/relab/gorums) [2] |
| 95 | + |
| 96 | +These modules are designed to be interchangeable and simple to implement. |
| 97 | +It is also possible to add custom modules that can interact with the modules we listed above. |
| 98 | + |
| 99 | +## Consensus Interfaces |
| 100 | + |
| 101 | +There are two ways to implement a new consensus protocol, depending on the requirements of the new protocol. |
| 102 | +The `Consensus` module interface is the most general, but also the most difficult to implement. |
| 103 | +That is because it is oriented towards the other modules, and the other modules rely on it to perform certain operations, |
| 104 | +such as verifying proposals, interacting with the `BlockChain`, `Acceptor`, `Executor`, and `Synchronizer` modules, |
| 105 | +and so on. That is why we provide a simplified `Rules` interface and the optional `ProposeRuler` interface. |
| 106 | +These interfaces are only required to implement the core rules of the consensus protocol, namely deciding whether or not |
| 107 | +to vote for a proposal, whether or not it is safe to commit a block, and optionally how to create new blocks. |
| 108 | +These interfaces do not require any interaction with other modules, as that is taken care of by a |
| 109 | +[default implementation](consensus/consensus.go) of the `Consensus` interface. |
| 110 | + |
| 111 | +The `Consensus` and `Rules` interfaces can also be used to override the behavior of other consensus implementations. |
| 112 | +The `consensus/byzantine` package contains some examples of byzantine behaviors that can be implemented by wrapping |
| 113 | +implementations of these interfaces. |
| 114 | + |
| 115 | +## Crypto Interfaces |
| 116 | + |
| 117 | +In a similar way to the `Consensus` interface, the `Crypto` interface also introduces a simplified, lower-level interface |
| 118 | +that should be used to implement new crypto algorithms. |
| 119 | +The `Crypto` interface itself provides methods for working with the high-level structures such as quorum certificates. |
| 120 | +However, to make it easy to implement new crypto algorithms, the `CryptoImpl` interface can be used instead. |
| 121 | +This interface deals with signatures and threshold signatures directly, which are used by the `Crypto` interface |
| 122 | +to implement quorum certificates. |
| 123 | + |
| 124 | +## References |
| 125 | + |
| 126 | +[1] M. Yin, D. Malkhi, M. K. Reiter, G. Golan Gueta, and I. Abraham, “HotStuff: BFT Consensus in the Lens of Blockchain,” Mar 2018. |
| 127 | + |
| 128 | +[2] Tormod Erevik Lea, Leander Jehl, and Hein Meling. Towards New Abstractions for Implementing Quorum-based Systems. In 37th International Conference on Distributed Computing Systems (ICDCS), Jun 2017. |
| 129 | + |
| 130 | +[3] Mohammad M. Jalalzai, Jianyu Niu, Chen Feng, Fangyu Gai. Fast-HotStuff: A Fast and Resilient HotStuff Protocol, Oct 2020. |
| 131 | + |
| 132 | +[4] Leander Jehl. Formal Verification of HotStuff, Jun 2021. |
| 133 | + |
| 134 | +[5] Baudet, Mathieu, et al. "State machine replication in the libra blockchain." The Libra Assn., Tech. Rep (2019). |
| 135 | + |
| 136 | +[6]: S. Bano, A. Sonnino, A. Chursin, D. Perelman, en D. Malkhi, “Twins: White-Glove Approach for BFT Testing”, 2020. |
0 commit comments