-
Notifications
You must be signed in to change notification settings - Fork 188
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
refactor(store,world): replace isStore with storeAddress #1061
Conversation
🦋 Changeset detectedLatest commit: fe49822 The changes in this PR will be included in the next version bump. This PR includes changesets to release 26 packages
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this upped the gas everywhere?
pretty much. It increases StoreSwitch calls by ~300 gas (which means any table interactions); relatively it's not big, but affects everything |
f6625e4
to
caffe53
Compare
is this to help us with the "what context am I running in" issue where tests don't work well with the previous approach? |
8bb1aea
to
fafa599
Compare
fafa599
to
be3c3ac
Compare
yep |
packages/world/src/WorldConsumer.sol
Outdated
@@ -1,11 +1,12 @@ | |||
// SPDX-License-Identifier: MIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Consumer is clearer than Context (which makes me think it's something World inherits, not systems), and it matches StoreConsumer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context was leaning on ERC2771Context where this pattern originates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like Context still makes sense for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i see how Consumer
would also make sense but I'd prefer to keep Context
to draw the analogy to ERC2771Context
packages/store/src/StoreSwitch.sol
Outdated
// Check whether this contract implements the IStore interface | ||
try IStore(address(this)).isStore() { | ||
success = true; | ||
} catch { | ||
success = false; | ||
try IStoreConsumer(address(this)).storeAddress(msg.sender) returns (address _storeAddress) { | ||
return _storeAddress; | ||
} catch (bytes memory lowLevelData) { | ||
// catch and rename the error, otherwise it's usually "EvmError: Revert" which is very unhelpful | ||
revert StoreSwitch_MissingOrInvalidStoreAddressFunction(lowLevelData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an alternative to enforcing IStoreConsumer
would be to fall back on msg.sender
if it's absent. That might help with gas too.
But I like this explicit approach since it gives a nice error instead of confusing behavior down the line, making things hopefully easy to debug (or answer questions about on mud-help
)
I was thinking of exploring the alternative in a followup though, along with other gas optimizations
packages/store/src/StoreConsumer.sol
Outdated
* Default Store consumers consider their caller to be the Store, thus delegating access control to the Store. | ||
* The Store contract considers itself to be the Store (so StoreRead has a different storeAddress definition). | ||
* Tests/scripts may override this value for convenience. | ||
* WARNING: World Systems rely on storeAddress being msg.sender for access control! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we should put this warning here - the Store package should be independent of the World package, and the warning itself is not detailed enough to be helpful without the full context. Maybe we should a more detailed explanation in the docs and link it somewhere in the world package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a comment to WorldConsumer
instead
also agree with docs, should it be in this PR or separate?
storage slot is mostly better (see #1158), rewrote this PR to use storage instead of a method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Just two minor proposed changes for comments. Also let's add a changeset to describe the change.
Co-authored-by: alvarius <[email protected]>
Co-authored-by: alvarius <[email protected]>
Co-authored-by: alvarius <[email protected]>
Co-authored-by: alvarius <[email protected]>
fixes #940
the previous approach used the absence of
isStore
to indicate that the contract isn't the StoreI change it so all store consumers
needuse a storage variable to detect storeAddressstoreAddress
method, and its absence is an errorMoved MudV2Test (otherwise circular dependency) and took the opportunity to rename it to MudTest