2023-01-19 06:38:42 -08:00
# Lite RPC For Solana Blockchain
2022-11-25 04:24:12 -08:00
2023-11-01 02:28:15 -07:00
Submitting a [transaction ](https://docs.solana.com/terminology#transaction ) to
be executed on the solana blockchain, requires the client to identify the next
few leaders based on the
[leader schedule ](https://docs.solana.com/terminology#leader-schedule ), look up
their peering information in gossip and connect to them via the
[quic protocol ](https://en.wikipedia.org/wiki/QUIC ). In order to simplify the
process so it can be triggered from a web browser, most applications run full
[validators ](https://docs.solana.com/terminology#validator ) that forward the
transactions according to the protocol on behalf of the web browser. Running
full solana [validators ](https://docs.solana.com/terminology#validator ) is
incredibly resource intensive `(>256GB RAM)` , the goal of this project would be
to create a specialized micro-service that allows to deploy this logic quickly
and allows [horizontal scalability ](https://en.wikipedia.org/wiki/Scalability )
with commodity vms. Optionally the Lite RCP micro-services can be configured to
send the transactions to a complementary __QUIC forward proxy__ instead of the
solana tpu ([details](quic-forward-proxy/README.md)).
2022-11-25 04:24:12 -08:00
2022-12-17 02:36:26 -08:00
### Confirmation strategies
2022-11-25 04:24:12 -08:00
2023-11-01 02:28:15 -07:00
1) Subscribe to new blocks using websockets (deprecated)
2) Polling blocks over RPC.(Current)
3) Subscribe blocks over gRPC.
(Current)
4) Listening to gossip protocol. (Future roadmap)
2022-12-17 02:36:26 -08:00
## Executing
*run using*
2022-12-16 18:35:49 -08:00
```bash
2022-12-17 02:36:26 -08:00
$ cargo run --release
2022-12-16 18:35:49 -08:00
```
2022-11-25 04:24:12 -08:00
2022-12-17 02:36:26 -08:00
*to know about command line options*
2022-12-16 18:35:49 -08:00
```bash
2022-12-17 02:36:26 -08:00
$ cargo run --release -- --help
2022-12-16 18:35:49 -08:00
```
2022-11-25 04:24:12 -08:00
2022-12-17 02:36:26 -08:00
## Test and Bench
*Make sure both `solana-validator` and `lite-rpc` is running*
2022-11-25 04:24:12 -08:00
2022-12-17 02:37:58 -08:00
*test*
2022-12-16 18:35:49 -08:00
```bash
2022-12-17 02:36:26 -08:00
$ cargo test
2022-12-07 08:30:29 -08:00
```
2022-12-17 02:37:58 -08:00
*bench*
2022-12-16 18:35:49 -08:00
```bash
2024-03-13 09:29:23 -07:00
$ cd bench
2024-03-14 09:49:34 -07:00
$ RUST_LOG=info cargo run -- --help
2022-12-07 08:30:29 -08:00
```
2022-12-16 18:35:49 -08:00
Find a new file named `metrics.csv` in the project root.
2022-12-17 02:36:26 -08:00
2023-05-13 06:52:43 -07:00
## Deployment
2023-01-31 05:30:52 -08:00
2023-05-13 06:52:43 -07:00
### Environment Variables
2023-01-31 05:30:52 -08:00
2023-11-27 00:54:59 -08:00
Thank you for providing the default values. Here's the updated table with the default values for the environment variables based on the additional information:
2023-12-22 06:21:01 -08:00
| Environment Variable | Purpose | Required? | Default Value |
|----------------------------------------------------------------------------|----------------------------------------------------------|---------------------|------------------------------------------------|
| `RPC_ADDR` | Address for the RPC node | Replaces default if set | `http://0.0.0.0:8899` (from `DEFAULT_RPC_ADDR` ) |
| `WS_ADDR` | WebSocket address for the RPC node | Replaces default if set | `ws://0.0.0.0:8900` (from `DEFAULT_WS_ADDR` ) |
| `LITE_RPC_HTTP_ADDR` | HTTP address for the lite RPC node | Replaces default if set | `http://0.0.0.0:8890` (from `DEFAULT_LITE_RPC_ADDR` ) |
| `LITE_RPC_WS_ADDR` | WebSocket address for the lite RPC node | Replaces default if set | `[::]:8891` (from `Config::default_lite_rpc_ws_addr` ) |
| `FANOUT_SIZE` | Configuration for the fanout size | Replaces default if set | `18` (from `DEFAULT_FANOUT_SIZE` ) |
| `IDENTITY` | Identity keypair | Optional, replaces default if set | None |
| `PROMETHEUS_ADDR` | Address for Prometheus monitoring | Replaces default if set | None specified in provided defaults |
| `MAX_RETRIES` | Maximum number of retries per transaction | Replaces default if set | `40` (from `MAX_RETRIES` ) |
| `RETRY_TIMEOUT` | Timeout for transaction retries in seconds | Replaces default if set | `3` (from `DEFAULT_RETRY_TIMEOUT` ) |
| `QUIC_PROXY_ADDR` | Address for QUIC proxy | Optional | None |
| `USE_GRPC` | Flag to enable or disable gRPC | Enables gRPC if set | `false` |
| `GRPC_ADDR` < br /> `GRPC_ADDR2`< br /> `GRPC_ADDR3`< br /> `GRPC_ADDR4` | gRPC address(es); will be multiplexed | Replaces default if set | `http://127.0.0.0:10000` (from `DEFAULT_GRPC_ADDR` ) |
| `GRPC_X_TOKEN` < br /> `GRPC_X_TOKEN2`< br /> `GRPC_X_TOKEN3`< br /> `GRPC_X_TOKEN4` | Token for gRPC authentication | Optional | None |
| `PG_*` | Various environment variables for Postgres configuration | Depends on Postgres usage | Based on `PostgresSessionConfig::new_from_env()` |
2023-01-31 05:30:52 -08:00
2023-05-13 06:52:43 -07:00
### Postgres
2023-11-01 02:28:15 -07:00
lite-rpc implements an optional postgres service that can write to postgres
database tables as defined in `./migrations` . This can be enabled by either
setting the environment variable `PG_ENABLED` to `true` or by passing the `-p`
option when launching the executable. If postgres is enabled then the optional
environment variables shown above must be set.
2023-05-13 06:52:43 -07:00
### Metrics
2023-11-01 02:28:15 -07:00
Various Prometheus metrics are exposed on `localhost:9091/metrics` which can be
used to monitor the health of the application in production.
2023-05-13 06:52:43 -07:00
### Deployment on fly.io
2023-11-01 02:28:15 -07:00
While lite-rpc can be deployed on any cloud infrastructure, it has been tested
extensively on https://fly.io. An example configuration has been provided in
`fly.toml` . We recommend a `dedicated-cpu-2x` VM with at least 4GB RAM.
The app listens by default on ports 8890 and 8891 for HTTP and Websockets
respectively. Since only a subset of RPC methods are implemented, we recommend
serving unimplemented methods from a full RPC node using a reverse proxy such as
HAProxy or Kong. Alternatively, you can connect directly to lite-rpc using a
web3.js Connection object that is _only_ used for sending and confirming
transactions.
Troubleshooting: if you encounter issues with QUIC _sendmsg_ check
[this ](https://github.com/blockworks-foundation/lite-rpc/issues/199 ) - you might
need to explicitly disable GSO (Generic Segmenatin Offload) see
```DISABLE_GSO=true```
2023-10-09 09:04:26 -07:00
2023-05-13 06:52:43 -07:00
#### Example
```bash
fly apps create my-lite-rpc
fly secrets set -a my-lite-rpc RPC_URL=... WS_URL=... # See above table for env options
fly scale vm dedicated-cpu-2x --memory 4096 -a my-lite-rpc
2023-12-01 04:02:41 -08:00
fly deploy -c cd/lite-rpc.toml -a my-lite-rpc --remote-only # To just launch lite-rpc
2023-09-09 08:55:37 -07:00
fly deploy -c cd/lite-rpc.toml -a my-lite-rpc --remote-only # To launch lite-rpc with proxy mode
2023-05-13 06:52:43 -07:00
```
2023-01-31 05:30:52 -08:00
2022-12-17 02:36:26 -08:00
## License & Copyright
Copyright (c) 2022 Blockworks Foundation
2023-05-02 05:02:21 -07:00
Licensed under the ** [AGPL-3.0 license ](LICENSE )**
2022-12-17 02:36:26 -08:00