Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/store-sync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@
"clean:js": "shx rm -rf dist",
"dev": "tsup --watch",
"lint": "eslint .",
"playground": "DEBUG=mud:* tsx playground/index.ts | tee playground.log",
"playground": "DEBUG=mud:* tsx --expose-gc playground/index.ts | tee playground.log",
"playground:stash": "tsx playground/syncToStash.ts",
"test": "vitest",
"test:ci": "vitest --run"
},
"dependencies": {
"@ark/util": "0.2.2",
"@dust/world": "https://pkg.pr.new/dustproject/dust/@dust/world@4c98455",
"@latticexyz/block-logs-stream": "workspace:*",
"@latticexyz/common": "workspace:*",
"@latticexyz/config": "workspace:*",
Expand Down
64 changes: 60 additions & 4 deletions packages/store-sync/playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { redstone as redstoneBase, garnet as garnetBase } from "@latticexyz/comm
import { createStoreSync } from "../src/createStoreSync";
// import { watchLogs } from "../src/watchLogs";
import { createPublicClient, http } from "viem";
import mudConfig from "@dust/world/mud.config";
import { getSnapshot, TableQuery } from "@latticexyz/store-sync/exports/internal";
import { Table } from "@latticexyz/store/internal";

const redstone = {
...redstoneBase,
Expand All @@ -25,24 +28,77 @@ const chain = chains.redstone;
const address = "0x253eb85B3C953bFE3827CC14a151262482E7189C"; // REDSTONE
// const address: "0x300f19AD7a0D7ec3D7fC09ad0D34425C24ffF08F", // GARNET blockNumber: 19302351

export const tables = pickTables([
"EntityPosition",
"EntityObjectType",
"BaseEntity",
"EntityOrientation",
"EntityFluidLevel",
"Fragment",
"ExploredChunk",
"InventorySlot",
"InventoryBitmap",
"Mass",
"PlayerBed",
"Energy",
"Machine",
"BedPlayer",
"SeedGrowth",
]);

function pickTables<key extends keyof typeof mudConfig.tables>(
tables: key[],
): { [k in key]: (typeof mudConfig.tables)[k] } {
return Object.fromEntries(Object.entries(mudConfig.tables).filter(([key]) => tables.includes(key as never))) as never;
}

const client = createPublicClient({ chain, transport: http() });
const latestBlock = await client.getBlockNumber();
console.log("latestBlock", latestBlock);

function selectAll(table: Table) {
return `select ${Object.keys(table.schema)
.map((key) => `"${key}"`)
.join(", ")} from ${table.name};`;
}

const filters = Object.values(tables).map(
(table) =>
({
table,
toBlock: undefined,
sql: selectAll(table),
}) satisfies TableQuery,
);

console.log("fetching snapshot...", process.memoryUsage());
const snapshot = await getSnapshot({
indexerUrl: "https://dozer.onrender.com",
storeAddress: address,
chainId: chain.id,
filters,
});
console.log("fetched snapshot!", process.memoryUsage());

const result = await createStoreSync({
internal_clientOptions: {
chain,
validateBlockRange: true,
},
address,
// initialBlockLogs: {
// blockNumber: latestBlock - 1000n,
// logs: [],
// },
initialBlockLogs: snapshot.initialBlockLogs,
enableHydrationChunking: false,
storageAdapter: async (block) => {
console.log("storageAdapter", { blockNumber: block.blockNumber, logs: block.logs.length });
console.log("memory storageAdapter", process.memoryUsage());
},
});
if (global.gc) {
global.gc();
} else {
console.warn("No GC hook! Start node with --expose-gc to enable manual garbage collection.");
}
console.log("memory after sync", process.memoryUsage());

// Start sync
result.storedBlockLogs$.subscribe();
Expand Down
Loading
Loading