Skip to content

Commit

Permalink
feat(store-indexer): add env var to index only one store (#1886)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Nov 9, 2023
1 parent 5ecccfe commit f318f2f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-crabs-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-indexer": minor
---

Added `STORE_ADDRESS` environment variable to index only a specific MUD Store.
15 changes: 8 additions & 7 deletions packages/store-indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ Each indexer can be configured with environment variables.

### Common environment variables for indexer

| Variable | Description | Default |
| ------------------ | ---------------------------------------------------------- | ------- |
| `RPC_HTTP_URL` | HTTP URL for Ethereum RPC to fetch data from | |
| `RPC_WS_URL` | WebSocket URL for Ethereum RPC to fetch data from | |
| `START_BLOCK` | Block number to start indexing from | `0` |
| `MAX_BLOCK_RANGE` | Maximum number of blocks to fetch from the RPC per request | `1000` |
| `POLLING_INTERVAL` | How often to poll for new blocks (in milliseconds) | `1000` |
| Variable | Description | Default |
| ------------------ | ------------------------------------------------------------------------------------------------------------- | ------- |
| `RPC_HTTP_URL` | HTTP URL for Ethereum RPC to fetch data from | |
| `RPC_WS_URL` | WebSocket URL for Ethereum RPC to fetch data from | |
| `START_BLOCK` | Block number to start indexing from | `0` |
| `MAX_BLOCK_RANGE` | Maximum number of blocks to fetch from the RPC per request | `1000` |
| `POLLING_INTERVAL` | How often to poll for new blocks (in milliseconds) | `1000` |
| `STORE_ADDRESS` | Optional address of the MUD Store to index. By default, store-indexer will index all MUD Stores on the chain. | |

Note that you only need one of `RPC_HTTP_URL` or `RPC_WS_URL`, but we recommend both. The WebSocket URL will be prioritized and fall back to the HTTP URL if there are any connection issues.

Expand Down
2 changes: 2 additions & 0 deletions packages/store-indexer/bin/parseEnv.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isHex } from "viem";
import { z, ZodError, ZodTypeAny } from "zod";

export const frontendEnvSchema = z.object({
Expand All @@ -10,6 +11,7 @@ export const indexerEnvSchema = z.intersection(
START_BLOCK: z.coerce.bigint().nonnegative().default(0n),
MAX_BLOCK_RANGE: z.coerce.bigint().positive().default(1000n),
POLLING_INTERVAL: z.coerce.number().positive().default(1000),
STORE_ADDRESS: z.string().refine(isHex).optional(),
}),
z.union([
z.object({
Expand Down
1 change: 1 addition & 0 deletions packages/store-indexer/bin/postgres-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const { latestBlockNumber$, storedBlockLogs$ } = await createStoreSync({
publicClient,
startBlock,
maxBlockRange: env.MAX_BLOCK_RANGE,
address: env.STORE_ADDRESS,
});

storedBlockLogs$.subscribe();
Expand Down
1 change: 1 addition & 0 deletions packages/store-indexer/bin/sqlite-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const { latestBlockNumber$, storedBlockLogs$ } = await syncToSqlite({
publicClient,
startBlock,
maxBlockRange: env.MAX_BLOCK_RANGE,
address: env.STORE_ADDRESS,
});

let isCaughtUp = false;
Expand Down

0 comments on commit f318f2f

Please sign in to comment.