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: v2 event decoding #415

Merged
merged 75 commits into from
Mar 15, 2023
Merged

feat: v2 event decoding #415

merged 75 commits into from
Mar 15, 2023

Conversation

holic
Copy link
Member

@holic holic commented Feb 17, 2023

Parses v2 events into schema registrations and data to populate client ECS with it.

TODO

  • decode arrays
  • use generics in config def so we can carry table types through
  • use generics in decoding to carry schema types through
  • figure out key tuples for client (concatenate? json encode?)
  • lazily fetch metadata
  • update missing key warning only for non-numeric keys
  • add support for key schema
  • add peer deps
  • ensure no local/linked deps
  • remove circular dep feat: v2 event decoding #415 (comment)
  • add tests for long-lived low-level stuff
  • fetch from ECS cache before RPC for schemas/metadata
  • figure out how to get things to compile with mud.config imports
  • make parseConfig more strongly typed and carry through statically defined values
  • flip StoreConfig and StoreUserConfig, etc. so we default to user-first

@holic holic force-pushed the holic/sync-store-v2 branch from 678cd09 to f3fb706 Compare February 20, 2023 16:02
@holic holic force-pushed the holic/sync-store-v2 branch 2 times, most recently from 5c588e5 to f1e27de Compare March 2, 2023 01:22
@holic holic changed the base branch from v2 to main March 2, 2023 01:22
@holic holic force-pushed the holic/sync-store-v2 branch from f1e27de to 5c588e5 Compare March 2, 2023 01:22
@holic holic force-pushed the holic/sync-store-v2 branch 3 times, most recently from b8fb384 to 7863484 Compare March 2, 2023 21:12
@holic holic force-pushed the holic/sync-store-v2 branch from 7863484 to 8b8b633 Compare March 2, 2023 23:38
@holic holic force-pushed the holic/sync-store-v2 branch from 580373b to e6491e8 Compare March 7, 2023 01:31
@holic holic force-pushed the holic/sync-store-v2 branch from df2fafb to 0afa82d Compare March 7, 2023 02:24
Copy link
Member

@alvrs alvrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking (except from the comment in package.json of world/store). Are you planning to add all TODO comments to some tracker and link the tracker in the code?

Almost there!!

@@ -7,7 +7,7 @@ export async function loadStoreConfig(configPath?: string) {
const config = await loadConfig(configPath);

try {
return parseStoreConfig(config);
return parseStoreConfig(config as any);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Member Author

@holic holic Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadConfig has a return value of unknown, and if I don't cast it, I get
image

this is happening now because I changed the argument type in parseStoreConfig to help with defineStoreComponents (to "expand" the mud config into something reasonable/without tons of shorthand and conditional branching)
image

import { decodeStaticField } from "./decodeStaticField";
import { decodeDynamicField } from "./decodeDynamicField";

export const decodeData = (schema: TableSchema, hexData: string): Record<number, any> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the function definitions are a bit more common in the current codebase, we should align everything at some point for consistency. Not blocking for this PR though.

console.log("fetching metadata for table", { table: table.toString(), world: world.address });
const metadataPromise = Promise.all([
registerSchema(world, metadataTableId),
// TODO: figure out how to pass in rawSchema, it was giving me "incorrect length" errors before
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we have to pad the raw schema string to 32 bytes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, but also not too worried since this is a getter and we still have to do both fetch calls anyway

// TODO: figure out how to pass in rawSchema, it was giving me "incorrect length" errors before
world["getRecord(uint256,bytes32[])"](metadataTableId.toHexString(), [table.toHexString()]),
]).then(([metadataSchema, metadataRecord]) => {
// TODO: error if schema or record not found?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we at least log a warning here?

@@ -13,7 +13,7 @@
"prepare": "yarn build && chmod u+x git-install.sh",
"git:install": "bash git-install.sh",
"codegen": "ts-node ./scripts/codegen.ts",
"tablegen": "../cli/dist/mud.js tablegen",
"tablegen": "mud tablegen",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd prefer keeping the local version for this script, so it works in the CI when we do changes to tablegen (without releasing a new version)

Copy link
Member Author

@holic holic Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if, instead, we have CI use a locally linked mud CLI?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work too, we just have to set it up. If it "just works" I'm down to do that instead in this PR, but wouldn't lose too much time on it, we can always change it in a follow up

Copy link
Member Author

@holic holic Mar 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change it back for ease and add an issue to come back to this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -12,7 +12,7 @@
"scripts": {
"prepare": "yarn build && chmod u+x git-install.sh",
"git:install": "bash git-install.sh",
"tablegen": "../cli/dist/mud.js tablegen",
"tablegen": "mud tablegen",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, see comment above (in store/package.json)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@holic holic requested a review from alvrs March 15, 2023 17:45
@@ -19,7 +19,7 @@ export const ecsEventFromLog = async (
const tableId = TableId.fromBytes32(utils.arrayify(args.table));
const component = tableId.toString();
// TODO: revisit key tuple encoding for client
const entity = args.key.join(":") as EntityID;
const entity = `v2:${args.key.join(":")}` as EntityID;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might break something if I want to use v2 with ECS, and want to refer to another entity in my component

Example: OwnedBy component, Bob (0x01) is owned by Alice (0x02), so I have an entry in the OwnedBy table with key 0x01 and value 0x02. Now I want to do an recs query on the client to get all entities owned by Alice, so I do getEntitiesWithValue(OwnedBy, {value: Alice}), but because Alice is normalized to v2:0x02 it wouldn't find the 0x02 value of key 0x01.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in 9c13cd7

Copy link
Member

@alvrs alvrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go!

@holic holic merged commit 374ed54 into main Mar 15, 2023
@alvrs alvrs deleted the holic/sync-store-v2 branch May 18, 2023 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants