Skip to content

Commit

Permalink
refactor: remove v1 network package, remove snap sync module, depreca…
Browse files Browse the repository at this point in the history
…te std-client (#1311)
  • Loading branch information
alvrs authored Aug 16, 2023
1 parent 162ca7d commit 331f0d6
Show file tree
Hide file tree
Showing 162 changed files with 300 additions and 8,124 deletions.
7 changes: 7 additions & 0 deletions .changeset/late-geese-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@latticexyz/world": major
---

The `SnapSyncModule` is removed. The recommended way of loading the initial state of a MUD app is via the new [`store-indexer`](https://mud.dev/indexer). Loading state via contract getter functions is not recommended, as it's computationally heavy on the RPC, can't be cached, and is an easy way to shoot yourself in the foot with exploding RPC costs.

The `@latticexyz/network` package was deprecated and is now removed. All consumers should upgrade to the new sync stack from `@latticexyz/store-sync`.
11 changes: 11 additions & 0 deletions .changeset/seven-flies-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@latticexyz/services": major
"create-mud": patch
---

Move `createFaucetService` from `@latticexyz/network` to `@latticexyz/services/faucet`.

```diff
- import { createFaucetService } from "@latticexyz/network";
+ import { createFaucetService } from "@latticexyz/services/faucet";
```
28 changes: 28 additions & 0 deletions .changeset/wild-gorillas-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
"@latticexyz/std-client": major
"@latticexyz/common": minor
"create-mud": patch
---

Deprecate `@latticexyz/std-client` and remove v1 network dependencies.

- `getBurnerWallet` is replaced by `getBurnerPrivateKey` from `@latticexyz/common`. It now returns a `Hex` string instead of an `rxjs` `BehaviorSubject`.

```
- import { getBurnerWallet } from "@latticexyz/std-client";
+ import { getBurnerPrivateKey } from "@latticexyz/common";
- const privateKey = getBurnerWallet().value;
- const privateKey = getBurnerPrivateKey();
```

- All functions from `std-client` that depended on v1 network code are removed (most notably `setupMUDNetwork` and `setupMUDV2Network`). Consumers should upgrade to v2 networking code from `@latticexyz/store-sync`.

- The following functions are removed from `std-client` because they are very use-case specific and depend on deprecated code: `getCurrentTurn`, `getTurnAtTime`, `getGameConfig`, `isUntraversable`, `getPlayerEntity`, `resolveRelationshipChain`, `findEntityWithComponentInRelationshipChain`, `findInRelationshipChain`. Consumers should vendor these functions if they are still needed.

- Remaining exports from `std-client` are moved to `/deprecated`. The package will be removed in a future release (once there are replacements for the deprecated exports).

```diff
- import { ... } from "@latticexyz/std-client";
+ import { ... } from "@latticexyz/std-client/deprecated";
```
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.

2 changes: 0 additions & 2 deletions e2e/packages/client-vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
"@improbable-eng/grpc-web": "^0.15.0",
"@latticexyz/common": "link:../../../packages/common",
"@latticexyz/dev-tools": "link:../../../packages/dev-tools",
"@latticexyz/network": "link:../../../packages/network",
"@latticexyz/recs": "link:../../../packages/recs",
"@latticexyz/schema-type": "link:../../../packages/schema-type",
"@latticexyz/services": "link:../../../packages/services",
"@latticexyz/std-client": "link:../../../packages/std-client",
"@latticexyz/store-sync": "link:../../../packages/store-sync",
"@latticexyz/utils": "link:../../../packages/utils",
"@latticexyz/world": "link:../../../packages/world",
Expand Down
4 changes: 2 additions & 2 deletions e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getBurnerWallet } from "@latticexyz/std-client";
import { getBurnerPrivateKey } from "@latticexyz/common";
import worldsJson from "contracts/worlds.json";
import { supportedChains } from "./supportedChains";

Expand All @@ -24,7 +24,7 @@ export async function getNetworkConfig() {
: world?.blockNumber ?? 0n;

return {
privateKey: params.get("privateKey") ?? getBurnerWallet().value,
privateKey: params.get("privateKey") ?? getBurnerPrivateKey(),
chainId,
chain,
faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl,
Expand Down
2 changes: 1 addition & 1 deletion e2e/packages/client-vanilla/src/mud/setupNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createPublicClient, http, createWalletClient, Hex, parseEther, ClientConfig } from "viem";
import { createFaucetService } from "@latticexyz/network";
import { createFaucetService } from "@latticexyz/services/faucet";
import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
import { getNetworkConfig } from "./getNetworkConfig";
import { world } from "./world";
Expand Down
1 change: 0 additions & 1 deletion e2e/packages/sync-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
},
"devDependencies": {
"@latticexyz/cli": "link:../../../packages/cli",
"@latticexyz/network": "link:../../../packages/network",
"@latticexyz/recs": "link:../../../packages/recs",
"@latticexyz/schema-type": "link:../../../packages/schema-type",
"@latticexyz/store": "link:../../../packages/store",
Expand Down
9 changes: 0 additions & 9 deletions e2e/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions examples/minimal/packages/client-phaser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
"@improbable-eng/grpc-web": "^0.15.0",
"@latticexyz/common": "link:../../../../packages/common",
"@latticexyz/dev-tools": "link:../../../../packages/dev-tools",
"@latticexyz/network": "link:../../../../packages/network",
"@latticexyz/phaserx": "link:../../../../packages/phaserx",
"@latticexyz/react": "link:../../../../packages/react",
"@latticexyz/recs": "link:../../../../packages/recs",
"@latticexyz/schema-type": "link:../../../../packages/schema-type",
"@latticexyz/services": "link:../../../../packages/services",
"@latticexyz/std-client": "link:../../../../packages/std-client",
"@latticexyz/store-sync": "link:../../../../packages/store-sync",
"@latticexyz/utils": "link:../../../../packages/utils",
"@latticexyz/world": "link:../../../../packages/world",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getBurnerWallet } from "@latticexyz/std-client";
import { getBurnerPrivateKey } from "@latticexyz/common";
import worldsJson from "contracts/worlds.json";
import { supportedChains } from "./supportedChains";

Expand All @@ -24,7 +24,7 @@ export async function getNetworkConfig() {
: world?.blockNumber ?? 0n;

return {
privateKey: getBurnerWallet().value,
privateKey: getBurnerPrivateKey(),
chainId,
chain,
faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createPublicClient, fallback, webSocket, http, createWalletClient, Hex, parseEther, ClientConfig } from "viem";
import { createFaucetService } from "@latticexyz/network";
import { createFaucetService } from "@latticexyz/services/faucet";
import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
import { getNetworkConfig } from "./getNetworkConfig";
import { world } from "./world";
Expand Down
2 changes: 0 additions & 2 deletions examples/minimal/packages/client-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
"@improbable-eng/grpc-web": "^0.15.0",
"@latticexyz/common": "link:../../../../packages/common",
"@latticexyz/dev-tools": "link:../../../../packages/dev-tools",
"@latticexyz/network": "link:../../../../packages/network",
"@latticexyz/react": "link:../../../../packages/react",
"@latticexyz/recs": "link:../../../../packages/recs",
"@latticexyz/schema-type": "link:../../../../packages/schema-type",
"@latticexyz/services": "link:../../../../packages/services",
"@latticexyz/std-client": "link:../../../../packages/std-client",
"@latticexyz/store-sync": "link:../../../../packages/store-sync",
"@latticexyz/utils": "link:../../../../packages/utils",
"@latticexyz/world": "link:../../../../packages/world",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getBurnerWallet } from "@latticexyz/std-client";
import { getBurnerPrivateKey } from "@latticexyz/common";
import worldsJson from "contracts/worlds.json";
import { supportedChains } from "./supportedChains";

Expand All @@ -24,7 +24,7 @@ export async function getNetworkConfig() {
: world?.blockNumber ?? 0n;

return {
privateKey: getBurnerWallet().value,
privateKey: getBurnerPrivateKey(),
chainId,
chain,
faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createPublicClient, fallback, webSocket, http, createWalletClient, Hex, parseEther, ClientConfig } from "viem";
import { createFaucetService } from "@latticexyz/network";
import { createFaucetService } from "@latticexyz/services/faucet";
import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
import { getNetworkConfig } from "./getNetworkConfig";
import { world } from "./world";
Expand Down
2 changes: 0 additions & 2 deletions examples/minimal/packages/client-vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
"@improbable-eng/grpc-web": "^0.15.0",
"@latticexyz/common": "link:../../../../packages/common",
"@latticexyz/dev-tools": "link:../../../../packages/dev-tools",
"@latticexyz/network": "link:../../../../packages/network",
"@latticexyz/recs": "link:../../../../packages/recs",
"@latticexyz/schema-type": "link:../../../../packages/schema-type",
"@latticexyz/services": "link:../../../../packages/services",
"@latticexyz/std-client": "link:../../../../packages/std-client",
"@latticexyz/store-sync": "link:../../../../packages/store-sync",
"@latticexyz/utils": "link:../../../../packages/utils",
"@latticexyz/world": "link:../../../../packages/world",
Expand Down
Loading

0 comments on commit 331f0d6

Please sign in to comment.