|
| 1 | +# Implementing new BFT Protocols |
| 2 | + |
| 3 | +This document describes the steps to implement a new BFT protocol in ByzzBench. |
| 4 | + |
| 5 | +A BFT Protocol implementation in ByzzBench consists of the following components: |
| 6 | + |
| 7 | +- A protocol replica that *extends* `Replica<T>`: these are the nodes that run the protocol and communicate with each other |
| 8 | + via messages. `T` is the type of each of the entries in the commit log (this should be simplified!). |
| 9 | + - Example: [PBFT-Java Replica](../simulator/src/main/java/byzzbench/simulator/protocols/pbft_java/PbftReplica.java) |
| 10 | + - The `Replica` constructor requires a `replicaId`, `nodeIds` (set of all replica IDs in the *cluster*), `transport` (the virtualized network instance) and a `commitLog` (instance where all committed operations from the replica are sent to). |
| 11 | +- A set of protocol message POJOs that *implement* `MessagePayload`: these are the messages that are exchanged between replicas. |
| 12 | + - They just need to have a `String getType()` method that returns e.g. that it is a `PREPARE` message. |
| 13 | + - Examples from PBFT-Java: [Checkpoint](../simulator/src/main/java/byzzbench/simulator/protocols/pbft_java/message/CheckpointMessage.java), [Commit](../simulator/src/main/java/byzzbench/simulator/protocols/pbft_java/message/CommitMessage.java), [NewView](../simulator/src/main/java/byzzbench/simulator/protocols/pbft_java/message/NewViewMessage.java), [Phase](../simulator/src/main/java/byzzbench/simulator/protocols/pbft_java/message/PhaseMessage.java), [Prepare](../simulator/src/main/java/byzzbench/simulator/protocols/pbft_java/message/PrepareMessage.java), [PrePrepare](../simulator/src/main/java/byzzbench/simulator/protocols/pbft_java/message/PrePrepareMessage.java), [Reply](../simulator/src/main/java/byzzbench/simulator/protocols/pbft_java/message/ReplyMessage.java), [Request](../simulator/src/main/java/byzzbench/simulator/protocols/pbft_java/message/RequestMessage.java), [ViewChange](../simulator/src/main/java/byzzbench/simulator/protocols/pbft_java/message/ViewChangeMessage.java) |
| 14 | + |
| 15 | +## Communication and Timeouts |
| 16 | + |
| 17 | +Communication between replicas is done via message-passing through the `Transport`. The `Replica` superclass exposes a few methods: |
| 18 | + |
| 19 | +- `sendMessage`: send a message to a recipient |
| 20 | +- `multicastMessage`: send a message to a set of replicas |
| 21 | +- `broadcastMessage`: send a message to every other replica |
| 22 | +- `broadcastMessageIncludingSelf`: send a message to every replica, including self |
| 23 | + |
| 24 | +Timeouts are implemented via callbacks to a `Runnable`, also handled by the `Transport`: |
| 25 | + |
| 26 | +- `setTimeout(Runnable, timeout)`: Creates a timeout event of `timeout` milliseconds, which will then invoke the `Runnable`. The time is currently being ignored, and is instead triggered just like any other event by the scheduler. |
| 27 | +- `clearAllTimeouts()`: Invalidates all outstanding timeouts for the current replica. |
| 28 | + |
| 29 | +## Commit Log |
| 30 | + |
| 31 | +Each replica has its own instance of a `CommitLog`: an immutable and total ordered sequence of records. This is used to check whether safety invariants of distributed consensus are broken. |
0 commit comments