RPC daemon
Remote Procedure Call
Like any other Erigon component, the Remote Procedure Call (RPC) can run within the Erigon all-in-one client or as an independent process. Erigon's rpcdaemon
runs in its own separate process. This has many advantages, including easier development, the ability to run multiple daemons at once, and the ability to run the daemon remotely. It is also possible to run the daemon locally (read-only) if both processes have access to the data folder.
Getting Started
The rpcdaemon
gets built as part of the main Erigon build process, but you can build it directly with this command:
Built-in RPC daemon
To enable RPC server as a built-in service in Erigon add the flags --http
and --ws
(sharing same port with http). For example:
Warning: The above example is a convenient but insecure snippet to allow users to connect their wallet from any host. To have a secure connection it is recommended to utilize TLS Authentication.
This command run Erigon on a remote server allowing connection from any host, enabling http api for eth, web3, net etc. To connect a remote wallet use IP address of the remote machine on the RPC URL. Default port is 8545 e.g. http://123.123.123.123:8545.
Websocket
Erigon supports also WebSocket protocol, just add the flag --ws
to enable the WS-RPC server (default: false) or --ws.compression
to enable compression over WebSocket (default: false).
In order to specify websocket server listening port you can use the flag --ws.port
(default: 8546)
GraphQL
GraphQL protocol is also supported, add flag --graphql
.
RPC as a separate process
The RPC daemon can use:
The local database, with Erigon running or on a snapshot of a database
A remote database running on another machine.
Running Locally
Run rpcdaemon
on the same computer along with Erigon. It's the default option because it uses Shared Memory access to Erigon's db, which is much faster than TCP access. Always provide the following options: - --datadir
to specify where Erigon data are stored; by default /home/user/.local/share/erigon
. - --private.api.addr
to provide private api network address (default "127.0.0.1:9090")
With the above command it has also been specified which RPC namespaces to enable by --http.api
flag.
Running Remotely
In some cases, it is useful to run Erigon nodes in a different network (for example, in a public cloud), but rpcdaemon
locally. In this scenario the local machine requires no storing capacity and basic computing requirements.
Warning: To ensure the integrity of communication and access control to the Erigon node, TLS authentication is needed.
This works regardless of whether RPC daemon is on the same computer with Erigon, or on a different one. They use TPC socket connection to pass data between them. To use this mode, run Erigon in one terminal window.
To start rpcdaemon
remotely - just don't set the --datadir
flag:
If the Erigon process is on one machine and RPC daemon is on another machine, use the private.api.addr
option for Erigon and open port 9090:
On the other machine:
For instance you can run also a number of different RPC daemon on different machines, attaching to the same Erigon process.
The daemon should respond with something like:
When running remotely, rpcdaemon
by default maintains a state cache that is updated each time Erigon imports a new block. When the state cache is reasonably warm, it allows such a remote RPC daemon to execute queries related to the latest block (i.e. current state) with comparable performance to a local rpcdaemon
(about 2x slower vs. 10x slower without state cache). Since there can be multiple such RPC daemons per Erigon node, it may scale well for some workloads that are heavy on current state queries.
Healthcheck
There are 2 options for running healtchecks, POST request, or GET request with custom headers. Both options are available at the /health
endpoint.
POST request
If the health check is successful it returns 200 OK
.
If the health check fails it returns 500 Internal Server Error
.
Configuration of the health check is sent as POST body of the method.
Not adding a check disables that.
v`min_peer_count` -- checks for mimimum of healthy node peers. Requires net
namespace to be listed in http.api
.
known_block
-- sets up the block that node has to know about. Requires eth
namespace to be listed in http.api
.
Example request http POST http://localhost:8545/health --raw '{"min_peer_count": 3, "known_block": "0x1F"}'
Example response:
GET with headers
If the healthcheck is successful it will return a 200 status code
.
If the healthcheck fails for any reason a status 500
will be returned. This is true if one of the criteria requested fails its check.
You can set any number of values on the X-ERIGON-HEALTHCHECK
header. Ones that are not included are skipped in the checks.
Available Options:
synced
- will check if the node has completed syncingmin_peer_count<count>
- will check that the node has at least <count> many peerscheck_block<block>
- will check that the node is at least ahead of the specified<block>
max_seconds_behind<seconds>
- will check that the node is no more than<seconds>
behind from its latest block
Example Request:
Example Response
Testing
By default, the rpcdaemon
serves data from localhost:8545
. You may send curl commands to see if things are working.
Try eth_blockNumber
for example. In a third terminal window enter this command:
This should return something along the lines of this (depending on how far your Erigon node has synced):
Postman may also be used to test rpcdaemon
.
Command Line Options
RPCdaemon is started and controlled using the command line. It is stopped by pressing ctrl-c.
You can configure RPCdaemon using command-line options (a.k.a. flags), which you can use to specify also sub-commands to invoke other functionalities.
The command-line help listing is reproduced below for your convenience. The same information can be obtained at any time from your own RPCdaemon instance by running:
gRPC ports
9090
erigon, 9091
sentry, 9092
consensus engine, 9093
torrent downloader, 9094
transactions pool
Supported JSON-RPC calls (eth, debug , net, web3):
For a details on the implementation status of each command, see this table.
For more detailed on RPC daemon info refer to this page:
https://github.com/ledgerwatch/erigon/blob/main/cmd/rpcdaemon/README.md
Commands
Last updated