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

Key hashing compatibility #333

Merged
merged 6 commits into from
Apr 8, 2020
Merged

Key hashing compatibility #333

merged 6 commits into from
Apr 8, 2020

Conversation

austinabell
Copy link
Contributor

@austinabell austinabell commented Apr 6, 2020

Summary of changes
Changes introduced in this pull request:

  • In go impls, they use a string as the key for the hamt despite the fact that it is really non utf-8 bytes. To solve this, there is the custom type introduced in this PR (BytesKey but open to a better name) for the type of the key to match.
    -The constraints on this type is that it has to hash the same as go implementation and that it serializes the same. str and [u8] hash the same with our impl so it's fine to use bytes as the hash type and that matches, and to get the serialization to match the bytes need to be unsafely converting to a string before serialization.
    • To clarify, a custom type would have to be created anyway even if go impls switch to using a byte slice as keys because a u8 slice serializes as an array of u8 by default, so this isn't all wasted work

Edit: go impl changed to serialize keys as bytes, so this update changes key type used within Actors

Reference issue to close (if applicable)

Closes
#324

Other information and links

Some(v) => v.0 + value,
None => value,
};
Ok(self.0.set(key.hash_key(), BigUintDe(new_val))?)
Ok(self.0.set(key.to_bytes().into(), BigUintDe(new_val))?)
Copy link
Contributor

Choose a reason for hiding this comment

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

you could just implement impl<T: AsRef<str>> From<T> for BytesKey and avoid all these to_bytes calls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm, I don't think this helps, I'm not sure if you're seeing that the key is of the address type, it is being converted into a Vec<u8> and then the into() is putting it as the wrapper type used as a key here (BytesKey) which is specifically needed to ensure the string serialization of those bytes.

Edit: Yeah this wouldn't work because Address should (and could) never be AsRef<str>. I also do not like how there is this chained call, but I wanted to keep the Address and Key type seperate

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah sorry, .to_bytes() made me think it was a string,

vm/actor/src/lib.rs Outdated Show resolved Hide resolved
@austinabell
Copy link
Contributor Author

Gonna let this PR hang for a bit, was indicated that the key serialization is going to be fixed in go impls, so might as well put this on ice to not have to revisit

@austinabell
Copy link
Contributor Author

bs_ask

Copy link
Contributor

@dignifiedquire dignifiedquire left a comment

Choose a reason for hiding this comment

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

So much nicer than the previous version 👏

@austinabell austinabell merged commit 3bc7d41 into master Apr 8, 2020
@austinabell austinabell deleted the austin/hashkey branch April 8, 2020 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants