Giter Club home page Giter Club logo

subway's Introduction

Subway

Substrate JSON RPC Gateway.

This is a generalized JSON RPC proxy server with features specifically designed for Substrate RPC and Ethereum RPC.

alt text

Getting Started

Pull vendors: git submodule update --init --recursive

Quick start: cargo run -- --config config.yml

This will run a proxy server with config.yml as the configuration file.

Run with RUSTFLAGS="--cfg tokio_unstable" to enable tokio-console

Environment Variables

  • RUST_LOG
    • Log level. Default: info.
  • PORT
    • Override port configuration in config file.
  • LOG_FORMAT
    • Log format. Default: full.
    • Options: full, pretty, json, compact

Features

Subway is build with middleware pattern.

Middlewares

Method Middlewares

  • Cache
    • Cache responses from upstream middleware.
  • Call
    • Forward requests to upstream servers.
  • Inject Params (Substrate)
    • For Substrate RPC
    • Inject optional blockAt or blockHash params to requests to ensure downstream middleware such as cache can work properly.
  • Inject Params (Ethereum)
    • For Ethereum RPC
    • Inject optional defaultBlock parameter to requests to ensure downstream middleware such as cache can work properly.
  • Subscription
    • Forward requests to upstream servers.
    • TODO: Merge duplicated subscriptions.
  • TODO: Rate Limit
    • Rate limit requests from downstream middleware.
  • TODO: Parameter filter
    • Deny requests with invalid parameters.

Additional features

  • Advance JSON RPC Client
    • Supports multiple upstream servers and rotate & reconnect on failure.
    • TODO: Load balance requests to upstream servers.
  • Batch Request
    • TODO: Process requests individually so they can be cached properly by downstream middlewares.
    • TODO: Limit batch size, request size and response size.
  • TODO: Metrics
    • Getting insights of the RPC calls and server performance.

Benchmarks

To run all benchmarks:

cargo bench

It's also possible to run individual benchmarks by:

cargo bench --bench bench ws_round_trip

Validate Middleware

This middleware will intercept all method request/responses and compare the result directly with healthy endpoint responses. This is useful for debugging to make sure the returned values are as expected. You can enable validate middleware on your config file.

middlewares:
  methods:
    - validate

NOTE: Keep in mind that if you place validate middleware before inject_params you may get false positive errors because the request will not be the same.

Ignored methods can be defined in extension config:

extensions:
  validator:
    ignore_methods:
      - system_health
      - system_name
      - system_version
      - author_pendingExtrinsics

subway's People

Contributors

xlc avatar ermalkaleci avatar shaunxw avatar shunjizhan avatar dependabot[bot] avatar mrq1911 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.