-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'y77cao/devtool-replace-callfrom' of https://github.com/…
…latticexyz/mud into y77cao/devtool-replace-callfrom
- Loading branch information
Showing
298 changed files
with
12,272 additions
and
5,805 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.