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

Dynamic struct tags to support different chain specifications #23

Open
pinebit opened this issue Aug 15, 2024 · 3 comments
Open

Dynamic struct tags to support different chain specifications #23

pinebit opened this issue Aug 15, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@pinebit
Copy link

pinebit commented Aug 15, 2024

For some chains like Gnosis, different field specs are defined (example).
A notable example is

Withdrawals   []*Withdrawal ssz-max:"16"`

which has ssz-max=16 for Ethereum networks and ssz-max=8 for Gnosis (yet there are other differences). This changes serialization and hashing results, which makes derived products not supporting chains other than Ethereum.

Is there a workaround for such the specific chains (Gnosis)?
The only viable option as it seems is to build two/three/more copies of objects (structs) having different struct attributes..

Other projects (Lodestar, Teku..) do support this. Here is how the above example is handled by Teku: https://github.com/Consensys/teku/blob/777c9dc7bbaa2f563e870b5fa277e48472e234ae/ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/versions/capella/ExecutionPayloadSchemaCapella.java#L104

@itsdevbear
Copy link
Contributor

Imo, this should be done via the codec / fork stuff, so it can be defined at runtime.

@karalabe
Copy link
Owner

I'll think about this a bit. One gut reaction is that why would you want to share data structures between gnosis and non-gnosis chains if they are "structurally different"? I mean the generated code/encoding will need to be different, so the only advantage is having a single source definition. Not per say bad, but it's a use case I haven't considered yet.

@karalabe
Copy link
Owner

Hmm, the linked Java code seems to be the literal encoder. You could do the same thing with this ssz lib if you wrote your own DefineSSZ method instead of generating one from Go tags; switching on some chain spec param manually. Supporting variables inside the generator seems a bit of a can of worms.

@itsdevbear's idea with forks will probably not work as in this case you'd want to have a different code within the same fork across different networks. Again, I could perhaps expand the fork support with other dimensionality, but I'm afraid that even like this it's getting a bit messy and should only be used for monolith types.

My gut reaction is that you have two workarounds:

  • Define two separate types and generate the code for them
  • Have a single type but manually write the DefineSSZ

Whilst neither is the "best", I'm trying to figure out the monoliths first, so it might take a while until I hit this issue. Will keep the issue open nonetheless, but don't expect a quick resolution apart of the two workarounds. :D

@karalabe karalabe added the enhancement New feature or request label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants