Giter VIP home page Giter VIP logo

pbft-typescript's Introduction

PBFT-Typescript

Work in progress, do not use in production.

This library is a PBFT implementation of the PBFT algorithm (Practical Byzantine Fault Tolerance).

Algorithm

  • Flow
  • Terminology: blockHeight; view; node; leader;
  • Initial setup: leader; storage; blockHeight; view
  • PBFT phases
  • Passing data between nodes: messages; filters; Gossip
  • Leader change: request view change; election; new view

Leader stores Prepare in Log Leader boradcasts preprepare to all nodes Node x receives onPreprepare; logs preprepare and its own Prepare Node x broadcasts prepare Node receives prepare, once it receives 2f+1 of those, it stores a commit and sends it out Node receives 2f+1 commits - it commits to its blockchain and deletes from Log.

Node is created with PBFT with Config Node calls PBFT.start() after init (it should know all other nodes first, as optimization) External invocation of start() happens just once in the beginning. start() gets block height

What can advance the flow: gossip events and election trigger.

Exponential timeouts

API

Classes

PBFT

There is a single instance of PBFT class. It handles multiple blockHeights.

  • start() disposes of the previous PBFTTerm and creates a new one.

The Node calls it once initially when it starts. Subsequent calls to start() are made inside the callback onCommittedBlock().

createPBFTTerm(): holds CB when block can be committed. The CB notifies listeners and advancesd PBFTTerm.

PBFTTerm

Each term (blockHeight) has a separate instance of PBFTTerm.

  • startTerm(): calls setView(), if node is not leader, it waits.
  • isLeader()
  • dispose()
  • onLeaderChange() - callback
  • setView() -

NetworkMessagesFilter

Single instance per PBFT - holds messages from different block heights

  • NetworkCommunication implementation of Gossip layer - discovery of member nodes; subscribe/unsubscribe to messages; send messages
  • onCommittedCB

Config

BlockUtils

  • requestNewBlock()
  • validateBlock()
  • calculateBlockHash()

ElectionTrigger

This is a timer which triggers when the current leader failed to reach consensus on the current block after some configurable time.

  • view - the view of this trigger
  • register()

PBFTStorage

Implemented by InMemoryPBFTStorage

Methods
  • storePreprepare():
  • storePrepare():
  • storeCommit():
  • storeViewChange():

There are matching getter functions

TermsMap is a mapping (term -> (view -> payload))

Running

Tests

On the project directory run: npm run tdd

To do

  • (Gil) messages should include message type (string)
  • (Gil) re-enable isViewChangeMessageValid in onReceiveNewView
  • (Gil) Extract the messages building functions out of PBFTTerm to a dedicated builder that can be used also in the tests
  • (Gil) verify preprepare.term in onReceiveNewView
  • (Gad) Check state still holds after async await functions (ex: when returning from requestNewBlock - view has changed)
  • (Gad) Think about view-change counting, when to count myself.
  • (Gad) code review

Future

  • allow to config the sockets logger's target server ip
  • add isACommitteeMember to PBFTTerm
  • Change logging methodology - warning - added metadata
  • Have a better (Readable) tests solution to await nextTick
  • monitoring/debug
  • Optimizations: IData - Signature only on hash(header).
  • implement verifyBlock
  • PBFT-BC onCommitted - adds header.pbftData.pbftProof

pbft-typescript's People

Contributors

gadcl avatar gilamran avatar idozilberberg avatar bolshchikov avatar

Stargazers

Lycrus Hamster avatar Andrejs Agejevs avatar lodge avatar  avatar  avatar  avatar

Watchers

Rotem Yakir avatar James Cloos avatar lodge avatar Jonathan Levison avatar  avatar David Dayag avatar  avatar  avatar  avatar  avatar Eran Kirshenboim avatar Lycrus Hamster avatar  avatar

Forkers

semenov

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.