Implement basic peer to peer connection establishment and maintenance. Message serialization and parsing using FlatBuffer(Including defining message schema). Validating incoming proposal messages.
3.7 KiB
Hot Pocket Consensus Engine
What's here?
In development
A C++ version of hotpocket designed for production envrionments, original prototype here: https://github.com/codetsunami/hotpocket
Libraries
- Crypto - Libsodium https://github.com/jedisct1/libsodium
- Websockets - Boost|Beast https://github.com/boostorg/beast
- RapidJSON - http://rapidjson.org
- P2P Protocol - https://google.github.io/flatbuffers/
Steps to setup Hot Pocket
Install Libsodium
Instructions are based on this.
- Download and extract Libsodium 1.0.18 from here.
- Navigate to the extracted libsodium directory in a terminal.
- Run
./configure - Run
make && make check - Run
sudo make install
Install Boost
Following Instructions are based on Boost getting started
- Download and extract boost 1.71 package from here.
- Navigate to the extracted boost directory in a terminal.
- Run
./bootstrap.sh - Run
sudo ./b2 install(This will compile and install boost libraries into your/usr/local/lib)
Install RapidJSON
- Download and extract RapidJSON 1.1 source from here.
- Navigate to the extracted directory.
- Run
sudo cp -r include/rapidjson /usr/local/include/
Install FlatBuffers
Instructions are based on this.
- Clone the git respository into a new directory from here.
- Build with CMake
git clone https://github.com/google/flatbuffers.git
cd flatbuffers
cmake -G "Unix Makefiles"
make
- Run
sudo cp -r include/flatbuffers /usr/local/include/ - Run
sudo snap install flatbuffers --edge
Compiling FlatBuffers message definitions
When you make a change to message.fbc defnition file, you need to run this:
flatc -o src/p2p/ --gen-mutable --cpp src/p2p/message.fbs
Run ldconfig
sudo ldconfig
This will update your library cache and avoid potential issues when running your compiled C++ program which links to newly installed libraries.
Install CMAKE
If you use apt, run sudo apt install cmake or follow this.
Build and run Hot Pocket
- Navigate to hotpocket repo root.
- Run
cmake .(You only have to do this once) - Run
make(Hot Pocket binary will be created as./build/hpcore) - Refer to Running Hot Pocket in the Wiki.
Refer to Hot Pocket Wiki for more info.
Code structure
Code is divided into subsystems via namespaces.
conf:: Handles contract configuration. Loads and holds the central configuration object. Used by most of the subsystems.
crypto:: Handles cryptographic activities. Wraps libsodium and offers convenience functions.
proc:: Handles contract process execution and managing user/SC I/O and npl I/O. Makes use of usr and p2p.
usr:: Handles user connections. Makes use of crypto and sock.
p2p:: Handles peer-to-peer connections and message exchange between nodes. Makes use of crypto and sock.
cons:: Handles consensus and proposal rounds. Makes use of usr, p2p and proc
sock:: Handles generic web sockets functionality. Mainly acts as a wrapper for boost/beast.
util:: Contains shared data structures/helper functions used by multiple subsystems.