Coder Social home page Coder Social logo

86b / dshackle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from drpcorg/dshackle

0.0 0.0 0.0 5.2 MB

Fault Tolerant Load Balancer for Ethereum and Bitcoin APIs

License: Apache License 2.0

Shell 0.03% JavaScript 0.30% Java 8.33% Groovy 31.84% Kotlin 59.46% Makefile 0.03% Dockerfile 0.01%

dshackle's Introduction

Dshackle

Unit Tests License

Dshackle is a Fault Tolerant Load Balancer for Blockchain API used at DRPC

Is is a fork of the EmeraldPay’s dshackle, adapted to work as a provider side adapter for the DRPC network. This project is specifically designed to integrate providers into the DRPC network, which is distinguished by its focus on low latency and high availability. Our service facilitates providers in easily connecting to the DRPC, enabling them to be part of a network that prioritizes robust, consistent, and responsive operations. Joining this network through our adapted service allows providers to contribute towards creating a highly available and resilient decentralized system.

The goal of the Dshackle is to provide a stable routing to multiple nodes, and ensure that each request is executed on an appropriate provider. It considers nodes locations, state, current height, RPC methods it can provide and other characteristics.

It tries to recover from connection errors, faulty nodes, invalid responses, etc. If upstream lags behind others, lost peers below required, started to resync or went down, then Dshackle temporarily excludes it from requests and returns it when the upstream problem is fixed.

The upstreams may be blockchain nodes such as Bitcoind, Geth, Parity, or public providers like DRPC. It automatically verifies their availability and the current status of the network, executes commands making sure that the response is consistent and/or data successfully broadcast to the network.

Provides:

  • Standard Bitcoin and Ethereum JSON RPC API over HTTP and WebSocket

  • Enhanced gRPC-based API, with upstream selection, async execution, etc

  • Secure TLS with optional client authentication

  • Blockchain-aware edge caching, in memory and Redis

  • Routing based on data availability (peers, height, sync status)

  • Data consistency, it always gives a most actual state

  • Automatic failover and retry

  • Separate public blockchain nodes from your internal servers

Supported chains

List of supported chains here. Feel free to contribute new chains.

Architecture

Warning
The project is still under development, please use with caution.

Quick Start

Configuration

Create file dshackle.yaml with the following content:

version: v1
port: 2449
tls:
  enabled: false

proxy:
  host: 0.0.0.0
  port: 8545
  routes:
    - id: eth
      blockchain: ethereum
    - id: btc
      blockchain: bitcoin

cluster:
  upstreams:
    - id: drpc-eth
      chain: ethereum
      connection:
        generic:
          rpc:
            url: "https://lb.drpc.org/ogrpc?network=ethereum&dkey=${DRPC_KEY}"
          ws:
            url: "wss://lb.drpc.org/ogws?network=ethereum&dkey=${DRPC_KEY}"
    - id: solana
      chain: solana
      connection:
        generic:
          rpc:
            url: "https://localhost:8899"
          ws:
            url: "wss://localhost:8900"
    - id: bitcoin-main
      chain: bitcoin
      connection:
        bitcoin:
          rpc:
            url: "http://localhost:8332"
            basic-auth:
              username: bitcoin
              password: mypassword

Which sets the following:

  • gRPC access through 0.0.0.0:2449

    • TLS security is disabled (please don’t use in production!)

    • compression is disabled for gRPC server (enabled by default)

  • JSON RPC access through 0.0.0.0:8545 (both HTTP and WebsScket)

    • proxy requests to Ethereum and Bitcoin upstreams

    • request path for Ethereum Mainnet is /eth and /btc for bitcoin

    • i.e. call Ethereum Mainnet by POST http://127.0.0.0:8545/eth with JSON RPC payload

  • three upstreams - ethereum, solana and bitcoin

  • for Ethereum Mainnet it connects using JSON RPC and WebSocket connections,

  • for Bitcoin Mainnet only JSON RPC is used

  • ${DRPC_KEY} will be provided through environment variable

Please note that you can configure many upstreams for a single blockchains. If there is more than one upstream, then Dshackle routes requests to them as Round Robin. If one of them becomes unavailable, Dshackle continues to use only active nodes.

I.e., you can set up a node in the local network, plus Infura with role: fallback. If anything happened to your local node, you still have access to a consistent state of the Ethereum blockchain via Infura.

Run docker image

Official Docker image you can find at: p2p-org/dshackle

Setup DRPC key
export DRPC_KEY=...
Run Dshackle
docker run -p 2449:2449 -p 8545:8545 -v $(pwd):/etc/dshackle -e "DRPC_KEY=$INFURA_USER" emeraldpay/dshackle:0.12

Now it listens on port 2449 at the localhost and can be connected from any gRPC compatible client. Tools such as gRPCurl can use protobuf definitions from proto reflection and connect to it

Alternatively you can connect to port 8545 with traditional JSON RPC requests

Documentation

For detailed documentation see docs/ directory.

Development

Warning
The code in master branch is considered a development version, which may lack proper testing and should not be used in production.

Setting up environment

Dshackle is JVM based project written in Kotlin. To build and run it from sources you’ll need to install Java JDK and Gradle

Build Dshackle

Build everything

gradle build

Make a Zip distribution

gradle distZip

You can find a redistributable zip in build/distributions

Make a Docker distribution

gradle jib -Pdocker=gcr.io/myproject

Gradle will prepare a Docker image and upload it to your custom Docker Registry at gcr.io/myproject (please change to address of your actual registry)

Community

Join our Discord

License

Copyright 2021 EmeraldPay, Inc

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Modifications made by p2p.org in 2022 are licensed under the same Apache License, Version 2.0. These modifications are copyrighted by p2p.org.

dshackle's People

Contributors

splix avatar a10zn8 avatar termina1 avatar kirillpampam avatar maxfomenkov avatar mxssl avatar mrdimidium avatar mysticryuujin avatar spontaneousoverthrow avatar aldoborrero avatar skylenet avatar tonyganch avatar wesleycharlesblake avatar roderik 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.