Giter Club home page Giter Club logo

pbft-rust's Introduction

pBFT-rust

This repository contains a simple implementation of Practical Byzantine Fault Tolerance Algorithm in Rust.

The project is an in-memory key-value store backed by pBFT.

While the implementation aims to be fairly complete (with view change protocol, message forwarding, etc.) this is a learning/fun project, it is not intended nor prepared for production usage. Not all features are implemented, all data lives in memory, and there are likely a lot of edge cases that are not handled.

Running locally

Running multiple replicas locally can easily be done with Overmind (see the Procfile). To do that use:

cd kv-node
overmind start

This will start 5 replicas with built-in dev configuration. The default ports will be [10000-10004].

You can also simply start replicas separately one by one in different sessions:

PBFT_DEV=0 cargo r --bin kv-node
PBFT_DEV=1 cargo r --bin kv-node
...

PBFT_DEV environment variable instructs the program to use built-in configuration for easy development and testing, the value denotes replica id and the correct values are [0-4].

Customization is possible with config files or environment variables.

Usage

After starting nodes, you can access the service with curl.

Set key:

curl localhost:10000/api/v1/kv -H "Content-Type: application/json" -d '{"key":"test_key", "value":"test_value"}'

Get key with consensus based operation:

curl "localhost:10000/api/v1/kv?key=test_key"

Get key from local node state:

curl "localhost:10000/api/v1/kv/local?key=test_key"

For testing/debugging purposes some properties of the node state can be inspected with:

curl localhost:10000/api/v1/pbft/state

Requests can be send to any replica, and will be automatically forwarded to the leader.

Logging

Use RUST_LOG environment variable to customize logging verbosity:

export RUST_LOG=kv_node=debug,pbft_core=debug

Triggering View Change

In order to trigger the view change stop the leader replica (replica0 when starting from scratch):

overmind stop replica0

NOTE: Make sure the replica actually stops (the graceful shutdown may wait for open connections to close). If you are not sure, simply execute the stop command twice, which will issue a SIGKILL.

And send the request to any other node:

curl "localhost:10001/api/v1/kv?key=test_key"

The request will fail, but the view change protocol should kick in in few seconds.

Repeating the request couple of seconds later, should yield correct result.

You can query the state endpoint to ensure the view has changed, and replica1 is the leader now:

curl "localhost:10001/api/v1/pbft/state"
{"replica_state":{"Leader":{"sequence":4}},"view":2,"last_applied":4,"last_stable_checkpoint_sequence":null}

NOTE: There are likely quite a bit of bugs / not handled edge cases.

pbft-rust's People

Contributors

szymongib avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.