Skip to content

Commit

Permalink
feat: replace Schema with FieldLayout for contract internals (#1336)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
Co-authored-by: alvrs <alvarius@lattice.xyz>
  • Loading branch information
3 people committed Sep 13, 2023
1 parent f823e72 commit de151fe
Show file tree
Hide file tree
Showing 223 changed files with 12,447 additions and 2,911 deletions.
28 changes: 28 additions & 0 deletions .changeset/grumpy-files-heal.md
@@ -0,0 +1,28 @@
---
"@latticexyz/cli": major
"@latticexyz/protocol-parser": minor
"@latticexyz/store": major
"@latticexyz/world": major
---

- 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.

- 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.

- 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.

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

- Add `constants.sol` for constants shared between `FieldLayout`, `Schema` and `PackedCounter`.
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.

0 comments on commit de151fe

Please sign in to comment.