Code Monkey home page Code Monkey logo

gossip-price's Introduction

Go with GOSSIP-PRICE DISTRIBUTED SYSTEM

This repository demonstrates how to build and deploy distributed system using libP2p library.

Requirements

  • It will work with distributed gossiping nodes
  • Each nodes signs and re-emit(pulls) the price message to network
  • If the message is signed with 3 signers, then it will be stored in Postgres
  • Must be stored in Postgres after 30 seconds from last signed
  • The price will be taken from coinbase API every 10 minutes

Infrastructure of the network

  • Postgres database: It's for storing signed data. Every node can access and write the data if it meets requirements
  • Bootstrap node: This is bootstrap node for responsible to provide newly joining nodes into the network.
  • Gossip node: This is responsible for receive/sign/pull the price message. Each node find the another node and bootstrap based on DHT(distributed hash table) algorithms.

Consensus of the network

The consensus of this network is when store the data to Postgres database. We start with fetching the price from coinbase API and sign with node private key using ECDSA and re-emit to network. When receive the message from other node, check if this message already signed by this signer and do it if not signed yet. After signed message, it will stored in cache memory of the node. And check if the more than 3 signers signed for this message and if so the message will be moved to verified list. Every 30 seconds we check if there is verified data to store database and execute the insert sql.

Technology Choices

  1. libp2p library for implementing distributed gossip system.

    go install github.com/libp2p/
  2. PostgreSQL database for storing signed data. This is the table description.

    Columns Comment
    id This shows each price message id
    price The USD price of ETH
    first_signer The first signer of the price message
    sign_data Json string to show signers and signatures
    lastsigned_time Last signed date time to calculate passing time
    created_time Created column date time
  3. Coinbase API to fetch ETH USD price

    https://api.coinbase.com/v2/exchange-rates?currency=ETH

Project Structure

  • consensus - This is where the engine logic which also includes database management.
  • global - This is where global constants, errors, fetch price management.
  • gossip - This is where implemented distributed system infrastructure using libp2p library.
  • node - This is where for manage each node(new, start, broadcast, receive).
  • migrations - this is where the schema.hcl file lives. Modify this file to alter the database.

Quick Start

Make sure you have Docker installed... And execute the docker compose command to run on docker.

docker-compose -f docker-compose.yaml up -d

Environment Variables and Config

  • GP_BOOTSTRAP: This is for identify current node is bootstrap or gossip node.
  • GP_DATABASEURL: PostgreSQL url for access database.
  • GP_CONNECTIONADDR: Node address for publishing to network.
  • GP_BOOTSTRAPADDR: Bootstrap address for connect from gossip node.
  • GP_MINIMUMSIGNERCOUNT: Minimum signer account for consensus.
  • GP_FETCHPRICEINTERVAL: Fetch price interval.

Security issues and improvements

  • We check from database if same message id already registered before insert. This will increase request to database as the number of nodes increases. We can solve this problem without access database using merkle tree so can reduce the requests to database.
  • We have to restrict of accessing to our bootstrap node. If you want to create node we have to build another bootstrap and create new organization.
  • We have to implement the monitoring system to maintain the connection of each node.
  • We have to implement the node distributed monitoring system to maintenance node receiving counts.

postgres.png

gossip-price's People

Contributors

redbird96 avatar

Stargazers

 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.