Report for Elara v0.2
5 weeks ago, Patract Hub applied a treasury proposal for Elara v0.2. Now, we have finished all the development work on time. Please review our design, work, and enjory the seperated free services (1M requests per day) online at https://elara.patract.io. We have also privided a shared limited bandwidth node RPC service for Polkadot (wss://polkadot.elara.patract.io and https://polkadot.elara.patract.io), you can add it directly into your project and https://polkadot.js.org/apps.
#
Recap of the detailed design of Elara v0.2
- Implement the account space features, supporting developers to use Github as a third-party login system to create an account space.
- Support the creating and management of multiple projects under the developer’s account space
- Provide developers with detailed access statistics features on the single project dimension, showing statistical indicators such as daily and weekly requests, calling methods, and source of user groups.
- Officially launch https://elara.patract.io, providing the community with public access services to the Polkadot mainnet
Now, let's show you the design and implementation of v0.2, and how to run and verify the work. With this micro-service architecture described blow, we can provide 5K requests per second and 500M requests per day for now. In the future, we will upgrade this architecture for 10 times improvements.
#
Architecture of Elara v0.2We had learned from Infura's work model, so that each development account can apply for multiple Projects
to divide different Workspace
, and then assign different Provider
to access chain nodes. Therefore, the user's smallest resource unit is a Project
. We have assigned an independent PID
for each project. In the index of all resources, the developer can use this PID
to find the information corresponding to this Project
, such as detailed information, daily or weekly access statistics, etc.
Therefore, the architecture of Elara v0.2 is roughly as follows:
As can be seen from the above, in the backend management platform of Elara v0.2, the entire system is divided into 3 main modules:
Developer-Account
: The module to manage the user's account login status.Stat
: The module for management and data statistics ofProject
.API
: TheRoute
module to manage user'sRequests
.
In the overall design, the three modules are designed into a microservice architecture system, which can be independently extended. Because these three modules all run in independent processes after they are started, in the future, individual modules can be upgraded in parallel, such as expansion, reconstruction, and replacement. Among them, the Developer-Account
module and the Stat
module share data through a shared database, and the Stat
and API
are decoupled through the message queue kafka
. In the future, it will be easy to add more complex functional modules based on this design to make Elara play a more powerful effect.
These three modules are responsible for different functions:
Developer-Account
Module#
1. This module manages user account information and maintains login status. This module currently uses Redis
to cache user information and maintain the user's login status. This login status is shared with the Stat
module. Currently, this module uses Github's AccountID
information to request authorization to access Github to create users.
Therefore, the external access interfaces provided by the module after running are:
- GET
/auth/login
: Get login status information - GET
/auth/logout
: logout, remove the user's login information. - GET
/auth/github
: request authorization information from github - GET
/auth/github/callback
: processing of callbacks authorized to github
Stat
Module#
2. This module is mainly responsible for the management of Project
, and counts the request information initiated by users from the API
module in the dimensions of Project and users. This module is Consumer
of kafka
Message Middleware, which accepts request information sent from the API
module and performs processing statistics. At the same time, the module shares the user's login status information with Developer-Account
to check whether the user is still connected to Elara's webpage. In this module, each user can apply for the allocation of multiple Projects
, representing a restricted resource unit in Elara, such as limiting the amount of requests and total bandwidth that a Project can accept per day.
The access interface of the Stat
module uses PID
as the basic element, and the PID
of a project will be used as the specific node Provider
of this project in the API
module. In the process of using this PID
to raise a node access request to the API
, the developer will consume the resources managed under the project corresponding to this PID
and accumulate the statistical information of this project.
Based on the above discussion, the Stat
module is designed as follows:
- GET
/project/list
: List all project information under the currently logged-in user, and return:
{ "code": 0, "message": "", "data": [ { "id": "b78a79f98a2bb1a991a357504a5b04c1", "status": "Active", "chain": "substrate", "name": "thedao", "uid": "...", "secret": "...", "createtime": "1600398327", "lasttime": "1600398327", "allowlist": "false" }, ... ]}
The id
in the returned information is the PID
of a Project
.
- GET
/project/<PID>
: Returns the detailed information associated with thisProject
. - POST
/project/create
: Create a newProject
based on the information of the currently logged in user
Parameters:
chain:<Polkdaot|Kusama>name:<Validation rules /[a-zA-Z]{4,32}/>
- GET
/stat/day/<PID>
: Get the statistics of aProject
in one day - GET
/stat/day/<PID>
: Get the statistical information of aProject
within one week - See the document for other interface definitions: Stat README
API
Module#
3. After receiving requests from different users, the API
module distinguishes which request to a Project
according to the PID
carried in the routing information, sends the corresponding information to the kafka
queue, and forwards the user request to the corresponding node. Therefore, for the API
module, Elara designed the following two access interfaces, among which the parameters of <chain>
can currently be filled in Polkadot
and Kusama
.
- HTTPS, POST
/<chain>/<PID>
: Accept the RPC request initiated by the user. The parameters of the request are all RPC interfaces that the node provides external services - Websocket
/<chain>/<PID>
: Accept the Websocket request initiated by the user. The parameters of the request are all RPC interfaces that the node provides external services
The above three modules work together to provide Elara's back-end components. Adding a front-end kit on top of it can become a complete Elara product to provide external services: https://elara.patract.io/ The sample screenshot is as follows:
This module is used to provide node services. It is mainly responsible to proxy user's node access request (RPC & websocket) to the node, and as the Producer of the kafka
message queue, it sends the relevant information of the user request to the Stat
module. In the API
module, the user composes the PID
created in the Stat
module into the URL of the access node Provider
, and then initiates a node access request to the API
module.
#
4. SummaryThe above three modules work together to provide Elara's back-end components. Adding a front-end kit on top of it can become a complete Elara product to provide external services: https://elara.patract.io/ The sample screenshot is as follows:
#
Run ElaraThe processes corresponding to the above 3 modules need to be started in sequence in the following order to make Elara work properly: 1, Developer-Account
, 2, Stat
, 3.API
#
Environment preparationElara's operating environment requires redis
and kafka
support. Therefore, before running the following commands, first ensure that there is a running redis
instance in the running environment and the executable file of kafka
has been installed. The 3 processes of Elara are run by node
, so you need to install the corresponding dependencies with the yarn
command before running.
#
Start ServicesStart
Developer-Account
Service- Enter
elara/packages/account
directory$ cd package/account
- Install dependence
$ yarn install
- Modify the configuration file of the
Developer-Account
service, including theredis
field and thegithub
field. The default port is set to7001
, so if theport
domain is not modified, the service will occupy the7001
port after startup.$ vim ./config/env/dev.env.js
- Start the service, and the log output by the process is located in the
./logs
directory.$ node app.js# or use pm2 to manage process$ pm2 start pm2.json --env dev
- Enter
Start
Stat
Service- Enter
elara/packages/stat
directory(If you are inaccount
directory)$ cd ../stat
- Install dependence
$ yarn install
- Switch to the
kafka
directory, start thekafka
directory and set thetopic
- Start
kafka
and related processes. If the configuration file ofkafka
is not modified, port9092
will be occupied by default.$ cd <the root directory of kafka>$ bin/zookeeper-server-start.sh config/zookeeper.properties$ bin/kafka-server-start.sh config/server.properties
- Add
elara-dev
topic tokafka
# add `elara-dev` topic to kafka$ bin/kafka-topics.sh --create --topic elara-dev --bootstrap-server localhost:9092# check whethere this topic is inittedbin/kafka-topics.sh --describe --topic elara-dev --bootstrap-server localhost:9092
- Start
- Switch to
elara/packages/stat
directory,modify the configration file ofStat
module.$ vim ./config/env/dev.env.js
- Since
Stat
andDeveloper-Account
share the sameredis
instance, the configuration of theredis
field in this configuration file should be consistent with the configuration ofredis
in theDeveloper-Account
configuration file . - The
kafka
domain here needs to be consistent with the configuration of startingkafka
in the previous step. - If it is only used for local testing, please modify the
test:false
in the default configuration totest:true
. After enabling this flag, when accessing the interface provided bystat
, the login status of the login account will not be verified, and all interfaces can be directly accessed. In a production environment, please ensure that the value of thetest
field isfalse
. - The default
port
domain in the configuration file is7002
, so if you do not modify this value, it will occupy the7002
port to provide services after startup.
- Since
- Start Services
- Start the
stat
service. If you do not modify the port after startup, the7002
port will be occupied. The following text uses127.0.0.1:7002
as the service address performed bystat
. The log output by the process is located in the./logs
directory.$ node app.js# or use pm2 to manage process$ pm2 start pm2.json --env dev
- Start
kafka
consumer service$ node ./kafka/consumer.js
- If you need to see the console information, you need to start the
dashboard
serviceAt this point, you can open$ node ./timer/dashboard.js
http://127.0.0.1:7002/dashboard
in the browser to see the statistics information of the monitoring station.
- Start the
- Enter
Start
API
ServiceEnter
elara/packages/api
directory(if you are instat
)$ cd ../api
Install dependence
$ yarn install
Modify the configuration file of the
API
module$ vim ./config/env/dev.env.js
- The
chain
field is used to configure the real chain node, where the name of the chain is part of the route provided by theapi
to the developer. For example, if there are the following configurations in the default, the access method of/Polkadot/<PID>
is supported in the routing supported by the API.'Polkadot': { 'rpc': ['****:**'], //configure as node http://IP: RPC port in step 2 'ws': ['****:**'] //configure as node ws://IP: WS port in step 2}
- The
kafka
field is used to configure the information of thekafka
process started in thestat
section. Note that the configured topic is the topicelara-dev
registered tokafka
when thestat
part is configured. , startServer
filed is used to configure the ip and port of thestat
process. For example, ifapi
andstat
are on the same host and the default configuration is used (that is,stat
occupies port 7002 by default), then The value here is127.0.0.1:7002
port
field is used to configure the port occupied by theapi
service process, the default configuration is 7003
- The
Start Services
$ node app.js# or use pm2 to manage process$ pm2 start pm2.json --env dev
At this time the service has been started, if the port is not modified, the port
7003
will be occupied. The following text uses the port127.0.0.1:7003
as the host for user access. The log output by the process is located in the./logs
directory.
#
Call ElaraSince the configuration of test:true
is used when starting stat
in the above case, the process of user login is skipped in the following process, and the process of creating Project
is directly started.
Create Project:
Send a request to create a project to the service address
127.0.0.1:7002
ofstat
: This project is a request for access to thePolkadot
chain, so the value of the parameterchain
is specified asPolkadot
.POST http://127.0.0.1:7002/project/create chain:Polkadotname:hello
Return:
{ "code": 0, "mssage": "", "data": { "id": "5d4ebb40b08f127652ad022f5936b9da", "status": "Active", "chain": "Polkadot", "name": "hello", "uid": "Only For Test", "secret": "0b89a386965bfe4dcb19f724ecb41890", "createtime": "1606581366", "lasttime": "1606581366", "allowlist": "false" }}
You can get the detailed information of creating
Project
andPID
, here is5d4ebb40b08f127652ad022f5936b9da
List all the
Projects
for this userGET http://127.0.0.1:7002/project/list
Return:
{ "code": 0, "message": "", "data": [ { "id": "5d4ebb40b08f127652ad022f5936b9da", "status": "Active", "chain": "Polkadot", "name": "hello", "uid": "Only For Test", "secret": "0b89a386965bfe4dcb19f724ecb41890", "createtime": "1606581366", "lasttime": "1606581366", "allowlist": "false" } ]}
Since testing is currently enabled, all
Project
information will be listed. If the test is not turned on, only the information list ofProject
for the current login will be listed.Use this PID as part of the route to initiate an access request to the node.
The access request to the node needs to be served through
API
, the currentAPI
service address is127.0.0.1:7003
, so we can initiate the following request: The access route is<api server host>/<project chain>/< PID>
composition, so in this case- The access address for rpc is
http://127.0.0.1:7003/Polkadot/5d4ebb40b08f127652ad022f5936b9da
- The access address for websocket is
ws://127.0.0.1:7003/Polkadot/5d4ebb40b08f127652ad022f5936b9da
POST http://127.0.0.1:7003/Polkadot/5d4ebb40b08f127652ad022f5936b9da { "id":1, "jsonrpc":"2.0", "method":"system_chain", "params":[ ]}
API
Service is normal and return:{ "jsonrpc": "2.0", "result": "Polkadot", "id": 1}
This request will be counted by Elara normally and recorded that project
5d4ebb40b08f127652ad022f5936b9da
has one request.- The access address for rpc is
If you want to test whether the api service can satisfy normal node requests, you can add the websocket access link to
Polkadot/Substrate Portal
。Log in to the Portal web page in the browser
Click on the upper left corner
Click on the
DEVELOPMENT
column and click on theCustom
column to fill inws://127.0.0.1:7003/Polkadot/5d4ebb40b08f127652ad022f5936b9da
Click "Switch"
At this point the Portal should be able to work normally, and all access requests are recorded by Elara.
Access the
Stat
service to get statisticsSuch as listing all the visit statistics of the current project in the day
GET http://127.0.0.1:7002/stat/day/5d4ebb40b08f127652ad022f5936b9da
Or list the statistics of this project this week
GET http://127.0.0.1:7002/stat/week/5d4ebb40b08f127652ad022f5936b9da
Visit
http://127.0.0.1:7002/dashboard
and you can see the total statistics from the console.
At this point, the entire system can operate normally.
#
验证Developers can use Github account to log in to the developer account space from https://elara.patract.ioAnyone can currently get access to the Polkadot chain through this link.
Developers can create new projects and access related API keys under the accountThe above process has introduced the concept of project, and you can log in to github with authorization and create a project at https://elara.patract.io.
Developers can access the Polkadot node in Elara through Http and web-socket protocols
The
API
service is used to support this function, and the corresponding operations have been shown aboveDevelopers can view the monitoring statistics of the projects on the day and the recent weeks
The
/stat/day/<PID>
and/stat/week/<PID>
interfaces ofStat
service are used to support this function.You can view the relevant monitoring statistics from the Elara dashboard
You can see the corresponding information from the
http://127.0.0.1:7002/dashboard
console.