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: add pushToField to Store and World #434

Merged
merged 6 commits into from
Mar 8, 2023
Merged

feat: add pushToField to Store and World #434

merged 6 commits into from
Mar 8, 2023

Conversation

dk1a
Copy link
Contributor

@dk1a dk1a commented Feb 23, 2023

Intentionally not adding a new event, but the method's logic accounts for it being added in the future with minimal changes to StoreCore and no changes to World etc (so it could be mostly a network PR)

Notably this allows pushing multiple items at once
No validity checks though (same as setField, they should be added in one separate refactor I think)

_verifiedTableRouteId, _expectRouteAccessDenied and _initRouteTableKey:
I basically want to reduce code repetition in World but I don't want to complicate this PR by refactoring things unrelated to pushToStore yet

setItem and pop could happen in the future, but rn I just need push for proper autogen

@dk1a dk1a requested review from alvrs and holic as code owners February 23, 2023 20:40
holic
holic previously approved these changes Feb 23, 2023
Copy link
Member

@holic holic left a comment

Choose a reason for hiding this comment

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

lgtm!

@@ -48,7 +48,6 @@ library AddressArray_ {

/**
* Push an element to the addresses array
* TODO: this is super inefficient right now, need to add support for pushing to arrays to the store core library to avoid reading/writing the entire array
Copy link
Member

Choose a reason for hiding this comment

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

Curious to see if we have gas tests for before/after this change to see how much more efficient this method is compared to the previous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The real change would be when a separate event is added. Right now there's still a redundant full storage read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there should be a gasreport for these changes too though (there're some for push too), wonder why it didn't get added

@alvrs
Copy link
Member

alvrs commented Feb 28, 2023

we need to rebase this one on main now

@dk1a dk1a force-pushed the dk1a/v2-array-push branch from 8000645 to a561c35 Compare March 1, 2023 21:05
@dk1a dk1a requested a review from a user March 1, 2023 21:05
@dk1a dk1a changed the base branch from v2 to main March 1, 2023 21:06
@dk1a dk1a force-pushed the dk1a/v2-array-push branch from a561c35 to 1779869 Compare March 2, 2023 22:22
alvrs
alvrs previously approved these changes Mar 6, 2023
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.

Looks good overall, just a couple smaller nits

packages/store/src/StoreCore.sol Outdated Show resolved Hide resolved
packages/store/src/StoreCore.sol Show resolved Hide resolved
* and return `tableRouteId` for `accessRoute/subRoute`
* because access to a route also grants access to all sub routes.
*/
function _verifiedTableRouteId(string calldata accessRoute, string calldata subRoute)
Copy link
Member

Choose a reason for hiding this comment

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

might make sense to use this internal function for other methods in here too. Would leave that for a follow up though, thinking about slightly changing the accessRoute/subRoute pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep I made it to remove code repetition but didn't wanna bloat this PR

@@ -83,6 +81,6 @@ library AddressArraySchemaLib {

function decode(bytes memory blob) internal pure returns (address[] memory addresses) {
if (blob.length == 0) return new address[](0);
SliceLib.getSubslice(blob, 32).decodeArray_address();
return SliceLib.getSubslice(blob, 32).decodeArray_address();
Copy link
Member

Choose a reason for hiding this comment

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

Good catch - is this schema used anywhere? Weird that this wasn't caught by any tests..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it broke something for me, which is how I noticed it. Don't remember what though, could have even been some temporary test I used AddressArray for

packages/world/test/World.t.sol Outdated Show resolved Hide resolved
vm.expectRevert(abi.encodeWithSelector(World.RouteAccessDenied.selector, route, caller));
}

function _initRouteTableKey(
Copy link
Member

Choose a reason for hiding this comment

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

This is a personal preference, but I'm not the biggest fan of helper functions in tests. They reduce verbosity, but in tests I prefer to see everything that happens explicitly without having to check the logic of a helper function. And if helper functions in tests become more complex, we would need to add tests for the helper functions too haha.

This helper function is simple enough to keep it if you feel strongly about it though.

Copy link
Contributor Author

@dk1a dk1a Mar 6, 2023

Choose a reason for hiding this comment

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

agree in general, and for _initRouteTableKey specifically, see #434 (comment)

for _expectRouteAccessDenied I think it's an exception. It's used a lot (12 times) with the same pattern. caller is used twice there, so without an internal method higher risk of making a mistake. Also changed it to prank+expectRevert (it was even longer with startPrank+expectRevert+stopPrank, which is yet another mistake risk).
So I refactored it more, to use _expectRouteAccessDenied in all 12 cases

@dk1a dk1a mentioned this pull request Mar 6, 2023
22 tasks
@dk1a dk1a force-pushed the dk1a/v2-array-push branch from b39897d to 05b8ec2 Compare March 6, 2023 23:31
alvrs
alvrs previously approved these changes Mar 8, 2023
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.

Looks good! Let's merge this before #467

@alvrs
Copy link
Member

alvrs commented Mar 8, 2023

Looks like we need to resolve the gas-report conflicts with main (easiest way would be to merge main into this and just rerun the gas report)

@alvrs alvrs changed the title feat: add pushToField to Store feat: add pushToField to Store and World Mar 8, 2023
@alvrs alvrs merged commit b665efc into main Mar 8, 2023
@dk1a dk1a deleted the dk1a/v2-array-push branch May 9, 2023 16:23
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