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

fix(store): emit event after calling beforeSetRecord hook [L-02] #2017

Merged
merged 24 commits into from
Jan 12, 2024

Conversation

yonadaa
Copy link
Contributor

@yonadaa yonadaa commented Dec 5, 2023

Rearranges setRecord, spliceStaticData, and _spliceDynamicData in StoreCore to emit the storage event after calling the beforeSetRecord hook, ensuring that storage events are emitted in the same order that values are stored on-chain.

An important side-effect is that off-chain tables also early return after the hook, which means they can now use the beforeSetRecord hook. I think this is okay because hooks do not necessarily need to read the current storage; they can just react to the new value. EDIT: registering before hooks for offchain tables is explicitly not allowed so this is a no-op

@yonadaa yonadaa requested review from alvrs and holic as code owners December 5, 2023 15:20
Copy link

changeset-bot bot commented Dec 5, 2023

🦋 Changeset detected

Latest commit: ea87f34

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@latticexyz/store Patch
@latticexyz/cli Patch
@latticexyz/dev-tools Patch
@latticexyz/react Patch
@latticexyz/store-indexer Patch
@latticexyz/store-sync Patch
@latticexyz/world-modules Patch
@latticexyz/world Patch
@latticexyz/abi-ts Patch
@latticexyz/block-logs-stream Patch
@latticexyz/common Patch
@latticexyz/config Patch
create-mud Patch
@latticexyz/ecs-browser Patch
@latticexyz/faucet Patch
@latticexyz/gas-report Patch
@latticexyz/network Patch
@latticexyz/noise Patch
@latticexyz/phaserx Patch
@latticexyz/protocol-parser Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
@latticexyz/services Patch
@latticexyz/solecs Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/std-client Patch
@latticexyz/std-contracts Patch
@latticexyz/store-cache Patch
@latticexyz/utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

lgtm, let's just remove the unrelated docs changes, add a changeset, and update the gas report

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.

Just realized we also need to apply this change to the deleteRecord function

Comment on lines -586 to -588
// Emit event to notify indexers
emit Store_DeleteRecord(tableId, keyTuple);

Copy link
Member

Choose a reason for hiding this comment

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

we also need to move the early return for offchain tables below the event emission, otherwise there is no event emitted for offchain tables (and the onBefore hook is not triggered)

Copy link
Member

Choose a reason for hiding this comment

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

can we add a test for this to make sure we don't regress?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a couple tests

@yonadaa yonadaa marked this pull request as draft January 9, 2024 16:54
@yonadaa yonadaa marked this pull request as ready for review January 12, 2024 12:29
.changeset/beige-ads-melt.md Outdated Show resolved Hide resolved
@holic holic merged commit c6c13f2 into main Jan 12, 2024
11 checks passed
@holic holic deleted the yonadaaa/emit-event-after-hook branch January 12, 2024 15:57
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.

3 participants