Skip to content

Commit

Permalink
remove snap sync module
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs committed Aug 15, 2023
1 parent bbf9745 commit 4a7d282
Show file tree
Hide file tree
Showing 20 changed files with 2 additions and 711 deletions.
34 changes: 1 addition & 33 deletions docs/pages/world/modules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function spawnSoldier() public {

### Querying modules

The `KeysInTableModule` and `KeysWithValueModule` modules index information about tables on-chain. Their functionality is leveraged in `SnapSyncModule` and `query` to allow on-chain querying.
The `KeysInTableModule` and `KeysWithValueModule` modules index information about tables on-chain. Their functionality is leveraged in `query` to allow on-chain querying.

#### **`KeysInTableModule`**

Expand Down Expand Up @@ -111,38 +111,6 @@ bytes32[] memory keysWithValue = getKeysWithValue(world, OwnersId, Owners.encode

Internally, it works by installing a [hook](/store/advanced-features#storage-hooks) that maintains an array of all keys in the table.

#### **`SnapSyncModule`**

The [`SnapSyncModule`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/snapsync/SnapSyncModule.sol) installs a [System](/world/world-101#systems) that returns all records in a given table, with offset-based pagination. It requires the `KeysInTable` module to be installed on each table, but the [`SnapSync` plugin](/world/snap-sync) does this automatically.

`SnapSyncSystem` exposes two public `view` functions:

- `getRecords(bytes32 tableId, uint256 limit, uint256 offset)` returns all keys in a table
- `getNumKeysInTable(bytes32 tableId)` returns the number of keys in a table

Clients can use snap-sync to get all records on the World, then begin syncing regularly from the current block:

```tsx
import { getSnapSyncRecords } from "@latticexyz/network";
import { getTableIds } from "@latticexyz/common/deprecated";

...

if (networkConfig.snapSync) {
const currentBlockNumber = await provider.getBlockNumber();
const tableRecords = await getSnapSyncRecords(
networkConfig.worldAddress,
getTableIds(storeConfig),
currentBlockNumber,
signerOrProvider
);

result.startSync(tableRecords, currentBlockNumber);
} else {
result.startSync();
}
```

#### **`query`**

`query` provides a simple API to get a list of keys matching certain specified criteria. It is not a standalone module, but requires `KeysInTable` and `KeysWithValue` to be installed.
Expand Down
144 changes: 0 additions & 144 deletions docs/pages/world/snap-sync.mdx

This file was deleted.

9 changes: 0 additions & 9 deletions examples/minimal/packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { mudConfig } from "@latticexyz/world/register";

/**
* Importing this enables "snap sync mode".
* It allows clients to sync the latest state of the world using view functions.
* This is a simple way to quickly sync without the use of an external indexer.
* This could lead to expensive queries on live RPCs if the world is large,
* so we suggest using MODE for production deployments.
*/
import "@latticexyz/world/snapsync";
import { resolveTableId } from "@latticexyz/config";

export default mudConfig({
snapSync: true,
systems: {
IncrementSystem: {
name: "increment",
Expand Down
7 changes: 0 additions & 7 deletions packages/cli/src/utils/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import CoreModuleData from "@latticexyz/world/abi/CoreModule.sol/CoreModule.json
import KeysWithValueModuleData from "@latticexyz/world/abi/KeysWithValueModule.sol/KeysWithValueModule.json" assert { type: "json" };
import KeysInTableModuleData from "@latticexyz/world/abi/KeysInTableModule.sol/KeysInTableModule.json" assert { type: "json" };
import UniqueEntityModuleData from "@latticexyz/world/abi/UniqueEntityModule.sol/UniqueEntityModule.json" assert { type: "json" };
import SnapSyncModuleData from "@latticexyz/world/abi/SnapSyncModule.sol/SnapSyncModule.json" assert { type: "json" };

export interface DeployConfig {
profile?: string;
Expand Down Expand Up @@ -113,12 +112,6 @@ export async function deploy(
disableTxWait,
"UniqueEntityModule"
),
SnapSyncModule: deployContract(
SnapSyncModuleData.abi,
SnapSyncModuleData.bytecode,
disableTxWait,
"SnapSyncModule"
),
};

// Deploy user Modules
Expand Down
1 change: 0 additions & 1 deletion packages/network/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ export * from "./createBlockNumberStream";
export * from "./createFaucetService";
export * from "./utils";
export * from "./createFastTxExecutor";
export * from "./v2/snapSync";
export { keyTupleToEntityID } from "./v2/keyTupleToEntityID";
48 changes: 0 additions & 48 deletions packages/network/src/v2/snapSync/getSnapSyncRecords.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/network/src/v2/snapSync/index.ts

This file was deleted.

69 changes: 0 additions & 69 deletions packages/network/src/v2/snapSync/snapSyncSystemAbi.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/world/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ export default mudConfig({
// (see https://github.com/latticexyz/mud/pull/584)
"UniqueEntitySystem",

"SnapSyncSystem",

// Worldgen currently does not support systems inheriting logic
// from other contracts, so all parts of CoreSystem are named
// System too to be included in the IBaseWorld interface.
Expand Down
4 changes: 0 additions & 4 deletions packages/world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"./node": "./dist/ts/node/index.js",
"./abi/*": "./abi/*",
"./types/*": "./types/*",
"./snapsync": "./dist/ts/plugins/snapsync/index.js",
"./*": "./dist/*"
},
"typesVersions": {
Expand All @@ -28,9 +27,6 @@
],
"node": [
"./ts/node/index.ts"
],
"snapsync": [
"./ts/plugins/snapsync/index.ts"
]
}
},
Expand Down
Loading

0 comments on commit 4a7d282

Please sign in to comment.