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

Use a shared enum for key prefixes #4689

Merged

Conversation

jacek-casper
Copy link
Contributor

@jacek-casper jacek-casper commented May 1, 2024

I need a way to query global state by prefixes for https://app.zenhub.com/workspaces/core-protocol-60953fafb1945f0011a3592d/issues/gh/casper-network/casper-node/4686. The existing code manually encodes byte arrays wherever a lookup by prefix was needed, but that's difficult to keep track of and it's pretty prone to errors, so I decided to create an enum that represents all possible key prefix combinations (excluding ones that are too broad, like querying all system/account/contract entities). This enum allows us to have a single data type for all the prefix lookups. Its deserializer is tested against the Key serializer to ensure that it remains binary compatible with the Key type.

This enum can also be a useful way to expose the capability of querying the GS by a prefix to binary port consumers in a safe way, because we can prevent them from making very large queries (like querying with just a key tag) and we can restrict which KeyPrefix variants we allow in the binary port.

Copy link
Collaborator

Choose a reason for hiding this comment

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

See comments

@EdHastingsCasperAssociation
Copy link
Collaborator

bors r+

casperlabs-bors-ng bot added a commit that referenced this pull request May 3, 2024
4640: burn implemented r=EdHastingsCasperAssociation a=hoffmannjan

Implements casper-network/ceps#92

4689: Use a shared enum for key prefixes r=EdHastingsCasperAssociation a=jacek-casper

I need a way to query global state by prefixes for https://app.zenhub.com/workspaces/core-protocol-60953fafb1945f0011a3592d/issues/gh/casper-network/casper-node/4686. The existing code manually encodes byte arrays wherever a lookup by prefix was needed, but that's difficult to keep track of and it's pretty prone to errors, so I decided to create an enum that represents all possible key prefix combinations (excluding ones that are too broad, like querying all system/account/contract entities). This enum allows us to have a single data type for all the prefix lookups. Its deserializer is tested against the Key serializer to ensure that it remains binary compatible with the `Key` type. 

This enum can also be a useful way to expose the capability of querying the GS by a prefix to binary port consumers in a safe way, because we can prevent them from making very large queries (like querying with just a key tag) and we can restrict which `KeyPrefix` variants we allow in the binary port.

Co-authored-by: Jan Hoffmann <jan@hfmn.pl>
Co-authored-by: Ed Hastings <ed@casperlabs.io>
Co-authored-by: Jacek Malec <145967538+jacek-casper@users.noreply.github.com>
Copy link
Contributor

This PR was included in a batch that successfully built, but then failed to merge into feat-2.0. It will not be retried.

Additional information:

{"message":"Changes must be made through a pull request.","documentation_url":"https://docs.github.com/articles/about-protected-branches"}

@jacek-casper
Copy link
Contributor Author

bors r+

Copy link
Contributor

Build succeeded:

@casperlabs-bors-ng casperlabs-bors-ng bot merged commit 8db0e07 into casper-network:feat-2.0 May 7, 2024
3 checks passed
@jacek-casper jacek-casper deleted the key-prefix-enum branch May 7, 2024 13:45
@devendran-m devendran-m added the rc-2 Release Candidate 2 label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rc-2 Release Candidate 2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants