Skip to content

Create custom serialization for external structs #1020

@nytzuga

Description

@nytzuga

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 and big.Int is ignored since they don't have any serialize:"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 the serialize:"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 property big.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?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Done 🎉

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions