Skip to content

Commit

Permalink
refactor(store): change argument order on Store_SpliceDynamicData a…
Browse files Browse the repository at this point in the history
…nd hooks for consistency (#1589)
  • Loading branch information
alvrs authored Sep 24, 2023
1 parent 22ee447 commit f9f9609
Show file tree
Hide file tree
Showing 21 changed files with 451 additions and 405 deletions.
44 changes: 44 additions & 0 deletions .changeset/eighty-pots-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
"@latticexyz/store": major
---

The argument order on `Store_SpliceDynamicData`, `onBeforeSpliceDynamicData` and `onAfterSpliceDynamicData` has been changed to match the argument order on `Store_SetRecord`,
where the `PackedCounter encodedLength` field comes before the `bytes dynamicData` field.

```diff
IStore {
event Store_SpliceDynamicData(
ResourceId indexed tableId,
bytes32[] keyTuple,
uint48 start,
uint40 deleteCount,
+ PackedCounter encodedLengths,
bytes data,
- PackedCounter encodedLengths
);
}

IStoreHook {
function onBeforeSpliceDynamicData(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint40 startWithinField,
uint40 deleteCount,
+ PackedCounter encodedLengths,
bytes memory data,
- PackedCounter encodedLengths
) external;

function onAfterSpliceDynamicData(
ResourceId tableId,
bytes32[] memory keyTuple,
uint8 dynamicFieldIndex,
uint40 startWithinField,
uint40 deleteCount,
+ PackedCounter encodedLengths,
bytes memory data,
- PackedCounter encodedLengths
) external;
}
```
2 changes: 1 addition & 1 deletion docs/pages/store/spec.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ When a record or a single field is edited, or when a record is deleted, Store em
```solidity
event Store_SetRecord(bytes32 indexed tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData),
event Store_SpliceStaticData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, bytes data),
event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, uint40 deleteCount, bytes data, bytes32 encodedLengths),
event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, uint40 deleteCount, bytes32 encodedLengths, bytes data),
event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple),
```

Expand Down
2 changes: 1 addition & 1 deletion packages/block-logs-stream/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ latestBlockNumber$
events: parseAbi([
"event Store_SetRecord(bytes32 indexed tableId, bytes32[] keyTuple, bytes staticData, bytes32 encodedLengths, bytes dynamicData)",
"event Store_SpliceStaticData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, bytes data)",
"event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, uint40 deleteCount, bytes data, bytes32 encodedLengths)",
"event Store_SpliceDynamicData(bytes32 indexed tableId, bytes32[] keyTuple, uint48 start, uint40 deleteCount, bytes32 encodedLengths, bytes data)",
"event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)",
]),
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/dev-tools/src/events/LogsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export function LogsTable({ logs }: Props) {
? JSON.stringify({
start: log.args.start,
deleteCount: log.args.deleteCount,
data: log.args.data,
encodedLengths: log.args.encodedLengths,
data: log.args.data,
})
: null}
</td>
Expand Down
8 changes: 4 additions & 4 deletions packages/store-sync/src/postgres/postgresStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("postgresStorage", async () => {
{
"chainId": 31337,
"lastError": null,
"lastUpdatedBlockNumber": 5n,
"lastUpdatedBlockNumber": 6n,
"schemaVersion": 1,
},
]
Expand All @@ -74,7 +74,7 @@ describe("postgresStorage", async () => {
"key": "0x5FbDB2315678afecb367f032d93F642f64180aa3::NumberList",
"keySchema": {},
"lastError": null,
"lastUpdatedBlockNumber": 5n,
"lastUpdatedBlockNumber": 6n,
"name": "NumberList",
"namespace": "",
"schemaVersion": 1,
Expand All @@ -94,7 +94,7 @@ describe("postgresStorage", async () => {
"key": "0x5FbDB2315678afecb367f032d93F642f64180aa3::NumberList",
"keySchema": {},
"lastError": null,
"lastUpdatedBlockNumber": 5n,
"lastUpdatedBlockNumber": 6n,
"name": "NumberList",
"namespace": "",
"schemaVersion": 1,
Expand All @@ -114,7 +114,7 @@ describe("postgresStorage", async () => {
"__encodedLengths": "0x0000000000000000000000000000000000000000000000000800000000000008",
"__isDeleted": false,
"__key": "0x",
"__lastUpdatedBlockNumber": 5n,
"__lastUpdatedBlockNumber": 6n,
"__staticData": null,
"value": [
420,
Expand Down
8 changes: 4 additions & 4 deletions packages/store-sync/src/sqlite/sqliteStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe("sqliteStorage", async () => {
{
"chainId": 31337,
"lastError": null,
"lastUpdatedBlockNumber": 5n,
"lastUpdatedBlockNumber": 6n,
"schemaVersion": 1,
},
]
Expand All @@ -77,7 +77,7 @@ describe("sqliteStorage", async () => {
"id": "0x5FbDB2315678afecb367f032d93F642f64180aa3____NumberList",
"keySchema": {},
"lastError": null,
"lastUpdatedBlockNumber": 5n,
"lastUpdatedBlockNumber": 6n,
"name": "NumberList",
"namespace": "",
"schemaVersion": 1,
Expand All @@ -97,7 +97,7 @@ describe("sqliteStorage", async () => {
"id": "0x5FbDB2315678afecb367f032d93F642f64180aa3____NumberList",
"keySchema": {},
"lastError": null,
"lastUpdatedBlockNumber": 5n,
"lastUpdatedBlockNumber": 6n,
"name": "NumberList",
"namespace": "",
"schemaVersion": 1,
Expand All @@ -117,7 +117,7 @@ describe("sqliteStorage", async () => {
"__encodedLengths": "0x0000000000000000000000000000000000000000000000000800000000000008",
"__isDeleted": false,
"__key": "0x",
"__lastUpdatedBlockNumber": 5n,
"__lastUpdatedBlockNumber": 6n,
"__staticData": null,
"value": [
420,
Expand Down
58 changes: 29 additions & 29 deletions packages/store/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -651,25 +651,25 @@
"file": "test/StoreCoreDynamic.t.sol",
"test": "testPopFromSecondField",
"name": "pop from field (cold, 1 slot, 1 uint32 item)",
"gasUsed": 18097
"gasUsed": 18094
},
{
"file": "test/StoreCoreDynamic.t.sol",
"test": "testPopFromSecondField",
"name": "pop from field (warm, 1 slot, 1 uint32 item)",
"gasUsed": 12104
"gasUsed": 12101
},
{
"file": "test/StoreCoreDynamic.t.sol",
"test": "testPopFromThirdField",
"name": "pop from field (cold, 2 slots, 10 uint32 items)",
"gasUsed": 15865
"gasUsed": 15862
},
{
"file": "test/StoreCoreDynamic.t.sol",
"test": "testPopFromThirdField",
"name": "pop from field (warm, 2 slots, 10 uint32 items)",
"gasUsed": 11872
"gasUsed": 11869
},
{
"file": "test/StoreCoreGas.t.sol",
Expand Down Expand Up @@ -729,13 +729,13 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testHooks",
"name": "register subscriber",
"gasUsed": 58019
"gasUsed": 58016
},
{
"file": "test/StoreCoreGas.t.sol",
"test": "testHooks",
"name": "set record on table with subscriber",
"gasUsed": 72428
"gasUsed": 72450
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -753,19 +753,19 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testHooksDynamicData",
"name": "register subscriber",
"gasUsed": 58019
"gasUsed": 58016
},
{
"file": "test/StoreCoreGas.t.sol",
"test": "testHooksDynamicData",
"name": "set (dynamic) record on table with subscriber",
"gasUsed": 165583
"gasUsed": 165605
},
{
"file": "test/StoreCoreGas.t.sol",
"test": "testHooksDynamicData",
"name": "set (dynamic) field on table with subscriber",
"gasUsed": 24599
"gasUsed": 24593
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -777,13 +777,13 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testPushToDynamicField",
"name": "push to field (1 slot, 1 uint32 item)",
"gasUsed": 9524
"gasUsed": 9521
},
{
"file": "test/StoreCoreGas.t.sol",
"test": "testPushToDynamicField",
"name": "push to field (2 slots, 10 uint32 items)",
"gasUsed": 32194
"gasUsed": 32191
},
{
"file": "test/StoreCoreGas.t.sol",
Expand Down Expand Up @@ -879,7 +879,7 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testSetAndGetField",
"name": "set dynamic field (1 slot, first dynamic field)",
"gasUsed": 54010
"gasUsed": 54007
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -891,7 +891,7 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testSetAndGetField",
"name": "set dynamic field (1 slot, second dynamic field)",
"gasUsed": 32233
"gasUsed": 32230
},
{
"file": "test/StoreCoreGas.t.sol",
Expand Down Expand Up @@ -927,19 +927,19 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testUpdateInDynamicField",
"name": "update in field (1 slot, 1 uint32 item)",
"gasUsed": 8872
"gasUsed": 8869
},
{
"file": "test/StoreCoreGas.t.sol",
"test": "testUpdateInDynamicField",
"name": "push to field (2 slots, 6 uint64 items)",
"gasUsed": 9318
"gasUsed": 9315
},
{
"file": "test/StoreHook.t.sol",
"test": "testCallHook",
"name": "call an enabled hook",
"gasUsed": 15010
"gasUsed": 15032
},
{
"file": "test/StoreHook.t.sol",
Expand Down Expand Up @@ -975,7 +975,7 @@
"file": "test/tables/Callbacks.t.sol",
"test": "testSetAndGet",
"name": "Callbacks: set field",
"gasUsed": 56321
"gasUsed": 56318
},
{
"file": "test/tables/Callbacks.t.sol",
Expand All @@ -987,19 +987,19 @@
"file": "test/tables/Callbacks.t.sol",
"test": "testSetAndGet",
"name": "Callbacks: push 1 element",
"gasUsed": 32579
"gasUsed": 32576
},
{
"file": "test/tables/StoreHooks.t.sol",
"test": "testOneSlot",
"name": "StoreHooks: set field with one elements (cold)",
"gasUsed": 58327
"gasUsed": 58324
},
{
"file": "test/tables/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: set field (cold)",
"gasUsed": 58327
"gasUsed": 58324
},
{
"file": "test/tables/StoreHooks.t.sol",
Expand All @@ -1011,25 +1011,25 @@
"file": "test/tables/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: push 1 element (cold)",
"gasUsed": 12677
"gasUsed": 12674
},
{
"file": "test/tables/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: pop 1 element (warm)",
"gasUsed": 10011
"gasUsed": 10008
},
{
"file": "test/tables/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: push 1 element (warm)",
"gasUsed": 10694
"gasUsed": 10691
},
{
"file": "test/tables/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: update 1 element (warm)",
"gasUsed": 29920
"gasUsed": 29917
},
{
"file": "test/tables/StoreHooks.t.sol",
Expand All @@ -1041,19 +1041,19 @@
"file": "test/tables/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: set field (warm)",
"gasUsed": 30472
"gasUsed": 30469
},
{
"file": "test/tables/StoreHooks.t.sol",
"test": "testThreeSlots",
"name": "StoreHooks: set field with three elements (cold)",
"gasUsed": 81015
"gasUsed": 81012
},
{
"file": "test/tables/StoreHooks.t.sol",
"test": "testTwoSlots",
"name": "StoreHooks: set field with two elements (cold)",
"gasUsed": 80927
"gasUsed": 80924
},
{
"file": "test/tables/StoreHooksColdLoad.t.sol",
Expand Down Expand Up @@ -1083,13 +1083,13 @@
"file": "test/tables/StoreHooksColdLoad.t.sol",
"test": "testPop",
"name": "StoreHooks: pop 1 element (cold)",
"gasUsed": 18446
"gasUsed": 18443
},
{
"file": "test/tables/StoreHooksColdLoad.t.sol",
"test": "testUpdate",
"name": "StoreHooks: update 1 element (cold)",
"gasUsed": 20375
"gasUsed": 20372
},
{
"file": "test/tightcoder/DecodeSlice.t.sol",
Expand Down
4 changes: 2 additions & 2 deletions packages/store/src/IStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ interface IStoreWrite {
bytes32[] keyTuple,
uint48 start,
uint40 deleteCount,
bytes data,
PackedCounter encodedLengths
PackedCounter encodedLengths,
bytes data
);
event Store_DeleteRecord(ResourceId indexed tableId, bytes32[] keyTuple);

Expand Down
Loading

0 comments on commit f9f9609

Please sign in to comment.