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(world): add support for upgrading systems #1378

Merged
merged 4 commits into from
Sep 5, 2023
Merged

Conversation

alvrs
Copy link
Member

@alvrs alvrs commented Aug 31, 2023

fixes #1140. Context in the changeset.

TODO:

  • Add tests for upgrading systems
  • Decide on whether we should store the list of addresses with access to a certain resource somewhere to be able to remove access for the previous system. -> I'm tending towards no since granting a system access is a manual action, so it feels wrong to automatically revoke access and grant it to a new system.

TODO in followup: Add CLI support for upgrading systems

@changeset-bot
Copy link

changeset-bot bot commented Aug 31, 2023

🦋 Changeset detected

Latest commit: d172dcb

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

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

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

*/
function registerSystem(bytes32 resourceSelector, WorldContextConsumer system, bool publicAccess) public virtual {
// Require the name to not be the namespace's root name
if (resourceSelector.getName() == ROOT_NAME) revert InvalidSelector(resourceSelector.toString());

// Require the system to not exist yet
if (SystemRegistry.get(address(system)) != 0) revert SystemExists(address(system));
// Require this system to not be registered at a different resource selector yet
Copy link
Member

Choose a reason for hiding this comment

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

ooc why? what if I want the same system in multiple namespaces?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since access control is based on addresses that would be a security risk (namespace A might have given system X access, now you register system X in namespace B without realising it might mean whoever has access to the system based on namespace A can now also call the system to access namespace B)

Copy link
Member

@holic holic Sep 1, 2023

Choose a reason for hiding this comment

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

hmmm, interesting! should we do access based on selector instead of/in addition to address?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since access control is also used for EOAs it couldn't be in instead of address (since EOAs don't have a registered selector). It would probably be possible to have an additional concept of access control based on the selector, but there are more complexities: if a system is registered at two selectors, it's not possible to infer the selector based on the system address (since there is no 1-1 mapping anymore), so a system would have to provide its own selector for every call that requires access control. That would require the system to be aware of where its registered (currently it doesn't care) and might have more security implications. Overall I think it's not worth the additional complexity to allow a system to be registered multiple times.

} else {
// Otherwise, this is a new system, so register its resource type
ResourceType.set(resourceSelector, Resource.SYSTEM);
}
Copy link
Member

@holic holic Sep 1, 2023

Choose a reason for hiding this comment

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

idle thought: I wonder if it's worth encoding the resource type into the selector, so selectors become something like

type (bytes2) + namespace (bytes14) + name (bytes16)

this would save a little on storage (but maybe not in any meaningful way if it's only used during registration) and could help during introspection (it's part of the selector/identifier itself rather than a separate lookup)

(Stripe has this for all IDs where each ID has a prefix of the kind of entity it is, e.g. acct_AbCdEf123 for accounts or ch_AbCdEf123 for charges and it's a really nice human-readability thing)

Copy link
Member Author

Choose a reason for hiding this comment

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

agree that might make sense!

Copy link
Member

Choose a reason for hiding this comment

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

opened an issue here: #1394

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.

implementation looks good, one question around registering the same system at multiple locations (specifically namespaces)

@alvrs alvrs merged commit ce97426 into main Sep 5, 2023
@alvrs alvrs deleted the alvrs/upgrade-systems branch September 5, 2023 09:44
@github-actions github-actions bot mentioned this pull request Sep 5, 2023
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.

Add support for upgrading systems
3 participants