-
Notifications
You must be signed in to change notification settings - Fork 51
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
MarshalSSZTo and other incompatibilities with fastssz #170
Comments
Thanks for the heads-up! |
As for this, nothing we can do here. As the comment on
That is, out of the methods in the type HashRoot interface {
GetTree() (*Node, error)
HashTreeRoot() ([32]byte, error)
HashTreeRootWith(hh HashWalker) error
}
|
You know, taking a step back, the whole situation is disappointing, as the interface should expect a function that marshals ssz into a preallocated buffer. Maybe it does If fastssz wants to live up to its name, maybe we can change the upstream interface to require a new That way fastssz can preallocate and no extra copies need be made. At any rate, I'm on a quick two week vacation, so i can't tell you immediately why an alias or struct with anonymous field didn't work with sszgen, but i did attempt it previously. It was before I moved the wrapper into its own package though, so maybe it works that way (aside from this bug). |
How so? I think it's fair to expect the marshalling to append to the buffer, that's how a lot of encoders work. With ssz, we also have the size, so the caller can easily ensure that there's no realloc by just providing a buffer with correct capacity. This is (mostly) fixed in #171 . At some point in the future, I'll add back the |
Fast ssz now expects
HashTreeRootWith(hh ssz.HashWalker) (err error)
in itsHashTreeRoot
interface. I believe the implementation is as simple as:but I have been known to make mistakes.
Further, fastssz's
MarshalSSZTo(buf []byte) ([]byte, error)
interface function expects the implementation to append to the end ofbuf
, not to overwrite it. Unfortunately, this library overwrites instead, and a wrapper is needed (one is needed anyway for sszgen to work):The text was updated successfully, but these errors were encountered: