From 8ef49ae693282edcfd3d37238181c4e5cce9d05e Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 22 Sep 2023 11:18:39 +0100 Subject: [PATCH 01/10] feat(store-indexer,store-sync): support filtering indexer query by tableIds --- packages/store-indexer/src/postgres/createQueryAdapter.ts | 8 ++++---- packages/store-indexer/src/sqlite/createQueryAdapter.ts | 7 +++++-- packages/store-sync/src/trpc-indexer/common.ts | 5 +---- packages/store-sync/src/trpc-indexer/createAppRouter.ts | 5 +++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/store-indexer/src/postgres/createQueryAdapter.ts b/packages/store-indexer/src/postgres/createQueryAdapter.ts index 17600fca5d..08feb6a924 100644 --- a/packages/store-indexer/src/postgres/createQueryAdapter.ts +++ b/packages/store-indexer/src/postgres/createQueryAdapter.ts @@ -13,11 +13,11 @@ import { getAddress } from "viem"; */ export async function createQueryAdapter(database: PgDatabase): Promise { const adapter: QueryAdapter = { - async findAll(chainId, address) { + async findAll({ chainId, address, tableIds }) { const internalTables = buildInternalTables(); - const tables = (await getTables(database)).filter( - (table) => address != null && getAddress(address) === getAddress(table.address) - ); + const tables = (await getTables(database)) + .filter((table) => address != null && getAddress(address) === getAddress(table.address)) + .filter((table) => tableIds != null && tableIds.includes(table.tableId)); const tablesWithRecords = await Promise.all( tables.map(async (table) => { diff --git a/packages/store-indexer/src/sqlite/createQueryAdapter.ts b/packages/store-indexer/src/sqlite/createQueryAdapter.ts index eae41e90c4..6e691b7a01 100644 --- a/packages/store-indexer/src/sqlite/createQueryAdapter.ts +++ b/packages/store-indexer/src/sqlite/createQueryAdapter.ts @@ -3,6 +3,7 @@ import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core"; import { createSqliteTable, chainState, getTables } from "@latticexyz/store-sync/sqlite"; import { QueryAdapter } from "@latticexyz/store-sync/trpc-indexer"; import { debug } from "../debug"; +import { getAddress } from "viem"; /** * Creates a storage adapter for the tRPC server/client to query data from SQLite. @@ -12,8 +13,10 @@ import { debug } from "../debug"; */ export async function createQueryAdapter(database: BaseSQLiteDatabase<"sync", any>): Promise { const adapter: QueryAdapter = { - async findAll(chainId, address) { - const tables = getTables(database).filter((table) => table.address === address); + async findAll({ chainId, address, tableIds }) { + const tables = getTables(database) + .filter((table) => address != null && getAddress(address) === getAddress(table.address)) + .filter((table) => tableIds != null && tableIds.includes(table.tableId)); const tablesWithRecords = tables.map((table) => { const sqliteTable = createSqliteTable(table); diff --git a/packages/store-sync/src/trpc-indexer/common.ts b/packages/store-sync/src/trpc-indexer/common.ts index c9ca712880..dc5d7005f4 100644 --- a/packages/store-sync/src/trpc-indexer/common.ts +++ b/packages/store-sync/src/trpc-indexer/common.ts @@ -2,10 +2,7 @@ import { Hex } from "viem"; import { TableWithRecords } from "../common"; export type QueryAdapter = { - findAll: ( - chainId: number, - address?: Hex - ) => Promise<{ + findAll: (opts: { chainId: number; address?: Hex; tableIds?: Hex[] }) => Promise<{ blockNumber: bigint | null; tables: TableWithRecords[]; }>; diff --git a/packages/store-sync/src/trpc-indexer/createAppRouter.ts b/packages/store-sync/src/trpc-indexer/createAppRouter.ts index c965dac7c5..71a4fae085 100644 --- a/packages/store-sync/src/trpc-indexer/createAppRouter.ts +++ b/packages/store-sync/src/trpc-indexer/createAppRouter.ts @@ -16,12 +16,13 @@ export function createAppRouter() { z.object({ chainId: z.number(), address: z.string().refine(isHex).optional(), + tableIds: z.array(z.string().refine(isHex)).optional(), }) ) .query(async (opts): ReturnType => { const { queryAdapter } = opts.ctx; - const { chainId, address } = opts.input; - return queryAdapter.findAll(chainId, address); + const { chainId, address, tableIds } = opts.input; + return queryAdapter.findAll({ chainId, address, tableIds }); }), }); } From 05077299298ef63e7f7c807fb08e698fd4857fcd Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 22 Sep 2023 11:49:21 +0100 Subject: [PATCH 02/10] filter by tableId during sync --- packages/store-sync/src/common.ts | 4 ++++ packages/store-sync/src/createStoreSync.ts | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/store-sync/src/common.ts b/packages/store-sync/src/common.ts index d903b05ba1..7791e216d8 100644 --- a/packages/store-sync/src/common.ts +++ b/packages/store-sync/src/common.ts @@ -99,6 +99,10 @@ export type SyncOptions = { * Optional maximum block range, if your RPC limits the amount of blocks fetched at a time. */ maxBlockRange?: bigint; + /** + * Optional table IDs to filter indexer state and RPC state. + */ + tableIds?: Hex[]; /** * Optional MUD tRPC indexer URL to fetch initial state from. */ diff --git a/packages/store-sync/src/createStoreSync.ts b/packages/store-sync/src/createStoreSync.ts index 2e0cfc0857..bb3e5b133f 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -1,6 +1,6 @@ import { ConfigToKeyPrimitives, ConfigToValuePrimitives, StoreConfig, storeEventsAbi } from "@latticexyz/store"; import { Hex, TransactionReceiptNotFoundError } from "viem"; -import { SetRecordOperation, StorageAdapter, SyncOptions, SyncResult, TableWithRecords } from "./common"; +import { BlockLogs, SetRecordOperation, StorageAdapter, SyncOptions, SyncResult, TableWithRecords } from "./common"; import { createBlockStream, blockRangeToLogs, groupLogsByBlockNumber } from "@latticexyz/block-logs-stream"; import { filter, @@ -19,6 +19,7 @@ import { combineLatest, scan, identity, + Observable, } from "rxjs"; import { BlockStorageOperations, blockLogsToStorage } from "./blockLogsToStorage"; import { debug as parentDebug } from "./debug"; @@ -48,6 +49,7 @@ export async function createStoreSync publicClient, startBlock: initialStartBlock = 0n, maxBlockRange, + tableIds, initialState, indexerUrl, }: CreateStoreSyncOptions): Promise> { @@ -74,7 +76,7 @@ export async function createStoreSync const indexer = createIndexerClient({ url: indexerUrl }); const chainId = publicClient.chain?.id ?? (await publicClient.getChainId()); - const result = await indexer.findAll.query({ chainId, address }); + const result = await indexer.findAll.query({ chainId, address, tableIds }); onProgress?.({ step: SyncStep.SNAPSHOT, @@ -114,6 +116,13 @@ export async function createStoreSync (initialState): initialState is { blockNumber: bigint; tables: TableWithRecords[] } => initialState != null && initialState.blockNumber != null && initialState.tables.length > 0 ), + // Initial state from indexer should already be filtered by table IDs, but we should + // still attempt to filter in case initialState was passed in as an argument or the + // indexer is being silly. + map(({ blockNumber, tables }) => ({ + blockNumber, + tables: tables.filter((table) => tableIds != null && tableIds.includes(table.tableId)), + })), concatMap(async ({ blockNumber, tables }) => { debug("hydrating from initial state to block", blockNumber); @@ -179,7 +188,7 @@ export async function createStoreSync let startBlock: bigint | null = null; let endBlock: bigint | null = null; - const blockLogs$ = combineLatest([startBlock$, latestBlockNumber$]).pipe( + const blockLogs$: Observable = combineLatest([startBlock$, latestBlockNumber$]).pipe( map(([startBlock, endBlock]) => ({ startBlock, endBlock })), tap((range) => { startBlock = range.startBlock; @@ -192,6 +201,10 @@ export async function createStoreSync maxBlockRange, }), mergeMap(({ toBlock, logs }) => from(groupLogsByBlockNumber(logs, toBlock))), + map(({ blockNumber, logs }) => ({ + blockNumber, + logs: logs.filter((log) => tableIds != null && tableIds.includes(log.args.table)), + })), share() ); From 98e11fadd19cc3367382c377bb8d6aff79f7890c Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 22 Sep 2023 12:06:28 +0100 Subject: [PATCH 03/10] see if our own runner helps --- .github/workflows/build.yml | 2 +- .github/workflows/snapshot.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a7c94549f4..45f81ec52c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ on: jobs: build: name: Build and validate artifacts - runs-on: ubuntu-latest + runs-on: ubuntu-latest-16-cores steps: - name: Checkout uses: actions/checkout@v3 diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 4837cd0d09..ab61928c2a 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -11,7 +11,7 @@ on: jobs: release-snapshot: name: Publish snapshot release to npm - runs-on: ubuntu-latest + runs-on: ubuntu-latest-16-cores if: github.event_name != 'workflow_dispatch' steps: - name: Checkout diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f36c3200eb..d61aae167f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ on: jobs: test: name: Run tests - runs-on: ubuntu-latest + runs-on: ubuntu-latest-16-cores services: postgres: image: postgres:12.1-alpine From 6f3c8564e0a7fcea42d2d796e56588d5ead033d5 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 22 Sep 2023 12:10:23 +0100 Subject: [PATCH 04/10] Revert "see if our own runner helps" This reverts commit 98e11fadd19cc3367382c377bb8d6aff79f7890c. --- .github/workflows/build.yml | 2 +- .github/workflows/snapshot.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 45f81ec52c..a7c94549f4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ on: jobs: build: name: Build and validate artifacts - runs-on: ubuntu-latest-16-cores + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index ab61928c2a..4837cd0d09 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -11,7 +11,7 @@ on: jobs: release-snapshot: name: Publish snapshot release to npm - runs-on: ubuntu-latest-16-cores + runs-on: ubuntu-latest if: github.event_name != 'workflow_dispatch' steps: - name: Checkout diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d61aae167f..f36c3200eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ on: jobs: test: name: Run tests - runs-on: ubuntu-latest-16-cores + runs-on: ubuntu-latest services: postgres: image: postgres:12.1-alpine From 40acb0d284e4f6f734e24d8cfbcdfc5e28282623 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 22 Sep 2023 12:35:17 +0100 Subject: [PATCH 05/10] allow dispatch to snapshot --- .github/workflows/snapshot.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 4837cd0d09..a97dac509c 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -12,7 +12,6 @@ jobs: release-snapshot: name: Publish snapshot release to npm runs-on: ubuntu-latest - if: github.event_name != 'workflow_dispatch' steps: - name: Checkout uses: actions/checkout@v3 From 3faa0320b91c95c8fc3d9f9746597af1acf70147 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 22 Sep 2023 21:37:24 +0000 Subject: [PATCH 06/10] filter data --- .../src/sqlite/createQueryAdapter.ts | 58 +++++++++++++++++-- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/packages/store-indexer/src/sqlite/createQueryAdapter.ts b/packages/store-indexer/src/sqlite/createQueryAdapter.ts index 6e691b7a01..830e0cbbf0 100644 --- a/packages/store-indexer/src/sqlite/createQueryAdapter.ts +++ b/packages/store-indexer/src/sqlite/createQueryAdapter.ts @@ -1,9 +1,9 @@ -import { eq } from "drizzle-orm"; +import { eq, inArray, and } from "drizzle-orm"; import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core"; import { createSqliteTable, chainState, getTables } from "@latticexyz/store-sync/sqlite"; import { QueryAdapter } from "@latticexyz/store-sync/trpc-indexer"; import { debug } from "../debug"; -import { getAddress } from "viem"; +import { Hex, getAddress } from "viem"; /** * Creates a storage adapter for the tRPC server/client to query data from SQLite. @@ -16,11 +16,49 @@ export async function createQueryAdapter(database: BaseSQLiteDatabase<"sync", an async findAll({ chainId, address, tableIds }) { const tables = getTables(database) .filter((table) => address != null && getAddress(address) === getAddress(table.address)) - .filter((table) => tableIds != null && tableIds.includes(table.tableId)); + .filter((table) => + // we don't need KeysWithValue tables + address === "0xB41e747bC9d07c85F020618A3A07d50F96703A78" ? table.namespace !== "keyswval" : true + ) + .filter((table) => tableIds == null || tableIds.includes(table.tableId)); + + const entities = ((): Hex[] => { + if (address !== "0xB41e747bC9d07c85F020618A3A07d50F96703A78") return []; + try { + const Position = createSqliteTable({ + address: "0xB41e747bC9d07c85F020618A3A07d50F96703A78", + namespace: "", + name: "Position", + keySchema: { key: "bytes32" }, + valueSchema: { + x: "int32", + y: "int32", + z: "int32", + }, + }); + // TODO: configurable match ID + const positions = database.select().from(Position).where(eq(Position.z, 137)).all(); + return positions.map((pos) => pos.key); + } catch (error: unknown) { + return []; + } + })(); const tablesWithRecords = tables.map((table) => { const sqliteTable = createSqliteTable(table); - const records = database.select().from(sqliteTable).where(eq(sqliteTable.__isDeleted, false)).all(); + const records = database + .select() + .from(sqliteTable) + .where( + and( + eq(sqliteTable.__isDeleted, false), + (entities.length && table.name === "MoveDifficulty") || + table.name === "TerrainType" /* || table.name === "ArmorModifier"*/ + ? inArray(sqliteTable.__key, entities) + : undefined + ) + ) + .all(); return { ...table, records: records.map((record) => ({ @@ -38,7 +76,17 @@ export async function createQueryAdapter(database: BaseSQLiteDatabase<"sync", an tables: tablesWithRecords, }; - debug("findAll", chainId, address, result); + const counts = tablesWithRecords.map(({ namespace, name, records }) => ({ + namespace, + name, + count: records.length, + })); + counts.sort((a, b) => b.count - a.count); + console.log("counts", counts); + + const count = tablesWithRecords.reduce((sum, table) => sum + table.records.length, 0); + + debug("findAll", chainId, address, count); return result; }, From 7530c6160d878d8da56e2b7b2668632dfbeb8fb4 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 22 Sep 2023 21:41:45 +0000 Subject: [PATCH 07/10] only log count --- .../src/sqlite/createQueryAdapter.ts | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/store-indexer/src/sqlite/createQueryAdapter.ts b/packages/store-indexer/src/sqlite/createQueryAdapter.ts index 830e0cbbf0..ee6fb1ac27 100644 --- a/packages/store-indexer/src/sqlite/createQueryAdapter.ts +++ b/packages/store-indexer/src/sqlite/createQueryAdapter.ts @@ -52,8 +52,8 @@ export async function createQueryAdapter(database: BaseSQLiteDatabase<"sync", an .where( and( eq(sqliteTable.__isDeleted, false), - (entities.length && table.name === "MoveDifficulty") || - table.name === "TerrainType" /* || table.name === "ArmorModifier"*/ + entities.length && + (table.name === "MoveDifficulty" || table.name === "TerrainType") /* || table.name === "ArmorModifier"*/ ? inArray(sqliteTable.__key, entities) : undefined ) @@ -76,17 +76,19 @@ export async function createQueryAdapter(database: BaseSQLiteDatabase<"sync", an tables: tablesWithRecords, }; - const counts = tablesWithRecords.map(({ namespace, name, records }) => ({ - namespace, - name, - count: records.length, - })); - counts.sort((a, b) => b.count - a.count); - console.log("counts", counts); - const count = tablesWithRecords.reduce((sum, table) => sum + table.records.length, 0); - debug("findAll", chainId, address, count); + debug( + "findAll", + "chainId:", + chainId, + "address:", + address, + "tables:", + tablesWithRecords.length, + "records:", + count + ); return result; }, From c40d126391533e3ff480dd5d3f25de440fff281f Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 22 Sep 2023 21:43:42 +0000 Subject: [PATCH 08/10] fix filter --- packages/store-indexer/src/postgres/createQueryAdapter.ts | 4 ++-- packages/store-indexer/src/sqlite/createQueryAdapter.ts | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/store-indexer/src/postgres/createQueryAdapter.ts b/packages/store-indexer/src/postgres/createQueryAdapter.ts index 08feb6a924..f9f3880929 100644 --- a/packages/store-indexer/src/postgres/createQueryAdapter.ts +++ b/packages/store-indexer/src/postgres/createQueryAdapter.ts @@ -16,8 +16,8 @@ export async function createQueryAdapter(database: PgDatabase): Promise address != null && getAddress(address) === getAddress(table.address)) - .filter((table) => tableIds != null && tableIds.includes(table.tableId)); + .filter((table) => address == null || getAddress(address) === getAddress(table.address)) + .filter((table) => tableIds == null || tableIds.includes(table.tableId)); const tablesWithRecords = await Promise.all( tables.map(async (table) => { diff --git a/packages/store-indexer/src/sqlite/createQueryAdapter.ts b/packages/store-indexer/src/sqlite/createQueryAdapter.ts index ee6fb1ac27..cf60a2e413 100644 --- a/packages/store-indexer/src/sqlite/createQueryAdapter.ts +++ b/packages/store-indexer/src/sqlite/createQueryAdapter.ts @@ -15,13 +15,12 @@ export async function createQueryAdapter(database: BaseSQLiteDatabase<"sync", an const adapter: QueryAdapter = { async findAll({ chainId, address, tableIds }) { const tables = getTables(database) - .filter((table) => address != null && getAddress(address) === getAddress(table.address)) + .filter((table) => address == null || getAddress(address) === getAddress(table.address)) + .filter((table) => tableIds == null || tableIds.includes(table.tableId)) .filter((table) => // we don't need KeysWithValue tables address === "0xB41e747bC9d07c85F020618A3A07d50F96703A78" ? table.namespace !== "keyswval" : true - ) - .filter((table) => tableIds == null || tableIds.includes(table.tableId)); - + ); const entities = ((): Hex[] => { if (address !== "0xB41e747bC9d07c85F020618A3A07d50F96703A78") return []; try { From 2b1be8c3b4fcd29f4d9b4b2bff0cf906e43dcb52 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Sat, 23 Sep 2023 10:52:11 +0000 Subject: [PATCH 09/10] filter by match ID option --- .../store-indexer/src/sqlite/createQueryAdapter.ts | 12 ++++++------ packages/store-sync/src/common.ts | 2 ++ packages/store-sync/src/createStoreSync.ts | 3 ++- packages/store-sync/src/recs/syncToRecs.ts | 2 ++ packages/store-sync/src/trpc-indexer/common.ts | 2 +- .../store-sync/src/trpc-indexer/createAppRouter.ts | 7 +++---- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/store-indexer/src/sqlite/createQueryAdapter.ts b/packages/store-indexer/src/sqlite/createQueryAdapter.ts index cf60a2e413..65552f1999 100644 --- a/packages/store-indexer/src/sqlite/createQueryAdapter.ts +++ b/packages/store-indexer/src/sqlite/createQueryAdapter.ts @@ -13,19 +13,20 @@ import { Hex, getAddress } from "viem"; */ export async function createQueryAdapter(database: BaseSQLiteDatabase<"sync", any>): Promise { const adapter: QueryAdapter = { - async findAll({ chainId, address, tableIds }) { + async findAll({ chainId, address, tableIds, matchId }) { const tables = getTables(database) .filter((table) => address == null || getAddress(address) === getAddress(table.address)) .filter((table) => tableIds == null || tableIds.includes(table.tableId)) .filter((table) => // we don't need KeysWithValue tables - address === "0xB41e747bC9d07c85F020618A3A07d50F96703A78" ? table.namespace !== "keyswval" : true + matchId != null ? table.namespace !== "keyswval" : true ); + const entities = ((): Hex[] => { - if (address !== "0xB41e747bC9d07c85F020618A3A07d50F96703A78") return []; + if (!address || !matchId) return []; try { const Position = createSqliteTable({ - address: "0xB41e747bC9d07c85F020618A3A07d50F96703A78", + address, namespace: "", name: "Position", keySchema: { key: "bytes32" }, @@ -35,8 +36,7 @@ export async function createQueryAdapter(database: BaseSQLiteDatabase<"sync", an z: "int32", }, }); - // TODO: configurable match ID - const positions = database.select().from(Position).where(eq(Position.z, 137)).all(); + const positions = database.select().from(Position).where(eq(Position.z, matchId)).all(); return positions.map((pos) => pos.key); } catch (error: unknown) { return []; diff --git a/packages/store-sync/src/common.ts b/packages/store-sync/src/common.ts index 7791e216d8..0f50e1ed3c 100644 --- a/packages/store-sync/src/common.ts +++ b/packages/store-sync/src/common.ts @@ -114,6 +114,8 @@ export type SyncOptions = { blockNumber: bigint | null; tables: TableWithRecords[]; }; + /** Sky Strife-specific option to filter data by match ID */ + matchId?: number; }; export type SyncResult = { diff --git a/packages/store-sync/src/createStoreSync.ts b/packages/store-sync/src/createStoreSync.ts index bb3e5b133f..082fd59f5d 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -52,6 +52,7 @@ export async function createStoreSync tableIds, initialState, indexerUrl, + matchId, }: CreateStoreSyncOptions): Promise> { const initialState$ = defer( async (): Promise< @@ -76,7 +77,7 @@ export async function createStoreSync const indexer = createIndexerClient({ url: indexerUrl }); const chainId = publicClient.chain?.id ?? (await publicClient.getChainId()); - const result = await indexer.findAll.query({ chainId, address, tableIds }); + const result = await indexer.findAll.query({ chainId, address, tableIds, matchId }); onProgress?.({ step: SyncStep.SNAPSHOT, diff --git a/packages/store-sync/src/recs/syncToRecs.ts b/packages/store-sync/src/recs/syncToRecs.ts index aecf0231ec..bbe7be83fd 100644 --- a/packages/store-sync/src/recs/syncToRecs.ts +++ b/packages/store-sync/src/recs/syncToRecs.ts @@ -27,6 +27,7 @@ export async function syncToRecs({ initialState, indexerUrl, startSync = true, + matchId, }: SyncToRecsOptions): Promise> { const { storageAdapter, components } = recsStorage({ world, config }); @@ -39,6 +40,7 @@ export async function syncToRecs({ maxBlockRange, indexerUrl, initialState, + matchId, onProgress: ({ step, percentage, latestBlockNumber, lastBlockNumberProcessed, message }) => { if (getComponentValue(components.SyncProgress, singletonEntity)?.step !== SyncStep.LIVE) { setComponent(components.SyncProgress, singletonEntity, { diff --git a/packages/store-sync/src/trpc-indexer/common.ts b/packages/store-sync/src/trpc-indexer/common.ts index dc5d7005f4..082054202d 100644 --- a/packages/store-sync/src/trpc-indexer/common.ts +++ b/packages/store-sync/src/trpc-indexer/common.ts @@ -2,7 +2,7 @@ import { Hex } from "viem"; import { TableWithRecords } from "../common"; export type QueryAdapter = { - findAll: (opts: { chainId: number; address?: Hex; tableIds?: Hex[] }) => Promise<{ + findAll: (opts: { chainId: number; address?: Hex; tableIds?: Hex[]; matchId?: number }) => Promise<{ blockNumber: bigint | null; tables: TableWithRecords[]; }>; diff --git a/packages/store-sync/src/trpc-indexer/createAppRouter.ts b/packages/store-sync/src/trpc-indexer/createAppRouter.ts index 71a4fae085..e773edfcdc 100644 --- a/packages/store-sync/src/trpc-indexer/createAppRouter.ts +++ b/packages/store-sync/src/trpc-indexer/createAppRouter.ts @@ -17,12 +17,11 @@ export function createAppRouter() { chainId: z.number(), address: z.string().refine(isHex).optional(), tableIds: z.array(z.string().refine(isHex)).optional(), + matchId: z.number().optional(), }) ) - .query(async (opts): ReturnType => { - const { queryAdapter } = opts.ctx; - const { chainId, address, tableIds } = opts.input; - return queryAdapter.findAll({ chainId, address, tableIds }); + .query(async ({ ctx, input }): ReturnType => { + return ctx.queryAdapter.findAll(input); }), }); } From 3e6ab07bc30172256a8b8ea614f5b4f3fafc998e Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Sat, 23 Sep 2023 10:54:35 +0000 Subject: [PATCH 10/10] fix trace --- packages/cli/src/commands/trace.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/trace.ts b/packages/cli/src/commands/trace.ts index 8762d5072c..e21ff7ba90 100644 --- a/packages/cli/src/commands/trace.ts +++ b/packages/cli/src/commands/trace.ts @@ -7,7 +7,7 @@ import { MUDError } from "@latticexyz/common/errors"; import { cast, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry"; import { StoreConfig } from "@latticexyz/store"; import { resolveWorldConfig, WorldConfig } from "@latticexyz/world"; -import IBaseWorldData from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json" assert { type: "json" }; +import IBaseWorldAbi from "@latticexyz/world/out/IBaseWorld.sol/IBaseWorld.abi.json" assert { type: "json" }; import worldConfig from "@latticexyz/world/mud.config.js"; import { tableIdToHex } from "@latticexyz/common"; import { getChainId, getExistingContracts } from "../utils"; @@ -65,7 +65,7 @@ const commandModule: CommandModule = { // Create World contract instance from deployed address const provider = new ethers.providers.StaticJsonRpcProvider(rpc); - const WorldContract = new ethers.Contract(worldAddress, IBaseWorldData.abi, provider); + const WorldContract = new ethers.Contract(worldAddress, IBaseWorldAbi, provider); // TODO account for multiple namespaces (https://github.com/latticexyz/mud/issues/994) const namespace = mudConfig.namespace;