Skip to content

Commit

Permalink
Merge branch 'main' into 230905-client-libs
Browse files Browse the repository at this point in the history
  • Loading branch information
qbzzt authored Sep 6, 2023
2 parents ea20b3c + b2fc830 commit 2f3ad39
Show file tree
Hide file tree
Showing 75 changed files with 830 additions and 94 deletions.
14 changes: 14 additions & 0 deletions .changeset/beige-radios-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@latticexyz/world": minor
---

It is now possible to upgrade systems by calling `registerSystem` again with an existing system id (resource selector).

```solidity
// Register a system
world.registerSystem(systemId, systemAddress, publicAccess);
// Upgrade the system by calling `registerSystem` with the
// same system id but a new system address or publicAccess flag
world.registerSystem(systemId, newSystemAddress, newPublicAccess);
```
5 changes: 5 additions & 0 deletions .changeset/funny-paws-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/services": patch
---

The build phase of services now works on machines with older protobuf compilers
9 changes: 8 additions & 1 deletion .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
},
"changesets": [
"afraid-hotels-bathe",
"beige-radios-drop",
"big-goats-prove",
"brave-needles-love",
"brave-rings-tickle",
"brown-icons-burn",
"chilled-chicken-repair",
"clever-rats-sip",
"cool-snakes-reply",
"dirty-items-retire",
"eighty-tigers-argue",
Expand All @@ -48,6 +50,7 @@
"flat-trainers-marry",
"fluffy-moles-march",
"four-coats-pull",
"funny-paws-admire",
"giant-masks-carry",
"great-cooks-dream",
"grumpy-geckos-raise",
Expand All @@ -67,6 +70,7 @@
"modern-bikes-build",
"modern-hornets-jam",
"nasty-waves-divide",
"nervous-walls-knock",
"nice-moose-love",
"nice-pandas-knock",
"olive-parrots-move",
Expand All @@ -75,7 +79,9 @@
"pink-horses-deny",
"pretty-hotels-drop",
"quick-numbers-flash",
"quiet-squids-share",
"rare-planes-draw",
"rare-trainers-fry",
"red-turkeys-develop",
"selfish-cycles-retire",
"seven-flies-chew",
Expand All @@ -100,6 +106,7 @@
"twenty-birds-scream",
"weak-mails-cross",
"wild-gorillas-care",
"witty-jokes-serve"
"witty-jokes-serve",
"witty-tigers-rest"
]
}
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules
**/node_modules
.gitignore
*.md
dist
**/dist
**/out/
**/cache/
**/bindings/
**/artifacts/
**/abi/
**/broadcast/
**/deploys/
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ jobs:
env:
DATABASE_URL: "postgres://postgres@localhost:5432/postgres"
working-directory: ./e2e/packages/sync-test
run: pnpm test
run: pnpm test:ci
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Run tests
env:
DATABASE_URL: "postgres://postgres@localhost:5432/postgres"
run: pnpm test
run: pnpm test:ci

- name: Generate gas reports
run: pnpm gas-report
Expand Down
219 changes: 219 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,222 @@
# Version 2.0.0-next.5

## Major changes

**[refactor(world): separate call utils into `WorldContextProvider` and `SystemCall` (#1370)](https://github.com/latticexyz/mud/commit/9d0f492a90e5d94c6b38ad732e78fd4b13b2adbe)** (@latticexyz/world)

- The previous `Call.withSender` util is replaced with `WorldContextProvider`, since the usecase of appending the `msg.sender` to the calldata is tightly coupled with `WorldContextConsumer` (which extracts the appended context from the calldata).

The previous `Call.withSender` utility reverted if the call failed and only returned the returndata on success. This is replaced with `callWithContextOrRevert`/`delegatecallWithContextOrRevert`

```diff
-import { Call } from "@latticexyz/world/src/Call.sol";
+import { WorldContextProvider } from "@latticexyz/world/src/WorldContext.sol";

-Call.withSender({
- delegate: false,
- value: 0,
- ...
-});
+WorldContextProvider.callWithContextOrRevert({
+ value: 0,
+ ...
+});

-Call.withSender({
- delegate: true,
- value: 0,
- ...
-});
+WorldContextProvider.delegatecallWithContextOrRevert({
+ ...
+});
```

In addition there are utils that return a `bool success` flag instead of reverting on errors. This mirrors the behavior of Solidity's low level `call`/`delegatecall` functions and is useful in situations where additional logic should be executed in case of a reverting external call.

```solidity
library WorldContextProvider {
function callWithContext(
address target, // Address to call
bytes memory funcSelectorAndArgs, // Abi encoded function selector and arguments to pass to pass to the contract
address msgSender, // Address to append to the calldata as context for msgSender
uint256 value // Value to pass with the call
) internal returns (bool success, bytes memory data);
function delegatecallWithContext(
address target, // Address to call
bytes memory funcSelectorAndArgs, // Abi encoded function selector and arguments to pass to pass to the contract
address msgSender // Address to append to the calldata as context for msgSender
) internal returns (bool success, bytes memory data);
}
```

- `WorldContext` is renamed to `WorldContextConsumer` to clarify the relationship between `WorldContextProvider` (appending context to the calldata) and `WorldContextConsumer` (extracting context from the calldata)

```diff
-import { WorldContext } from "@latticexyz/world/src/WorldContext.sol";
-import { WorldContextConsumer } from "@latticexyz/world/src/WorldContext.sol";
```

- The `World` contract previously had a `_call` method to handle calling systems via their resource selector, performing accesss control checks and call hooks registered for the system.

```solidity
library SystemCall {
/**
* Calls a system via its resource selector and perform access control checks.
* Does not revert if the call fails, but returns a `success` flag along with the returndata.
*/
function call(
address caller,
bytes32 resourceSelector,
bytes memory funcSelectorAndArgs,
uint256 value
) internal returns (bool success, bytes memory data);
/**
* Calls a system via its resource selector, perform access control checks and trigger hooks registered for the system.
* Does not revert if the call fails, but returns a `success` flag along with the returndata.
*/
function callWithHooks(
address caller,
bytes32 resourceSelector,
bytes memory funcSelectorAndArgs,
uint256 value
) internal returns (bool success, bytes memory data);
/**
* Calls a system via its resource selector, perform access control checks and trigger hooks registered for the system.
* Reverts if the call fails.
*/
function callWithHooksOrRevert(
address caller,
bytes32 resourceSelector,
bytes memory funcSelectorAndArgs,
uint256 value
) internal returns (bytes memory data);
}
```

- System hooks now are called with the system's resource selector instead of its address. The system's address can still easily obtained within the hook via `Systems.get(resourceSelector)` if necessary.

```diff
interface ISystemHook {
function onBeforeCallSystem(
address msgSender,
- address systemAddress,
+ bytes32 resourceSelector,
bytes memory funcSelectorAndArgs
) external;

function onAfterCallSystem(
address msgSender,
- address systemAddress,
+ bytes32 resourceSelector,
bytes memory funcSelectorAndArgs
) external;
}
```

## Minor changes

**[feat(world): add support for upgrading systems (#1378)](https://github.com/latticexyz/mud/commit/ce97426c0d70832e5efdb8bad83207a9d840302b)** (@latticexyz/world)

It is now possible to upgrade systems by calling `registerSystem` again with an existing system id (resource selector).

```solidity
// Register a system
world.registerSystem(systemId, systemAddress, publicAccess);
// Upgrade the system by calling `registerSystem` with the
// same system id but a new system address or publicAccess flag
world.registerSystem(systemId, newSystemAddress, newPublicAccess);
```

**[feat(world): add callFrom entry point (#1364)](https://github.com/latticexyz/mud/commit/1ca35e9a1630a51dfd1e082c26399f76f2cd06ed)** (@latticexyz/world)

The `World` has a new `callFrom` entry point which allows systems to be called on behalf of other addresses if those addresses have registered a delegation.
If there is a delegation, the call is forwarded to the system with `delegator` as `msgSender`.

```solidity
interface IBaseWorld {
function callFrom(
address delegator,
bytes32 resourceSelector,
bytes memory funcSelectorAndArgs
) external payable virtual returns (bytes memory);
}
```

A delegation can be registered via the `World`'s `registerDelegation` function.
If `delegatee` is `address(0)`, the delegation is considered to be a "fallback" delegation and is used in `callFrom` if there is no delegation is found for the specific caller.
Otherwise the delegation is registered for the specific `delegatee`.

```solidity
interface IBaseWorld {
function registerDelegation(
address delegatee,
bytes32 delegationControl,
bytes memory initFuncSelectorAndArgs
) external;
}
```

The `delegationControl` refers to the resource selector of a `DelegationControl` system that must have been registered beforehand.
As part of registering the delegation, the `DelegationControl` system is called with the provided `initFuncSelectorAndArgs`.
This can be used to initialize data in the given `DelegationControl` system.

The `DelegationControl` system must implement the `IDelegationControl` interface:

```solidity
interface IDelegationControl {
function verify(address delegator, bytes32 systemId, bytes calldata funcSelectorAndArgs) external returns (bool);
}
```

When `callFrom` is called, the `World` checks if a delegation is registered for the given caller, and if so calls the delegation control's `verify` function with the same same arguments as `callFrom`.
If the call to `verify` is successful and returns `true`, the delegation is valid and the call is forwarded to the system with `delegator` as `msgSender`.

Note: if `UNLIMITED_DELEGATION` (from `@latticexyz/world/src/constants.sol`) is passed as `delegationControl`, the external call to the delegation control contract is skipped and the delegation is considered valid.

For examples of `DelegationControl` systems, check out the `CallboundDelegationControl` or `TimeboundDelegationControl` systems in the `std-delegations` module.
See `StandardDelegations.t.sol` for usage examples.

**[feat(world): allow transferring ownership of namespaces (#1274)](https://github.com/latticexyz/mud/commit/c583f3cd08767575ce9df39725ec51195b5feb5b)** (@latticexyz/world)

It is now possible to transfer ownership of namespaces!

```solidity
// Register a new namespace
world.registerNamespace("namespace");
// It's owned by the caller of the function (address(this))
// Transfer ownership of the namespace to address(42)
world.transferOwnership("namespace", address(42));
// It's now owned by address(42)
```

## Patch changes

**[fix(services): correctly export typescript types (#1377)](https://github.com/latticexyz/mud/commit/33f50f8a473398dcc19b17d10a17a552a82678c7)** (@latticexyz/services)

Fixed an issue where the TypeScript types for createFaucetService were not exported correctly from the @latticexyz/services package

**[feat: docker monorepo build (#1219)](https://github.com/latticexyz/mud/commit/80a26419f15177333b523bac5d09767487b4ffef)** (@latticexyz/services)

The build phase of services now works on machines with older protobuf compilers

**[refactor: remove v1 network package, remove snap sync module, deprecate std-client (#1311)](https://github.com/latticexyz/mud/commit/331f0d636f6f327824307570a63fb301d9b897d1)** (@latticexyz/common, @latticexyz/store, @latticexyz/world)

- Refactor tightcoder to use typescript functions instead of ejs
- Optimize `TightCoder` library
- Add `isLeftAligned` and `getLeftPaddingBits` common codegen helpers

**[fix(cli): make mud test exit with code 1 on test error (#1371)](https://github.com/latticexyz/mud/commit/dc258e6860196ad34bf1d4ac7fce382f70e2c0c8)** (@latticexyz/cli)

The `mud test` cli now exits with code 1 on test failure. It used to exit with code 0, which meant that CIs didn't notice test failures.

---

# Version 2.0.0-next.4

## Major changes
Expand Down
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM docker.io/library/debian:bullseye-slim as base
ENV SHELL /bin/bash

WORKDIR /opt
RUN apt-get -y update --fix-missing && \
apt-get -y upgrade && \
apt-get install -y --no-install-recommends \
libssl-dev make cmake graphviz \
git pkg-config curl time rhash ca-certificates jq \
python3 python3-pip lsof ruby ruby-bundler git-restore-mtime xz-utils zstd unzip gnupg protobuf-compiler \
wget net-tools iptables iproute2 iputils-ping ed zlib1g-dev wabt && \
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs

# foundry
RUN curl -L https://foundry.paradigm.xyz/ | bash && \
${HOME}/.foundry/bin/foundryup \
&& forge --version \
&& cast --version \
&& anvil --version \
&& chisel --version
# go
RUN wget https://dl.google.com/go/go1.20.4.linux-amd64.tar.gz && \
# -C to move to given directory
tar -C /usr/local/ -xzf go1.20.4.linux-amd64.tar.gz
# pnpm
RUN npm install pnpm --global && pnpm --version

FROM base AS builder
COPY . /app
WORKDIR /app

ENV PATH="${PATH}:/usr/local/go/bin"
ENV PATH="${PATH}:/root/.foundry/bin"
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run -r build

FROM builder AS store-indexer
WORKDIR /app/packages/store-indexer
EXPOSE 3001
6 changes: 3 additions & 3 deletions docs/pages/store/advanced-features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ contract MirrorSubscriber is IStoreHook {
}
function onSetRecord(uint256 table, bytes32[] memory key, bytes memory data) public {
if (table != table) revert("invalid table");
if (_table != table) revert("invalid table");
StoreSwitch.setRecord(indexerTableId, key, data);
}
function onSetField(uint256 table, bytes32[] memory key, uint8 schemaIndex, bytes memory data) public {
if (table != table) revert("invalid table");
if (_table != table) revert("invalid table");
StoreSwitch.setField(indexerTableId, key, schemaIndex, data);
}
function onDeleteRecord(uint256 table, bytes32[] memory key) public {
if (table != table) revert("invalid table");
if (_table != table) revert("invalid table");
StoreSwitch.deleteRecord(indexerTableId, key);
}
}
Expand Down
Loading

0 comments on commit 2f3ad39

Please sign in to comment.