Patract Labs’ treasury report for Elara v0.1

3yrs ago
0 Comments

Overview

Five weeks ago, Patract Labs applied a treasury proposal #103 for Elara v0.1, which will be an instant and scalable Polkadot API service.

In the proposal, we promised to finish the following works (referring to motion #31):

v0.1: Implement Substrate node access

  • Create a server-side framework to develop proxy access, automatic monitoring and data statistics to the RPC service of the Substrate node
  • Support developers to use http and web-socket protocols to uniformly access the network through the server framework
  • Develop a front-end dashboard to display relevant monitoring statistics of the RPC service of the Substrate node

How to verify v0.1: Youtube demo video & Github source

  • The Substrate node of the service can be accessed through http and web-socket protocols
  • Can monitor RPC requests of Substrate nodes
  • Can view the relevant monitoring statistics from the dashboard

By now, we have finished all the development requirements for Elara v0.1 on time. There is a demo video to show all the features on YouTube in https://youtu.be/7UhsUEqk1pQ. The Github repo is https://github.com/patractlabs/elara, and the homepage of a demo dashboard to show the current statistics is in https://elara.patract.io/.

image

Then, Let's show you how Elara works:

Start Elara On Your Own Computer

Elara v0.1 can be used for any Substrate blockchain. For example, if you want to run a Polkadot or Kusama node to provide a public RPC endpoint node, then you what to monitor how many times and what kind of RPC calls had been called in one day, you can do the following steps to start Elara:

  1. The node server should already have yarn and node command.

  2. Git clone Elara into this server:

git clone https://github.com/patractlabs/elara.git
  1. Install Elara’s dependencies:
cd elara
yarn install
  1. Install database:

Currently, Elara use Redis memory database to provide the back-end DB to store all data. We will support other database like MongoDB or PostgreSQL in the future, but now we just support Redis DB and the corresponding configs. If you need persistent data, using redis’ persistent feature is good enough.

# for ubuntu or debian
sudo apt install redis
# other system just replace to related command to install redis
  • Notice: we advice to config password for Redis if you use Elara in production environment *

And on the other hand, the Redis server instance can be replaced by cloud service. In this way, DevOps can save some time and lot of troubles.

  1. Start Polkadot or Kusama, or any other substrate node that you want to monitor.

Please notice that all Substrate node will export ws-port and rpc-port, and can set some limit for commands, like --rpc-cors, --rpc-methods or --unsafe-rpc-external, --unsafe-ws-external or something else.

For more information, please refer to https://github.com/paritytech/substrate/wiki/Public-RPC.

  1. Modify Elara’s config file:

By now, Elara has provided a real RPC / web-socket service for outside users, and Elara can connect with Substrate node directly. Elara is doing like a proxy to transmit client requests to the node, at the same time, logging, monitoring, and counting all the requests.

So you need to modify config file for Elara:

vim config/env/dev.env.js

And you can see:

process.env.DEBUG = process.env.DEBUG || 'dev-errer:*'

module.exports = {
    keys: ['elara@#^*&'],
    name: 'elara',
    port: 8001,  // this port is elara server, receive all client request(inlude rpc and websocket) and dashbord server port
    pid:'00000000000000000000000000000000',
    chain: {
        'substrate': {
            'rpc': ['localhost:9933'], // the substrate node rpc port
            'ws': ['localhost:9944'] // the substrate node websocket port
        }
    },
    redis: { // the redis config
        host: '127.0.0.1',
        port: '6379',
        password: ''
    },
    timeout: 10000,// ms
    requests: 1000//
}

In this config file, you should pay attention to 3 fields:

  • port : This field is used for Elara server, all client requests will go through this port, including RPC requests and web-socket requests.
  • chain/substrate: This field is used to connect with the Substrate node, so it should match its --ws-port and --rpc-port. If the Substrate node doesn’t set those two parameters, the default values are 9944 and 9933.
  • redis: This field is used to connect with the Redis instance.
  1. Start Elara’s service and dashboard:

In Elara’s root directory, you can start in the current process:

node app.js

Or use pm2 to management the process

pm2 start pm2.json --env dev

You can find the running log in elara/logs/

And then you can start the dashboard:

cd ./daemon
nohub node dashboard.js &

Now open http://127.0.0.1:8001/demo in your browser, you can see the dashboard and all the statistics for requests.

Please notice that the client request’s endpoint should be http://127.0.0.1:8001 or ws://127.0.0.1:8001 to start the RPC or web-socket request, otherwise the request can't be monitored by Elara.

  1. Start requesting from client:
  • If you provide RPC service for developers:
  1. Method 1 : using curl to send HTTP requests:
      #curl http
      curl --location --request POST 'http://localhost:8001' \
          --header 'Content-Type: application/json' \
          --data-raw '{
              "id":1,
              "jsonrpc":"2.0",
              "method":"chain_getBlock",
              "params":[]
          }'
  1. Method 2: using wscat to send websocket request:
    parachain@ubuntu:~/elara$ wscat  -c ws://localhost:8001/
    Connected (press CTRL+C to quit)
    > {"id":1,"jsonrpc":"2.0","method":"chain_getBlock","params":[]}
    < {Response data...}
  1. Method 3 : Using the SDK. You can refer to polkadot-js, using the following and similar code to access the node by HTTP or websocket:
    const { ApiPromise, WsProvider } = require('@polkadot/api');
    const { HttpProvider } = require('@polkadot/rpc-provider');
    
    (async function () {
    // Http
    const httpProvider = new HttpProvider('http://localhost:8001')
    const hash = await httpProvider.send('chain_getBlockHash', [])
    console.log('latest block Hash', hash)
    
    // Websocket
    const wsProvider = new WsProvider('ws://localhost:8001')
    const api = await ApiPromise.create({ provider: wsProvider })
    //Do something
    })()

We also provide reference examples under elara/example/. Examples can be executed:

    node client.js

You must remember that the current endpoint is provided by elara, such as 127.0.0.1:8001. You can config ws://127.0.0.1:8001 in your https://polkadot.js.org/apps/ website.

image

Then in your dashboard, you can see all the statistics.

What we have implemented for v0.1

As we describe above, we have implemented all features required in proposal.

The Substrate node of the service can be accessed through http and websocket protocols

The Official Polkadot Portal can directly use Elara as an endpoint.

Can monitor RPC requests of Substrate nodes

We can see all the statistics in Redis or on dashboard.

Can view the relevant monitoring statistics from the dashboard

We have provided a demo video to show this dashboard.

Overall, we believe that the node services, wallets, blockchain explorers and other service providers can benefit from Elara! We have done the design of Elara v0.2, Please see the next treasury proposal https://polkadot.polkassembly.io/post/141.

Up
Comments
No comments here