Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(world): add CallBatchSystem to core module #1500

Merged
merged 25 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f2d79e0
feat(world): add BatchCallModule
yonadaa Sep 15, 2023
e5bba67
fix: remove comment
yonadaa Sep 15, 2023
ca27801
Merge remote-tracking branch 'origin/main' into batch-call
yonadaa Sep 18, 2023
8ab8d04
chore: run gas report, rename to callDatas
yonadaa Sep 18, 2023
4f00381
feat: add batch call from root module
yonadaa Sep 18, 2023
c3c3d00
chore: add batch call to default module contracts
yonadaa Sep 18, 2023
ad2bebb
test: do not hardcode system address
yonadaa Sep 18, 2023
f7c9bc9
chore: run gas report
yonadaa Sep 18, 2023
7cd8904
Merge remote-tracking branch 'origin/main' into batch-call
yonadaa Sep 18, 2023
c2a9869
chore: delete non-root batch call module
yonadaa Sep 18, 2023
295ed8c
chore: remove mud config change
yonadaa Sep 18, 2023
7159e83
feat: rename to callBatch, add to core module
yonadaa Sep 18, 2023
312dba9
chore: rename gas report
yonadaa Sep 18, 2023
f27d7a2
feat: add return data to callBatch
yonadaa Sep 18, 2023
94cfee6
Merge remote-tracking branch 'origin/main' into batch-call
yonadaa Sep 18, 2023
2218493
chore: move comment
yonadaa Sep 18, 2023
059b0e6
chore: modify comment
yonadaa Sep 19, 2023
5cf3012
feat: use struct for callBatch arguments
yonadaa Sep 19, 2023
8300aa0
test: add access control tests for callBatch
yonadaa Sep 19, 2023
480b721
chore: tweak comment
yonadaa Sep 19, 2023
1affa39
refactor: move test constants
yonadaa Sep 19, 2023
e8144b7
Merge remote-tracking branch 'origin/main' into batch-call
yonadaa Sep 19, 2023
56f1094
Merge branch 'main' into batch-call
alvrs Sep 21, 2023
9f8a2a2
gas report
alvrs Sep 21, 2023
4ce27d2
Create wild-nails-wonder.md
alvrs Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/wild-nails-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@latticexyz/world": minor
---

The `World` now has a `callBatch` method which allows multiple system calls to be batched into a single transaction.

```solidity
import { SystemCallData } from "@latticexyz/world/modules/core/types.sol";

interface IBaseWorld {
function callBatch(SystemCallData[] calldata systemCalls) external returns (bytes[] memory returnDatas);
}
```
48 changes: 27 additions & 21 deletions packages/world/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,23 @@
"name": "AccessControl: requireAccess (this address)",
"gasUsed": 153
},
{
"file": "test/CallBatch.t.sol",
"test": "testCallBatchReturnData",
"name": "call systems with callBatch",
"gasUsed": 45546
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallComposite",
"name": "install keys in table module",
"gasUsed": 1414653
"gasUsed": 1415069
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallGas",
"name": "install keys in table module",
"gasUsed": 1414653
"gasUsed": 1415069
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -57,13 +63,13 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testInstallSingleton",
"name": "install keys in table module",
"gasUsed": 1414653
"gasUsed": 1415069
},
{
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookCompositeGas",
"name": "install keys in table module",
"gasUsed": 1414653
"gasUsed": 1415069
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -81,7 +87,7 @@
"file": "test/KeysInTableModule.t.sol",
"test": "testSetAndDeleteRecordHookGas",
"name": "install keys in table module",
"gasUsed": 1414653
"gasUsed": 1415069
},
{
"file": "test/KeysInTableModule.t.sol",
Expand All @@ -99,7 +105,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testGetKeysWithValueGas",
"name": "install keys with value module",
"gasUsed": 665378
"gasUsed": 665448
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -117,7 +123,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testInstall",
"name": "install keys with value module",
"gasUsed": 665378
"gasUsed": 665448
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -129,7 +135,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetAndDeleteRecordHook",
"name": "install keys with value module",
"gasUsed": 665378
"gasUsed": 665448
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand All @@ -147,7 +153,7 @@
"file": "test/KeysWithValueModule.t.sol",
"test": "testSetField",
"name": "install keys with value module",
"gasUsed": 665378
"gasUsed": 665448
},
{
"file": "test/KeysWithValueModule.t.sol",
Expand Down Expand Up @@ -231,7 +237,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromCallboundDelegation",
"name": "register a callbound delegation",
"gasUsed": 114589
"gasUsed": 114729
},
{
"file": "test/StandardDelegationsModule.t.sol",
Expand All @@ -243,7 +249,7 @@
"file": "test/StandardDelegationsModule.t.sol",
"test": "testCallFromTimeboundDelegation",
"name": "register a timebound delegation",
"gasUsed": 109084
"gasUsed": 109224
},
{
"file": "test/StandardDelegationsModule.t.sol",
Expand All @@ -255,7 +261,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstall",
"name": "install unique entity module",
"gasUsed": 690431
"gasUsed": 690539
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand All @@ -267,7 +273,7 @@
"file": "test/UniqueEntityModule.t.sol",
"test": "testInstallRoot",
"name": "installRoot unique entity module",
"gasUsed": 680681
"gasUsed": 680735
},
{
"file": "test/UniqueEntityModule.t.sol",
Expand All @@ -285,7 +291,7 @@
"file": "test/World.t.sol",
"test": "testCallFromUnlimitedDelegation",
"name": "register an unlimited delegation",
"gasUsed": 50629
"gasUsed": 50617
},
{
"file": "test/World.t.sol",
Expand All @@ -309,43 +315,43 @@
"file": "test/World.t.sol",
"test": "testRegisterFallbackSystem",
"name": "Register a fallback system",
"gasUsed": 59306
"gasUsed": 59347
},
{
"file": "test/World.t.sol",
"test": "testRegisterFallbackSystem",
"name": "Register a root fallback system",
"gasUsed": 52950
"gasUsed": 52972
},
{
"file": "test/World.t.sol",
"test": "testRegisterFunctionSelector",
"name": "Register a function selector",
"gasUsed": 79872
"gasUsed": 79913
},
{
"file": "test/World.t.sol",
"test": "testRegisterNamespace",
"name": "Register a new namespace",
"gasUsed": 123269
"gasUsed": 123225
},
{
"file": "test/World.t.sol",
"test": "testRegisterRootFunctionSelector",
"name": "Register a root function selector",
"gasUsed": 74863
"gasUsed": 74885
},
{
"file": "test/World.t.sol",
"test": "testRegisterSystem",
"name": "register a system",
"gasUsed": 165750
"gasUsed": 165772
},
{
"file": "test/World.t.sol",
"test": "testRegisterTable",
"name": "Register a new table in the namespace",
"gasUsed": 651802
"gasUsed": 651898
},
{
"file": "test/World.t.sol",
Expand Down
2 changes: 2 additions & 0 deletions packages/world/src/interfaces/IBaseWorld.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IWorldKernel } from "../interfaces/IWorldKernel.sol";
import { ICoreSystem } from "./ICoreSystem.sol";
import { IAccessManagementSystem } from "./IAccessManagementSystem.sol";
import { IBalanceTransferSystem } from "./IBalanceTransferSystem.sol";
import { ICallBatchSystem } from "./ICallBatchSystem.sol";
import { IModuleInstallationSystem } from "./IModuleInstallationSystem.sol";
import { IWorldRegistrationSystem } from "./IWorldRegistrationSystem.sol";

Expand All @@ -22,6 +23,7 @@ interface IBaseWorld is
ICoreSystem,
IAccessManagementSystem,
IBalanceTransferSystem,
ICallBatchSystem,
IModuleInstallationSystem,
IWorldRegistrationSystem
{
Expand Down
10 changes: 10 additions & 0 deletions packages/world/src/interfaces/ICallBatchSystem.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.21;

/* Autogenerated file. Do not edit manually. */

import { SystemCallData } from "./../modules/core/types.sol";

interface ICallBatchSystem {
function callBatch(SystemCallData[] calldata systemCalls) external returns (bytes[] memory returnDatas);
}
5 changes: 4 additions & 1 deletion packages/world/src/modules/core/CoreModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Balances } from "./tables/Balances.sol";

import { AccessManagementSystem } from "./implementations/AccessManagementSystem.sol";
import { BalanceTransferSystem } from "./implementations/BalanceTransferSystem.sol";
import { CallBatchSystem } from "./implementations/CallBatchSystem.sol";
import { ModuleInstallationSystem } from "./implementations/ModuleInstallationSystem.sol";
import { StoreRegistrationSystem } from "./implementations/StoreRegistrationSystem.sol";
import { WorldRegistrationSystem } from "./implementations/WorldRegistrationSystem.sol";
Expand Down Expand Up @@ -102,14 +103,16 @@ contract CoreModule is Module {
* Register function selectors for all CoreSystem functions in the World
*/
function _registerFunctionSelectors() internal {
bytes4[16] memory functionSelectors = [
bytes4[17] memory functionSelectors = [
// --- AccessManagementSystem ---
AccessManagementSystem.grantAccess.selector,
AccessManagementSystem.revokeAccess.selector,
AccessManagementSystem.transferOwnership.selector,
// --- BalanceTransferSystem ---
BalanceTransferSystem.transferBalanceToNamespace.selector,
BalanceTransferSystem.transferBalanceToAddress.selector,
// --- CallBatchSystem ---
CallBatchSystem.callBatch.selector,
// --- ModuleInstallationSystem ---
ModuleInstallationSystem.installModule.selector,
// --- StoreRegistrationSystem ---
Expand Down
2 changes: 2 additions & 0 deletions packages/world/src/modules/core/CoreSystem.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IWorldErrors } from "../../interfaces/IWorldErrors.sol";

import { AccessManagementSystem } from "./implementations/AccessManagementSystem.sol";
import { BalanceTransferSystem } from "./implementations/BalanceTransferSystem.sol";
import { CallBatchSystem } from "./implementations/CallBatchSystem.sol";
import { ModuleInstallationSystem } from "./implementations/ModuleInstallationSystem.sol";
import { StoreRegistrationSystem } from "./implementations/StoreRegistrationSystem.sol";
import { WorldRegistrationSystem } from "./implementations/WorldRegistrationSystem.sol";
Expand All @@ -17,6 +18,7 @@ contract CoreSystem is
IWorldErrors,
AccessManagementSystem,
BalanceTransferSystem,
CallBatchSystem,
ModuleInstallationSystem,
StoreRegistrationSystem,
WorldRegistrationSystem
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import { System } from "../../../System.sol";
import { IBaseWorld } from "../../../interfaces/IBaseWorld.sol";
import { revertWithBytes } from "../../../revertWithBytes.sol";

import { SystemCallData } from "../types.sol";

contract CallBatchSystem is System {
/**
* Batch calls to multiple systems into a single transaction, return the array of return data.
*/
function callBatch(SystemCallData[] calldata systemCalls) public returns (bytes[] memory returnDatas) {
IBaseWorld world = IBaseWorld(_world());
returnDatas = new bytes[](systemCalls.length);

for (uint256 i; i < systemCalls.length; i++) {
(bool success, bytes memory returnData) = address(world).delegatecall(
abi.encodeCall(world.call, (systemCalls[i].systemId, systemCalls[i].callData))
);
if (!success) revertWithBytes(returnData);

returnDatas[i] = abi.decode(returnData, (bytes));
}
}
}
9 changes: 9 additions & 0 deletions packages/world/src/modules/core/types.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.21;

import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";

struct SystemCallData {
ResourceId systemId;
bytes callData;
}
Loading