Skip to content

Commit

Permalink
feat(store): indexed tableId in store events (#1520)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Sep 16, 2023
1 parent 708b49c commit 99ab9cd
Show file tree
Hide file tree
Showing 12 changed files with 496 additions and 420 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-worms-hunt.md
@@ -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.
2 changes: 0 additions & 2 deletions .changeset/thin-terms-lay.md
Expand Up @@ -11,7 +11,6 @@ This saves gas for use cases where the functionality to dynamically determine wh
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;
Expand All @@ -21,5 +20,4 @@ library Counter {
// ... equivalent functions for all other Store methods
}
```
1 change: 1 addition & 0 deletions .gitattributes
@@ -1,2 +1,3 @@
# suppress diffs for codegen in PRs
**/codegen/**/*.sol linguist-generated=true
**/test-data/**/*.json linguist-generated=true
8 changes: 4 additions & 4 deletions packages/store-sync/src/postgres/postgresStorage.test.ts
Expand Up @@ -56,7 +56,7 @@ describe("postgresStorage", async () => {
{
"chainId": 31337,
"lastError": null,
"lastUpdatedBlockNumber": 6n,
"lastUpdatedBlockNumber": 5n,
"schemaVersion": 1,
},
]
Expand All @@ -74,7 +74,7 @@ describe("postgresStorage", async () => {
"key": "0x5FbDB2315678afecb367f032d93F642f64180aa3::NumberList",
"keySchema": {},
"lastError": null,
"lastUpdatedBlockNumber": 6n,
"lastUpdatedBlockNumber": 5n,
"name": "NumberList",
"namespace": "",
"schemaVersion": 1,
Expand All @@ -92,7 +92,7 @@ describe("postgresStorage", async () => {
{
"address": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"keySchema": {},
"lastUpdatedBlockNumber": 6n,
"lastUpdatedBlockNumber": 5n,
"name": "NumberList",
"namespace": "",
"tableId": "0x000000000000000000000000000000004e756d6265724c697374000000000000",
Expand All @@ -111,7 +111,7 @@ describe("postgresStorage", async () => {
"__encodedLengths": "0x0000000000000000000000000000000000000000000000000800000000000008",
"__isDeleted": false,
"__key": "0x",
"__lastUpdatedBlockNumber": 6n,
"__lastUpdatedBlockNumber": 5n,
"__staticData": null,
"value": [
420,
Expand Down
8 changes: 4 additions & 4 deletions packages/store-sync/src/sqlite/sqliteStorage.test.ts
Expand Up @@ -64,7 +64,7 @@ describe("sqliteStorage", async () => {
{
"chainId": 31337,
"lastError": null,
"lastUpdatedBlockNumber": 6n,
"lastUpdatedBlockNumber": 5n,
"schemaVersion": 1,
},
]
Expand All @@ -77,7 +77,7 @@ describe("sqliteStorage", async () => {
"id": "0x5FbDB2315678afecb367f032d93F642f64180aa3____NumberList",
"keySchema": {},
"lastError": null,
"lastUpdatedBlockNumber": 6n,
"lastUpdatedBlockNumber": 5n,
"name": "NumberList",
"namespace": "",
"schemaVersion": 1,
Expand All @@ -96,7 +96,7 @@ describe("sqliteStorage", async () => {
"address": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"id": "0x5FbDB2315678afecb367f032d93F642f64180aa3____NumberList",
"keySchema": {},
"lastUpdatedBlockNumber": 6n,
"lastUpdatedBlockNumber": 5n,
"name": "NumberList",
"namespace": "",
"tableId": "0x000000000000000000000000000000004e756d6265724c697374000000000000",
Expand All @@ -115,7 +115,7 @@ describe("sqliteStorage", async () => {
"__encodedLengths": "0x0000000000000000000000000000000000000000000000000800000000000008",
"__isDeleted": false,
"__key": "0x",
"__lastUpdatedBlockNumber": 6n,
"__lastUpdatedBlockNumber": 5n,
"__staticData": null,
"value": [
420,
Expand Down

0 comments on commit 99ab9cd

Please sign in to comment.