Skip to content

Commit

Permalink
Merge branch 'y77cao/devtool-replace-callfrom' of https://github.com/…
Browse files Browse the repository at this point in the history
…latticexyz/mud into y77cao/devtool-replace-callfrom
  • Loading branch information
y77cao committed Sep 18, 2023
2 parents 044e4d7 + d5ba6f0 commit 8d86eb6
Show file tree
Hide file tree
Showing 298 changed files with 12,272 additions and 5,805 deletions.
23 changes: 23 additions & 0 deletions .changeset/chilled-cougars-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
"@latticexyz/faucet": minor
---

New package to run your own faucet service. We'll use this soon for our testnet in place of `@latticexyz/services`.

To run the faucet server:

- Add the package with `pnpm add @latticexyz/faucet`
- Add a `.env` file that has a `RPC_HTTP_URL` and `FAUCET_PRIVATE_KEY` (or pass the environment variables into the next command)
- Run `pnpm faucet-server` to start the server

You can also adjust the server's `HOST` (defaults to `0.0.0.0`) and `PORT` (defaults to `3002`). The tRPC routes are accessible under `/trpc`.

To connect a tRPC client, add the package with `pnpm add @latticexyz/faucet` and then use `createClient`:

```ts
import { createClient } from "@latticexyz/faucet";

const faucet = createClient({ url: "http://localhost:3002/trpc" });

await faucet.mutate.drip({ address: burnerAccount.address });
```
5 changes: 5 additions & 0 deletions .changeset/chilled-kangaroos-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-indexer": patch
---

Fixes postgres indexer stopping sync after it catches up to the latest block.
30 changes: 30 additions & 0 deletions .changeset/cyan-hats-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
"@latticexyz/store": major
"@latticexyz/world": major
---

We've updated Store events to be "schemaless", meaning there is enough information in each event to only need to operate on the bytes of each record to make an update to that record without having to first decode the record by its schema. This enables new kinds of indexers and sync strategies.

If you've written your own sync logic or are interacting with Store calls directly, this is a breaking change. We have a few more breaking protocol changes upcoming, so you may hold off on upgrading until those land.

If you are using MUD's built-in tooling (table codegen, indexer, store sync, etc.), you don't have to make any changes except upgrading to the latest versions and deploying a fresh World.

- The `data` field in each `StoreSetRecord` and `StoreEphemeralRecord` has been replaced with three new fields: `staticData`, `encodedLengths`, and `dynamicData`. This better reflects the on-chain state and makes it easier to perform modifications to the raw bytes. We recommend storing each of these fields individually in your off-chain storage of choice (indexer, client, etc.).

```diff
- event StoreSetRecord(bytes32 tableId, bytes32[] keyTuple, bytes data);
+ event StoreSetRecord(bytes32 tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData);

- event StoreEphemeralRecord(bytes32 tableId, bytes32[] keyTuple, bytes data);
+ event StoreEphemeralRecord(bytes32 tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData);
```

- The `StoreSetField` event is now replaced by two new events: `StoreSpliceStaticData` and `StoreSpliceDynamicData`. Splicing allows us to perform efficient operations like push and pop, in addition to replacing a field value. We use two events because updating a dynamic-length field also requires updating the record's `encodedLengths` (aka PackedCounter).

```diff
- event StoreSetField(bytes32 tableId, bytes32[] keyTuple, uint8 fieldIndex, bytes data);
+ event StoreSpliceStaticData(bytes32 tableId, bytes32[] keyTuple, uint48 start, uint40 deleteCount, bytes data);
+ event StoreSpliceDynamicData(bytes32 tableId, bytes32[] keyTuple, uint48 start, uint40 deleteCount, bytes data, bytes32 encodedLengths);
```

Similarly, Store setter methods (e.g. `setRecord`) have been updated to reflect the `data` to `staticData`, `encodedLengths`, and `dynamicData` changes. We'll be following up shortly with Store getter method changes for more gas efficient storage reads.
6 changes: 6 additions & 0 deletions .changeset/fast-zebras-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@latticexyz/common": minor
"@latticexyz/protocol-parser": major
---

`readHex` was moved from `@latticexyz/protocol-parser` to `@latticexyz/common`
42 changes: 42 additions & 0 deletions .changeset/few-jars-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
"@latticexyz/store": major
"@latticexyz/world": major
---

Moved the registration of store hooks and systems hooks to bitmaps with bitwise operator instead of a struct.

```diff
- import { StoreHookLib } from "@latticexyz/src/StoreHook.sol";
+ import {
+ BEFORE_SET_RECORD,
+ BEFORE_SET_FIELD,
+ BEFORE_DELETE_RECORD
+ } from "@latticexyz/store/storeHookTypes.sol";

StoreCore.registerStoreHook(
tableId,
subscriber,
- StoreHookLib.encodeBitmap({
- onBeforeSetRecord: true,
- onAfterSetRecord: false,
- onBeforeSetField: true,
- onAfterSetField: false,
- onBeforeDeleteRecord: true,
- onAfterDeleteRecord: false
- })
+ BEFORE_SET_RECORD | BEFORE_SET_FIELD | BEFORE_DELETE_RECORD
);
```

```diff
- import { SystemHookLib } from "../src/SystemHook.sol";
+ import { BEFORE_CALL_SYSTEM, AFTER_CALL_SYSTEM } from "../src/systemHookTypes.sol";

world.registerSystemHook(
systemId,
subscriber,
- SystemHookLib.encodeBitmap({ onBeforeCallSystem: true, onAfterCallSystem: true })
+ BEFORE_CALL_SYSTEM | AFTER_CALL_SYSTEM
);

```
8 changes: 8 additions & 0 deletions .changeset/hot-mice-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@latticexyz/cli": patch
"@latticexyz/store": patch
"@latticexyz/world": patch
---

The `FieldLayout` in table libraries is now generated at compile time instead of dynamically in a table library function.
This significantly reduces gas cost in all table library functions.
5 changes: 5 additions & 0 deletions .changeset/hungry-rings-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store": patch
---

Added `Storage.loadField` to optimize loading 32 bytes or less from storage (which is always the case when loading data for static fields).
5 changes: 5 additions & 0 deletions .changeset/lovely-fireants-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/world": patch
---

Renamed all `funcSelectorAndArgs` arguments to `callData` for clarity.
25 changes: 25 additions & 0 deletions .changeset/proud-insects-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
"@latticexyz/store-indexer": minor
---

You can now install and run `@latticexyz/store-indexer` from the npm package itself, without having to clone/build the MUD repo:

```sh
npm install @latticexyz/store-indexer

npm sqlite-indexer
# or
npm postgres-indexer
```

or

```sh
npx -p @latticexyz/store-indexer sqlite-indexer
# or
npx -p @latticexyz/store-indexer postgres-indexer
```

The binary will also load the nearby `.env` file for easier local configuration.

We've removed the `CHAIN_ID` requirement and instead require just a `RPC_HTTP_URL` or `RPC_WS_URL` or both. You can now also adjust the polling interval with `POLLING_INTERVAL` (defaults to 1000ms, which corresponds to MUD's default block time).
9 changes: 9 additions & 0 deletions .changeset/rotten-cats-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@latticexyz/common": minor
---

`spliceHex` was added, which has a similar API as JavaScript's [`Array.prototype.splice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice), but for `Hex` strings.

```ts
spliceHex("0x123456", 1, 1, "0x0000"); // "0x12000056"
```
6 changes: 6 additions & 0 deletions .changeset/short-dragons-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@latticexyz/store": patch
"@latticexyz/world": patch
---

Optimized the `StoreCore` hash function determining the data location to use less gas.
29 changes: 29 additions & 0 deletions .changeset/shy-monkeys-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
"@latticexyz/cli": major
"@latticexyz/store": major
"create-mud": patch
---

Renamed the default filename of generated user types from `Types.sol` to `common.sol` and the default filename of the generated table index file from `Tables.sol` to `index.sol`.

Both can be overridden via the MUD config:

```ts
export default mudConfig({
/** Filename where common user types will be generated and imported from. */
userTypesFilename: "common.sol",
/** Filename where codegen index will be generated. */
codegenIndexFilename: "index.sol",
});
```

Note: `userTypesFilename` was renamed from `userTypesPath` and `.sol` is not appended automatically anymore but needs to be part of the provided filename.

To update your existing project, update all imports from `Tables.sol` to `index.sol` and all imports from `Types.sol` to `common.sol`, or override the defaults in your MUD config to the previous values.

```diff
- import { Counter } from "../src/codegen/Tables.sol";
+ import { Counter } from "../src/codegen/index.sol";
- import { ExampleEnum } from "../src/codegen/Types.sol";
+ import { ExampleEnum } from "../src/codegen/common.sol";
```
9 changes: 9 additions & 0 deletions .changeset/shy-sheep-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@latticexyz/dev-tools": major
"@latticexyz/store-sync": major
"create-mud": minor
---

We've updated Store events to be "schemaless", meaning there is enough information in each event to only need to operate on the bytes of each record to make an update to that record without having to first decode the record by its schema. This enables new kinds of indexers and sync strategies.

As such, we've replaced `blockStorageOperations$` with `storedBlockLogs$`, a stream of simplified Store event logs after they've been synced to the configured storage adapter. These logs may not reflect exactly the events that are on chain when e.g. hydrating from an indexer, but they will still allow the client to "catch up" to the on-chain state of your tables.
16 changes: 16 additions & 0 deletions .changeset/soft-fans-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@latticexyz/store": minor
"@latticexyz/world": minor
---

Add protocol version with corresponding getter and event on deploy

```solidity
world.worldVersion();
world.storeVersion(); // a World is also a Store
```

```solidity
event HelloWorld(bytes32 indexed worldVersion);
event HelloStore(bytes32 indexed storeVersion);
```
34 changes: 34 additions & 0 deletions .changeset/sour-cycles-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
"@latticexyz/cli": patch
"@latticexyz/store": minor
"@latticexyz/world": patch
---

`StoreCore` and `IStore` now expose specific functions for `getStaticField` and `getDynamicField` in addition to the general `getField`.
Using the specific functions reduces gas overhead because more optimized logic can be executed.

```solidity
interface IStore {
/**
* Get a single static field from the given tableId and key tuple, with the given value field layout.
* Note: the field value is left-aligned in the returned bytes32, the rest of the word is not zeroed out.
* Consumers are expected to truncate the returned value as needed.
*/
function getStaticField(
bytes32 tableId,
bytes32[] calldata keyTuple,
uint8 fieldIndex,
FieldLayout fieldLayout
) external view returns (bytes32);
/**
* Get a single dynamic field from the given tableId and key tuple at the given dynamic field index.
* (Dynamic field index = field index - number of static fields)
*/
function getDynamicField(
bytes32 tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex
) external view returns (bytes memory);
}
```
5 changes: 5 additions & 0 deletions .changeset/stale-worms-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store": major
---

Store events now use an `indexed` `tableId`. This adds ~100 gas per write, but means we our sync stack can filter events by table.
23 changes: 23 additions & 0 deletions .changeset/thin-terms-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
"@latticexyz/cli": patch
"@latticexyz/common": minor
"@latticexyz/store": minor
"@latticexyz/world": patch
---

Generated table libraries now have a set of functions prefixed with `_` that always use their own storage for read/write.
This saves gas for use cases where the functionality to dynamically determine which `Store` to use for read/write is not needed, e.g. root systems in a `World`, or when using `Store` without `World`.

We decided to continue to always generate a set of functions that dynamically decide which `Store` to use, so that the generated table libraries can still be imported by non-root systems.

```solidity
library Counter {
// Dynamically determine which store to write to based on the context
function set(uint32 value) internal;
// Always write to own storage
function _set(uint32 value) internal;
// ... equivalent functions for all other Store methods
}
```
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# suppress diffs for codegen in PRs
**/codegen/**/*.sol linguist-generated=true
**/test-data/**/*.json linguist-generated=true
9 changes: 2 additions & 7 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
name: Docker

on:
push:
branches:
- main
tags:
# only target a single package tag to avoid running this task for every package on a version release
# in the metadata step, we parse out the specific version used in the tag (e.g. `2.0.0-next.5` and `next`)
- "@latticexyz/common@*"
workflow_call:
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -37,6 +31,7 @@ jobs:
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
# If this doesn't tag properly within the context of `workflow_call`, try `context: git`
images: ${{ matrix.image }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Check for pre.json file existence
id: check_files
uses: andstor/[email protected]
Expand All @@ -47,10 +47,13 @@ jobs:
run: npx changeset pre enter next

- name: Create next version PR or publish 🚀
uses: changesets/action@v1
uses: changesets/action@v1
with:
version: pnpm release:version
publish: pnpm release:publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker:
uses: ./.github/workflows/docker.yml
needs: prerelease
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- name: "Setup"
uses: ./.github/actions/setup

- name: Clean
shell: bash
run: pnpm turbo run clean --force --concurrency 10
Expand Down Expand Up @@ -60,3 +60,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

docker:
uses: ./.github/workflows/docker.yml
needs: version
4 changes: 4 additions & 0 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

docker:
uses: ./.github/workflows/docker.yml
needs: release-snapshot
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ RUN pnpm run -r build
FROM mud AS store-indexer
WORKDIR /app/packages/store-indexer
EXPOSE 3001

FROM mud AS faucet
WORKDIR /app/packages/faucet
EXPOSE 3002
Loading

0 comments on commit 8d86eb6

Please sign in to comment.