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: replace Schema with FieldLayout for contract internals #1336

Merged
merged 27 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e950c82
replace SchemaType in Schema with staticByteLength and numDynamicFields
dk1a Aug 21, 2023
984756d
fix gas comments
dk1a Aug 21, 2023
b6d01ca
refactor(store): change Schema to FieldLayout
dk1a Aug 28, 2023
af3f27b
refactor(world): change Schema to FieldLayout
dk1a Aug 28, 2023
d9da351
build
dk1a Aug 28, 2023
20e84a6
refactor(store): add Schema back
dk1a Aug 29, 2023
19e6f61
refactor(world): add Schema back
dk1a Sep 2, 2023
2c73ca1
Merge branch 'main' into dk1a/schematype-to-length
dk1a Sep 2, 2023
536406e
refactor(store): remove keyFieldLayout, add more Schema methods back
dk1a Sep 4, 2023
44d2b53
refactor(world): remove keyFieldLayout, add more Schema methods back
dk1a Sep 4, 2023
142b3b3
finish renaming, cleanup, build
dk1a Sep 5, 2023
ec219b5
fix names, add more tests
dk1a Sep 5, 2023
cc9df67
Merge branch 'main' into dk1a/schematype-to-length
dk1a Sep 5, 2023
9a96307
Create grumpy-files-heal.md
dk1a Sep 5, 2023
8656b5a
update test fixtures
holic Sep 6, 2023
7b2e6fb
Merge branch 'main' into dk1a/schematype-to-length
dk1a Sep 11, 2023
e7a3f7a
update the comment of registerTable
dk1a Sep 12, 2023
fe676b9
update FieldLayout error names
dk1a Sep 12, 2023
8385372
build
dk1a Sep 12, 2023
8de0f19
improve FieldLayout readability with constants
dk1a Sep 12, 2023
54ad7ab
single source for MAX_DYNAMIC_FIELDS constant
dk1a Sep 12, 2023
7094aae
use shared constants file, refactor Schema
dk1a Sep 12, 2023
0133a8c
rename valueNames back to fieldNames
dk1a Sep 12, 2023
2d91a23
build
dk1a Sep 12, 2023
2afc1c5
update changelog
dk1a Sep 12, 2023
387068a
Update .changeset/grumpy-files-heal.md
dk1a Sep 12, 2023
5e993cc
Merge branch 'main' into dk1a/schematype-to-length
alvrs Sep 13, 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
30 changes: 30 additions & 0 deletions .changeset/grumpy-files-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
"@latticexyz/cli": major
"@latticexyz/protocol-parser": minor
"@latticexyz/store": major
"@latticexyz/world": major
---

1. Add `FieldLayout`, which is a `bytes32` user-type similar to `Schema`.

Both `FieldLayout` and `Schema` have the same kind of data in the first 4 bytes.

- 2 bytes for total length of all static fields
- 1 byte for number of static size fields
- 1 byte for number of dynamic size fields

But whereas `Schema` has `SchemaType` enum in each of the other 28 bytes,
`FieldLayout` has static byte lengths in each of the other 28 bytes.

2. Replace `Schema valueSchema` with `FieldLayout fieldLayout` in Store and World contracts.

`FieldLayout` is more gas-efficient because it already has lengths, and `Schema` has types which need to be converted to lengths.

3. Add `getFieldLayout` to `IStore` interface.

There is no `FieldLayout` for keys, only for values, because key byte lengths aren't usually relevant on-chain.
You can still use `getKeySchema` if you need key types.

4. Add `fieldLayoutToHex` utility to `protocol-parser` package.

5. Add `constants.sol` for constants shared between `FieldLayout`, `Schema` and `PackedCounter`.
dk1a marked this conversation as resolved.
Show resolved Hide resolved
59 changes: 38 additions & 21 deletions e2e/packages/contracts/src/codegen/tables/Multi.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 28 additions & 12 deletions e2e/packages/contracts/src/codegen/tables/Number.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading