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

feat: params.ChainConfig and params.Rules extra payloads #1

Merged
merged 10 commits into from
Sep 10, 2024

Conversation

ARR4N
Copy link
Collaborator

@ARR4N ARR4N commented Aug 23, 2024

Why this should be merged

The params.ChainConfig and params.Rules types are (possibly the most) widely used configuration structs in geth. This makes them ideal candidates for carrying arbitrary data payloads without altering geth plumbing. This PR introduces a method for adding arbitrary payloads that is:

  1. Minimally destructive to existing geth code;
  2. Type safe for the end user;
  3. Configurable from outside of the entire Go module via a registration pattern, thus avoiding circular dependencies; and
  4. Amenable to extension to also carry hooks.

Note

This chain of PRs will all be merged into the arr4n/libevm branch, which will itself be squash-merged into libevm. This keeps the commit history intact so each PR's diff base will automatically update.

How this works

Start by reviewing params/example.libevm_test.go for the intended usage.

Both ChainConfig and Rules have extra fields added to them to carry the payloads. Without making the structs generic, some mechanism must exist for indicating the concrete types of the fields when constructing new instances (including JSON unmarshalling). The new params.RegisterExtras[C,R]() function allows for registration of all the necessary types and logic for construction.

Although the extra fields could have been regular interfaces, this left them too vulnerable to unintentional override with arbitrary values. The pseudo package was thus introduced and its rationale is explained in its package comment. However, its usage is entirely hidden and MUST remain so; a primary goal of this implementation was to make the exported API easy to use and hard to misuse.

In follow-up PRs, C and R type parameters will no longer be any but interfaces required to add other configurable behaviour via hooks. See:

How this was tested

Unit tests of new functionality, without modification of existing geth tests. A testable example acts as an integration test.

@ARR4N ARR4N added the Status: 🔴 DO NOT MERGE This PR is not meant to be merged in its current state label Aug 23, 2024
@ARR4N ARR4N force-pushed the arr4n/libevm-params-extras branch from 5781184 to a6742fd Compare September 8, 2024 16:35
@ARR4N ARR4N changed the base branch from arr4n/libevm to libevm September 8, 2024 16:35
@ARR4N ARR4N changed the base branch from libevm to arr4n/libevm September 9, 2024 12:46
@ARR4N ARR4N marked this pull request as ready for review September 9, 2024 13:18
@ARR4N ARR4N requested review from darioush and ceyonur September 9, 2024 13:18
@ARR4N ARR4N removed the Status: 🔴 DO NOT MERGE This PR is not meant to be merged in its current state label Sep 9, 2024
@darioush darioush changed the base branch from arr4n/libevm to libevm September 9, 2024 20:04
@darioush darioush changed the base branch from libevm to arr4n/libevm September 9, 2024 20:32
@ARR4N ARR4N merged commit 9c2c214 into arr4n/libevm Sep 10, 2024
@ARR4N ARR4N deleted the arr4n/libevm-params-extras branch September 10, 2024 16:00
ARR4N added a commit that referenced this pull request Dec 17, 2024
## Why this should be merged

The `types.Header` fields of both
[`coreth`](https://pkg.go.dev/github.com/ava-labs/coreth/core/types#Header)
and
[`subnet-evm`](https://pkg.go.dev/github.com/ava-labs/subnet-evm/core/types#Header)
have been modified such that their RLP encodings (i.e. block hashes)
aren't compatible with vanilla `geth` nor each other. This PR adds
support for arbitrary RLP encoding coupled with type-safe extra
payloads.

## How this works

Equivalent to #1 (`params`) and #44 (`types.StateAccount`) registration
of pseudo-generic payloads. The only major difference is the guarantee
of a non-nil payload pointer, which means that the payload hooks are
never called on nil pointers as this would make it difficult to decode
RLP into them.

## How this was tested

Round-trip RLP {en,de}coding via a registered stub hook.

---------

Signed-off-by: Arran Schlosberg <[email protected]>
Co-authored-by: Quentin McGaw <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants