acywu / babble

Consensus Platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BABBLE

Consensus platform for distributed applications.

Babble allows many computers to behave as one. It uses Peer to Peer (P2P) networking
and a consensus algorithm to guarantee that multiple connected computers process
the same commands in the same order; a technique known as state machine replication.
This makes for secure systems that can tolerate arbitrary failures including malicious
behaviour.

For guidance on how to install and use Babble please visit our documentation pages.

NOTE:
This is alpha software. Please contact us if you intend to run it in production.

Consensus Algorithm

We use the Hashgraph consensus algorithm, invented by Leemon Baird.
It is best described in the white-paper and its accompanying document.
The algorithm is protected by patents in the USA. Therefore, anyone intending to
use this software in the USA should obtain a license from the patent holders.

Hashgraph is based on the intuitive idea that gossiping about gossip itself yields
enough information to compute a consensus ordering of events. It attains the
theoretical limit of tolerating up to one-third of faulty nodes without compromising
on speed. For those familiar with the jargon, it is a leaderless, asynchronous BFT
consensus algorithm.

Design

Babble is designed to integrate with applications written in any programming language.

    ========================================
    = APP                                  =  
    =                                      =
    =  ===============     ==============  =
    =  = Service     = <-- = State      =  =
    =  =             =     =            =  =
    =  ===============     ==============  =
    =          |                |          =
    =       ========================       =
    =       = Babble Proxy         =       =
    =       ========================       =
    =          |                ^          =
    ===========|================|===========
               |                |
--------- SubmitTx(tx) ---- CommitTx(tx) ------- (JSON-RPC/TCP)
               |                |
 ==============|================|===============================
 = BABBLE      |                |                              =
 =             v                |                              =
 =          ========================                           =
 =          = App Proxy            =                           =
 =          =                      =                           =
 =          ========================                           = 
 =                     |                                       =
 =   =======================================                   =
 =   = Core                                =                   =
 =   =                                     =                   =
 =   =                                     =    ============   =
 =   =  =============        ===========   =    = Service  =   =  
 =   =  = Hashgraph =        = Store   =   = -- =          = <----> HTTP API
 =   =  =============        ===========   =    =          =   =
 =   =                                     =    ============   =     
 =   =                                     =                   =
 =   =======================================                   =
 =                     |                                       =
 =   =======================================                   =
 =   = Transport                           =                   =
 =   =                                     =                   =
 =   =======================================                   =
 =                     ^                                       =
 ======================|========================================
                       |                  
                       v
                   
                    Network

The above diagram shows how Babble fits in the typical architecture of a distributed
application. Users interact with an App's Service which reads data from its State.
However, the Service never updates the State directly. Instead, it passes commands
to an ordering system which communicates to other nodes and feeds the commands back
to the State in consensus order. Babble is an ordering system that plugs into the
App thanks to a very simple JSON-RPC interface over TCP.

Usage

Go

Babble is written in Golang. Hence, the first step is to install Go version 1.9 or above
which is both the programming language and a CLI tool for managing Go code. Go is
very opinionated and will require you to define a workspace where all your go code will
reside.

Babble and dependencies

Clone the repository in the appropriate GOPATH subdirectory:

$ mkdir -p $GOPATH/src/github.com/babbleio/
$ cd $GOPATH/src/github.com/babbleio
[...]/babbleio$ git clone https://github.com/babbleio/babble.git

Babble uses Glide to manage dependencies.

[...]/babble$ sudo add-apt-repository ppa:masterminds/glide && sudo apt-get update
[...]/babble$ sudo apt-get install glide
[...]/babble$ glide install

This will download all dependencies and put them in the vendor folder.

Testing

Babble has extensive unit-testing. Use the Go tool to run tests:

[...]/babble$ make test

If everything goes well, it should output something along these lines:

ok      github.com/babbleio/babble/net      0.052s
ok      github.com/babbleio/babble/common   0.011s
?       github.com/babbleio/babble/cmd      [no test files]
?       github.com/babbleio/babble/cmd/dummy_client [no test files]
ok      github.com/babbleio/babble/hashgraph        0.174s
ok      github.com/babbleio/babble/node     1.699s
ok      github.com/babbleio/babble/proxy    0.018s
ok      github.com/babbleio/babble/crypto   0.028s

Docker Testnet

To see Babble in action, we have provided a series of scripts to bootstrap a test
network locally.

Make sure you have Docker installed.

One of the scripts requires babble to be installed locally because it uses the
keygen command to generate cryptographic key pairs in the format used by babble.
To install babble:

[...]/babble$ make install

Then, run the testnet:

[...]/babble$ cd docker
[...]/babble/docker$ make

Once the testnet is started, a script is automatically launched to monitor consensus
figures:

consensus_events:98 consensus_transactions:40 events_per_second:0.00 id:3 last_consensus_round:11 num_peers:3 round_events:12 rounds_per_second:0.00 state:Babbling sync_rate:1.00 transaction_pool:0 undetermined_events:34
consensus_events:98 consensus_transactions:40 events_per_second:0.00 id:1 last_consensus_round:11 num_peers:3 round_events:12 rounds_per_second:0.00 state:Babbling sync_rate:1.00 transaction_pool:0 undetermined_events:35
consensus_events:98 consensus_transactions:40 events_per_second:0.00 id:0 last_consensus_round:11 num_peers:3 round_events:12 rounds_per_second:0.00 state:Babbling sync_rate:1.00 transaction_pool:0 undetermined_events:34
consensus_events:98 consensus_transactions:40 events_per_second:0.00 id:2 last_consensus_round:11 num_peers:3 round_events:12 rounds_per_second:0.00 state:Babbling sync_rate:1.00 transaction_pool:0 undetermined_events:35

Running docker ps -a will show you that 8 docker containers have been launched:

[...]/babble/docker$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
9e4c863c9e83        dummy               "dummy '--name=cli..."   9 seconds ago       Up 8 seconds        1339/tcp            client4
40c92938a986        babble              "babble run --cach..."   10 seconds ago      Up 9 seconds        1337-1338/tcp       node4
4c1eb201d29d        dummy               "dummy '--name=cli..."   10 seconds ago      Up 9 seconds        1339/tcp            client3
cda62387e4fd        babble              "babble run --cach..."   11 seconds ago      Up 9 seconds        1337-1338/tcp       node3
765c73d66bcf        dummy               "dummy '--name=cli..."   11 seconds ago      Up 10 seconds       1339/tcp            client2
a6895aaa141a        babble              "babble run --cach..."   11 seconds ago      Up 10 seconds       1337-1338/tcp       node2
8f996e13eda7        dummy               "dummy '--name=cli..."   12 seconds ago      Up 11 seconds       1339/tcp            client1
36c97a968d22        babble              "babble run --cach..."   12 seconds ago      Up 11 seconds       1337-1338/tcp       node1

Indeed, each node is comprised of an App and a Babble node (cf Architecture section).

Run the demo script to play with the Dummy App which is a simple chat application powered by the Babble consensus platform:

[...]/babble/docker$ make demo

Demo

Finally, stop the testnet:

[...]/babble/docker$ make stop

About

Consensus Platform


Languages

Language:Go 95.5%Language:Shell 2.8%Language:HCL 1.1%Language:Makefile 0.5%