Skip to content

Commit

Permalink
Merge pull request #28 from ironbeer/feat/websocket-proxy
Browse files Browse the repository at this point in the history
Add WebSocket proxy
  • Loading branch information
ironbeer authored May 28, 2024
2 parents fc1b97c + bd8b7b0 commit a3bf84f
Show file tree
Hide file tree
Showing 22 changed files with 3,107 additions and 1,813 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PORT=3000
VERSE_MASTER_NODE_URL=http://localhost:8545
VERSE_READ_NODE_URL=
VERSE_WS_URL=ws://localhost:8546
DATASTORE=redis
REDIS_URI=redis://localhost:6379
BLOCK_NUMBER_CACHE_EXPIRE_SEC=
MAX_BODY_BYTE_SIZE=
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ lerna-debug.log*
!.vscode/launch.json
!.vscode/extensions.json

# Environment variable
.env
# Dev dependencies
.env*
!.env.example
.node-version
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,26 @@ Details are described later.
- `src/config/configuration.ts`
- `src/config/transactionAllowList.ts`

### 3. Set up npm
### 3. Set configuration variables
- Create file `.env` refer to `.env.example`
- Update those variables with corrected values from your side

### 4. Set up redis server
- Verse-Proxy use redis as a database to read and write data, so in order to run this proxy you will need start a redis server and pass url to `REDIS_URI`
- also Verse-Proxy need to know which database you would use which can be config using `DATASTORE`
For example:
```
DATASTORE=redis
REDIS_URI=redis://localhost:6379
```

### 5. Set up npm
```bash
$ npm install
$ npm build
```

### 4. Run app
### 6. Run app

```bash
# development
Expand Down Expand Up @@ -57,7 +70,7 @@ $ npm run test:cov
#### 1. Set Environment Variables
```bash
export PORT=[YOUR_PROXY_PORT]
export VERSE_URL=[YOUR_VERSE_URL]
export VERSE_MASTER_NODE_URL=[YOUR_VERSE_HTTP_URL]
```

#### 2. Set allow list config
Expand Down Expand Up @@ -293,10 +306,19 @@ It will send read-transactions to the read-node and write-transactions to the ma

You can set Master-Verse-Node and Read-Verse-node by the environment variable.
```bash
VERSE_MASTER_NODE_URL=[YOUR_VERSE_URL]
VERSE_READ_NODE_URL=[YOUR_VERSE_REPLICA_URL]
VERSE_READ_NODE_URL=[YOUR_VERSE_REPLICA_HTTP_URL]
```

### WebSocket Proxy
The WebSocket proxy is an experimental feature. To enable it, add the WebSocket rpc url of the your Verse node to the following environment variable and then restart the proxy.
```bash
VERSE_WS_URL=[YOUR_VERSE_WEBSOCKET_URL]
```

In the WebSocket proxy feature, only the `eth_subscribe` and `eth_unsubscribe` methods are proxied to the Verse node. All other methods are internally routed to the HTTP proxy feature. This means that if the `VERSE_READ_NODE_URL` environment variable is configured, read-transactions are proxied to the replica node, while write-transactions are proxied to the master node.

**For the question of whether to choose a master node or a reader node**, please make your selection considering replication latency. Since latency is typically only a few tens of milliseconds, it is generally recommended to use the reader node.

### Check Master-Verse-Node
To check the behavior of requests to the Master-Verse-Node, an endpoint named `/master` is provided.

Expand Down
Loading

0 comments on commit a3bf84f

Please sign in to comment.