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

refactor: generate internal Header.encodeRLP() for override #86

Merged
merged 4 commits into from
Dec 11, 2024

Conversation

ARR4N
Copy link
Collaborator

@ARR4N ARR4N commented Dec 10, 2024

Why this should be merged

This is a precursor to being able to override types.Header RLP {en,de}coding. As there is already a Header.EncodeRLP() method we either have to modify the generated code or rename the generated method—this PR does the latter.

How this works

The rlpgen -internal_methods flag changes the generated methods from EncodeRLP() and DecodeRLP() to encodeRLP() and decodeRLP(), respectively. A new CI job checks that generated code is up to date. We can then implement our own Header.EncodeRLP() that either overrides or falls back on the original.

It appears that core/gen_genesis.go was out of date but only because of formatting.

How this was tested

I deliberately excluded the change to core/types/gen_header_rlp.go to confirm that the new workflow detects the change and fails. The actual change can be inspected via the code diff.

@ARR4N ARR4N marked this pull request as ready for review December 10, 2024 15:58
@ARR4N ARR4N requested review from a team, darioush, ceyonur and michaelkaplan13 and removed request for a team December 10, 2024 16:04
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21.4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit shouldn't we stay on 1.20 given that's what in the go.mod? 🤔

Copy link
Collaborator Author

@ARR4N ARR4N Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both the go.mod and the go.yml inherit their versions from upstream v1.13.14 for now. I'm happy to look at changing them but think we should consider it more thoroughly first.

If you want to send a PR that uses a matrix strategy for multiple versions I think that will be the best of both worlds. Please try to keep the pull_request to main workflow trigger fast / limited to one version and leave the multi-version tests to main push + everything to release/* (I'm not 100% sure this is possible, but it would be nice for PRs to not have to wait half an hour).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to support/check it works on versions above the one in go.mod though? When we later sync with geth, we can just bump all CI versions to the geth go.mod version (and CI may or may not fail). I'm creating (slowly) an issue to list CI checks we could add for post-syncing, for example keeping go-version of CI jobs in sync with go.mod (perhaps dependabot does it). Maybe a more appropriate PR would be to pin all go-version of jobs to 1.20? 🤔

Comment on lines +39 to +40
- name: Run `go generate`
run: go list ./... | grep -Pv "${EXCLUDE_REGEX}" | xargs go generate;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the -skip flag I think:

Suggested change
- name: Run `go generate`
run: go list ./... | grep -Pv "${EXCLUDE_REGEX}" | xargs go generate;
- run: go generate -skip "${EXCLUDE_REGEX}" ./...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, TIL about -skip. This doesn't work for me locally though (I suspect because the regex needs to change):

$ go generate -skip 'ava-labs/libevm/(accounts/usbwallet/trezor)$' ./...
/usr/local/include: warning: directory does not exist.
protoc-gen-go: no such flag -import_path
--go_out: protoc-gen-go: Plugin failed with status code 1.
accounts/usbwallet/trezor/trezor.go:45: running "protoc": exit status 1

If you add the matrix strategy and switching to -skip is simple then please include it, but I think it should be timeboxed as it's low yield.

Copy link
Collaborator

@qdm12 qdm12 Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies, similarly to -run, it's for the source text in the //go:generate statement, not the file path. Better to keep it as it is!

core/gen_genesis.go Show resolved Hide resolved
rlp/rlpgen/gen.go Show resolved Hide resolved
@ARR4N ARR4N merged commit aa183c5 into main Dec 11, 2024
4 checks passed
@ARR4N ARR4N deleted the arr4n/rlpgen-internal-methods branch December 11, 2024 10:21
@ARR4N ARR4N mentioned this pull request Dec 16, 2024
ARR4N added a commit that referenced this pull request Dec 17, 2024
## Why this should be merged

Replaces #86. That approach couldn't be replicated for generated JSON
marshalling, and this once also reduces the upstream delta.

## How this works

AST manipulation of a specified file, which finds specified methods and
modifies their names to be unexported.

## How this was tested

Inspection of the output (`core/types/gen_header_rlp.go` remains
unchanged).
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.

3 participants