-
Notifications
You must be signed in to change notification settings - Fork 242
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
Create custom serialization for external structs #1020
Comments
There are few other options:
|
In an attempt to better solve ava-labs/subnet-evm#1020, this is an approach to let serialize types with the standard Text or Binary marshal/unmarshal. This is an attempt to have a more robust solution to ava-labs/subnet-evm#1022 (which relies on a feature inside Golang that may generate determinist JSON)
In an attempt to better solve ava-labs/subnet-evm#1020, this is an approach to let serialize types with the standard Text or Binary marshal/unmarshal. This is an attempt to have a more robust solution to ava-labs/subnet-evm#1022 (which relies on a feature inside Golang that may generate determinist JSON)
Some more ideas: Custom Handler In CodecThis involves adding a handler that would check if a certain interface is implemented and call custom serialize/deserialize method. This involves a change to the codec. In this case we should decide which interface to be handled in codec. Possibilities are IMO
That leaves us with Currently none of our required types like We should make sure everything works with this approach before we actually merge anything to the codec. Create an Serializer/Deserializer interface for PrecompileConfigWith this way we can ensure every precompile config implements a serializer/deserializer of their own. This is the safest option because we'd not need to change the codec in AvalancheGo and if a bug occurs this could only impact the Subnet-EVM's config handshake. This could a bit complicated for external developers and we probably still need to use a library/helper method to make those functions a bit standardized and easier than actually encoding/decoding every field in config. Borsh Codec (Reflect codec)@patrick-ogrady suggested we can use this library to serialize/deserialize sturct directly without any change to types (or avago codec) https://github.com/near/borsh-go. This also would require to be tested out with our existing precompiles (and some additional test with common types like |
This is being solved in #762 implementing UnmarshalBinary/MarshalBinary |
Context and scope
As part of #758 and #268, it is needed to support external structures. Our codec uses reflection and serializes only fields which have the
serialize:"true"
tag.That is problematic for external structs, particularly the
big.Int
struct, which is part of the data to be exchanged between nodes or to calculate the upgrade config change. Hashing or exchanging configurations require serialization andbig.Int
is ignored since they don't have anyserialize:"true"
for their inner members.Discussion and alternatives
There are two alternatives proposed in this issue.
serialize:"all"
The easiest approach is introducing yet another patch to our codec, extending it to support
serialize:"all"
.For context, several improvements have already been made to enhance the codec to support the serialization of the config (nullable pointers, deterministic map serialization).
This new tag will be another way of serializing fields (alongside with
serialize:"true"
,serialize:"true,nullable"
). This tag will signal the codec to serialize all inner fields as if they all have theserialize:"true"
tag in each field and inner fields.This change will leverage a lot of the existing code in the codec, and it is backward compatible.
Wrap the
big.Int
The alternative solution would be to have our version of
big.Int
, owned by the package. This type will be converted to a propertybig.Int
for usage after deserialization.This solution would require zero changes in the codec but will require changes in all the codec inside subnet-EVM. This solution would have to be replicated everywhere in the configurations where
big.Int
and any external struct is being read.Open questions
Is there any other alternative?
The text was updated successfully, but these errors were encountered: