Skip to content

Commit

Permalink
fix(store): emit event after calling beforeSetRecord hook [L-02] (#2017)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
  • Loading branch information
yonadaaa and holic committed Jan 12, 2024
1 parent ca01b29 commit c6c13f2
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 125 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-ads-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store": patch
---

Storage events are now emitted after "before" hooks, so that the resulting logs are now correctly ordered and reflect onchain logic. This resolves issues with store writes and event emissions happening in "before" hooks.
78 changes: 39 additions & 39 deletions packages/store/gas-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"file": "test/Callbacks.t.sol",
"test": "testSetAndGet",
"name": "Callbacks: set field",
"gasUsed": 56256
"gasUsed": 56271
},
{
"file": "test/Callbacks.t.sol",
Expand All @@ -75,7 +75,7 @@
"file": "test/Callbacks.t.sol",
"test": "testSetAndGet",
"name": "Callbacks: push 1 element",
"gasUsed": 32514
"gasUsed": 32530
},
{
"file": "test/FieldLayout.t.sol",
Expand Down Expand Up @@ -369,7 +369,7 @@
"file": "test/KeyEncoding.t.sol",
"test": "testRegisterAndGetFieldLayout",
"name": "register KeyEncoding table",
"gasUsed": 719032
"gasUsed": 719062
},
{
"file": "test/Mixed.t.sol",
Expand All @@ -393,7 +393,7 @@
"file": "test/Mixed.t.sol",
"test": "testSetGetDeleteExternal",
"name": "set record in Mixed (external, cold)",
"gasUsed": 108527
"gasUsed": 108528
},
{
"file": "test/Mixed.t.sol",
Expand All @@ -411,7 +411,7 @@
"file": "test/Mixed.t.sol",
"test": "testSetGetDeleteInternal",
"name": "set record in Mixed (internal, cold)",
"gasUsed": 103281
"gasUsed": 103282
},
{
"file": "test/Mixed.t.sol",
Expand Down Expand Up @@ -669,25 +669,25 @@
"file": "test/StoreCoreDynamic.t.sol",
"test": "testPopFromSecondField",
"name": "pop from field (cold, 1 slot, 1 uint32 item)",
"gasUsed": 18032
"gasUsed": 18041
},
{
"file": "test/StoreCoreDynamic.t.sol",
"test": "testPopFromSecondField",
"name": "pop from field (warm, 1 slot, 1 uint32 item)",
"gasUsed": 12039
"gasUsed": 12049
},
{
"file": "test/StoreCoreDynamic.t.sol",
"test": "testPopFromThirdField",
"name": "pop from field (cold, 2 slots, 10 uint32 items)",
"gasUsed": 15800
"gasUsed": 15810
},
{
"file": "test/StoreCoreDynamic.t.sol",
"test": "testPopFromThirdField",
"name": "pop from field (warm, 2 slots, 10 uint32 items)",
"gasUsed": 11807
"gasUsed": 11818
},
{
"file": "test/StoreCoreGas.t.sol",
Expand Down Expand Up @@ -759,13 +759,13 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testHooks",
"name": "set record on table with subscriber",
"gasUsed": 72361
"gasUsed": 72385
},
{
"file": "test/StoreCoreGas.t.sol",
"test": "testHooks",
"name": "set static field on table with subscriber",
"gasUsed": 19813
"gasUsed": 19837
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -783,13 +783,13 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testHooksDynamicData",
"name": "set (dynamic) record on table with subscriber",
"gasUsed": 165516
"gasUsed": 165525
},
{
"file": "test/StoreCoreGas.t.sol",
"test": "testHooksDynamicData",
"name": "set (dynamic) field on table with subscriber",
"gasUsed": 24424
"gasUsed": 24446
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -801,19 +801,19 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testPushToDynamicField",
"name": "push to field (1 slot, 1 uint32 item)",
"gasUsed": 9459
"gasUsed": 9475
},
{
"file": "test/StoreCoreGas.t.sol",
"test": "testPushToDynamicField",
"name": "push to field (2 slots, 10 uint32 items)",
"gasUsed": 32129
"gasUsed": 32150
},
{
"file": "test/StoreCoreGas.t.sol",
"test": "testRegisterAndGetFieldLayout",
"name": "StoreCore: register table",
"gasUsed": 640914
"gasUsed": 640944
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -837,7 +837,7 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testSetAndGetDynamicData",
"name": "set complex record with dynamic data (4 slots)",
"gasUsed": 102512
"gasUsed": 102513
},
{
"file": "test/StoreCoreGas.t.sol",
Expand Down Expand Up @@ -879,7 +879,7 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testSetAndGetField",
"name": "set static field (1 slot)",
"gasUsed": 31224
"gasUsed": 31252
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -891,7 +891,7 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testSetAndGetField",
"name": "set static field (overlap 2 slot)",
"gasUsed": 29877
"gasUsed": 29908
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -903,7 +903,7 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testSetAndGetField",
"name": "set dynamic field (1 slot, first dynamic field)",
"gasUsed": 53945
"gasUsed": 53961
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -915,7 +915,7 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testSetAndGetField",
"name": "set dynamic field (1 slot, second dynamic field)",
"gasUsed": 32168
"gasUsed": 32186
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -927,7 +927,7 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testSetAndGetStaticData",
"name": "set static record (1 slot)",
"gasUsed": 32756
"gasUsed": 32782
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -939,7 +939,7 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testSetAndGetStaticDataSpanningWords",
"name": "set static record (2 slots)",
"gasUsed": 55260
"gasUsed": 55289
},
{
"file": "test/StoreCoreGas.t.sol",
Expand All @@ -951,19 +951,19 @@
"file": "test/StoreCoreGas.t.sol",
"test": "testSetDataOffchainTable",
"name": "StoreCore: set record in offchain table",
"gasUsed": 8082
"gasUsed": 8093
},
{
"file": "test/StoreCoreGas.t.sol",
"test": "testUpdateInDynamicField",
"name": "update in field (1 slot, 1 uint32 item)",
"gasUsed": 8807
"gasUsed": 8835
},
{
"file": "test/StoreCoreGas.t.sol",
"test": "testUpdateInDynamicField",
"name": "push to field (2 slots, 6 uint64 items)",
"gasUsed": 9253
"gasUsed": 9282
},
{
"file": "test/StoreHook.t.sol",
Expand Down Expand Up @@ -993,13 +993,13 @@
"file": "test/StoreHooks.t.sol",
"test": "testOneSlot",
"name": "StoreHooks: set field with one elements (cold)",
"gasUsed": 58262
"gasUsed": 58275
},
{
"file": "test/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: set field (cold)",
"gasUsed": 58262
"gasUsed": 58275
},
{
"file": "test/StoreHooks.t.sol",
Expand All @@ -1011,25 +1011,25 @@
"file": "test/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: push 1 element (cold)",
"gasUsed": 12612
"gasUsed": 12626
},
{
"file": "test/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: pop 1 element (warm)",
"gasUsed": 9946
"gasUsed": 9958
},
{
"file": "test/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: push 1 element (warm)",
"gasUsed": 10629
"gasUsed": 10646
},
{
"file": "test/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: update 1 element (warm)",
"gasUsed": 29855
"gasUsed": 29886
},
{
"file": "test/StoreHooks.t.sol",
Expand All @@ -1041,19 +1041,19 @@
"file": "test/StoreHooks.t.sol",
"test": "testTable",
"name": "StoreHooks: set field (warm)",
"gasUsed": 30407
"gasUsed": 30427
},
{
"file": "test/StoreHooks.t.sol",
"test": "testThreeSlots",
"name": "StoreHooks: set field with three elements (cold)",
"gasUsed": 80950
"gasUsed": 80966
},
{
"file": "test/StoreHooks.t.sol",
"test": "testTwoSlots",
"name": "StoreHooks: set field with two elements (cold)",
"gasUsed": 80862
"gasUsed": 80878
},
{
"file": "test/StoreHooksColdLoad.t.sol",
Expand Down Expand Up @@ -1083,13 +1083,13 @@
"file": "test/StoreHooksColdLoad.t.sol",
"test": "testPop",
"name": "StoreHooks: pop 1 element (cold)",
"gasUsed": 18381
"gasUsed": 18390
},
{
"file": "test/StoreHooksColdLoad.t.sol",
"test": "testUpdate",
"name": "StoreHooks: update 1 element (cold)",
"gasUsed": 20310
"gasUsed": 20333
},
{
"file": "test/StoreSwitch.t.sol",
Expand Down Expand Up @@ -1155,13 +1155,13 @@
"file": "test/Vector2.t.sol",
"test": "testRegisterAndGetFieldLayout",
"name": "register Vector2 field layout",
"gasUsed": 442418
"gasUsed": 442447
},
{
"file": "test/Vector2.t.sol",
"test": "testSetAndGet",
"name": "set Vector2 record",
"gasUsed": 33658
"gasUsed": 33684
},
{
"file": "test/Vector2.t.sol",
Expand Down
Loading

0 comments on commit c6c13f2

Please sign in to comment.