blockchain
This is a naive and native Rust blockchain protocol implementation, very much WIP. From this experiment will eventually emerge a series of articles on the principles of distributed consensus, and a step-by-step implementation of a blockchain protocol in Rust.
General design
The node
crate is the entry point: it sets up a TCP server for node-to-node communication, parsing protocol messages in the MessagePack format.
A protocol message has the following structure:
| MAGIC ("BLOCK") | PROTOCOL VERSION (32B) | MSG TYPE (32B) | MSG PAYLOAD (32B) | PAYLOAD |
While TCP is fine for broadcasting transactions, blocks, and other technical stuff, users need a more human-friendly channel of communication witht their local node in order to start transactions, check blockchain status, etc. This implementation aims at providing a JSON-RPC server through HTTP (very much a la Bitcoin).
The jsonrpc
crate provides data structures that model the JSON-RPC protocol model (V2.0).
The merkle
crate provides for now a simple immutable binary tree implementation.
It aims at providing a sensible Merkle-tree implementation, which I expect will warrant its separate post
(implementing data structures in Rust is
interesting
to
say
the least).
Cryptography
The fantastic ed_25519
library is used for public-key cryptography.
For hashing purposes, we rely on Sha2
.
Common sense dictates that "ye shall base58
-encode addresses, lest thine offspring be lost".