feat(storage): add canonical dlob postgres store

This commit is contained in:
mpabi
2026-03-13 23:10:35 +01:00
parent 8a378b7a08
commit 1ea14833ba
7 changed files with 712 additions and 0 deletions

View File

@@ -82,6 +82,12 @@ To properly configure the DLOB server, set the following environment variables i
| `ELASTICACHE_HOST` | (for websocket server) Redis host endpoint. | `localhost` |
| `ELASTICACHE_PORT` | (for websocket server) Redis port. | `6379` |
| `REDIS_CLIENT` | (for websocket server) Redis client type (DLOB/DLOB_HELIUS). | `DLOB` |
| `ENABLE_PERSISTENT_STORE` | Persist canonical latest DLOB snapshots to Postgres. | `true` |
| `POSTGRES_URL` | Connection string for canonical DLOB store. | `postgres://user:pass@host:5432/db` |
| `DLOB_SOURCE` | Source key stored with canonical DLOB rows. | `mevnode` |
| `PRICE_PRECISION` | Price scale used by projection views. | `1000000` |
| `BASE_PRECISION` | Base size scale used by projection views. | `1000000000` |
| `PERSISTENT_STATS_DEPTH` | Depth used by SQL projection views for stats. | `10` |
| `WS_PORT` | (for websocket server) The port to run the websocket server on. | `3000` |
Note: multiple Redis hosts can be provided by providing a comma separated string.
@@ -131,6 +137,30 @@ When you're done, stop the redis cluster:
bash redisCluster.sh stop
```
## Persistent canonical store
The publisher can now persist canonical latest DLOB snapshots directly to Postgres while still using Redis as the hot path.
- Redis remains the runtime cache and pub/sub layer.
- Postgres stores canonical latest snapshots in:
- `dlob_orderbook_l2_latest`
- `dlob_orderbook_l3_latest`
- `dlob_best_makers_latest`
- Postgres exposes projection views for Hasura and frontend adaptation:
- `dlob_l2_latest_projection`
- `dlob_l3_latest_projection`
- `dlob_best_makers_latest_projection`
- `dlob_stats_latest_projection`
- This aligns the DLOB stack with a `Redis hot state + Postgres durable canonical store + projection views` model.
To initialize the persistent tables without connecting to chain inputs yet:
```bash
ENABLE_PERSISTENT_STORE=true \
POSTGRES_URL=postgres://user:pass@host:5432/db \
yarn dlob-storage:init
```
# Run the example client
Documentation for connecting to the dlob server are available [here](https://drift-labs.github.io/v2-teacher/?python#orderbook-trades-dlob-server)