go-ethereum/common
Arran Schlosberg eda3b59f67
feat(core/types): fine-grained Body RLP override (#109)
## Why this should be merged

Allows for modification of `types.Body` payload data + RLP encoding
without placing the entire RLP burden on the `libevm` user as we did
with `types.HeaderHooks`.

## How this works

RLP encoding of a struct is simply a concatenation of RLP encodings of
fields, encompassed by an RLP "list". The
`AppendRLPFields(rlp.EncoderBuffer, ...)` hook exploits this and plugs
in before all `rlp:"optional"`-tagged fields to allow for inclusion of
any new fields. The `EncoderBuffer` SHOULD be used as the `io.Writer`
passed when encoding each field: `rlp.Encode(buffer, fieldValue)`.

`Body` doesn't have `{En,De}codeRLP` methods so they are implemented to
identically replicate original behaviour when a no-op hook is present.

This pattern is sufficient for the `ava-labs/coreth` modifications of
`Body` but can be modified / extended for more complex scenarios, like
`Header`.

> [!NOTE]
> This PR does not include registration of the hooks as that was not the
initial goal and adding them would create too much PR bloat. There is a
placeholder `var todoRegisteredBodyHooks` global variable that can only
be set in tests.

## How this was tested

- Backwards compatibility: the new methods are fuzzed against a `type
withoutMethods Body` passed directly to `rlp.{En,De}code()`
- `coreth` compatibility: unit test of a local implementation of
`BodyHooks` demonstrating reproducibility of RLP encoding.

---------

Signed-off-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@avalabs.org>
2025-02-05 10:52:28 +00:00
..
bitutil [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
compiler common/compiler: json unmarshalling error checks (#25449) 2022-08-01 13:47:21 +02:00
fdlimit fix: linter warning (#25192) 2022-06-29 10:54:57 +02:00
hexutil [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
lru common/lru: add test case for BasicLRU.Peek (#27559) 2023-06-27 10:27:40 +02:00
math [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
mclock common/mclock: add Alarm (#26333) 2023-01-03 12:10:48 +01:00
prque [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
big.go all: use uint256 in state (#28598) 2024-01-23 14:51:58 +01:00
bytes.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
bytes_test.go all: simplify and fix database iteration with prefix/start (#20808) 2020-04-15 14:08:53 +03:00
debug.go common: rename unused function with typo (#23025) 2021-06-10 10:53:23 +03:00
format.go common: improve pretty duration regex (#25073) 2022-06-14 14:08:43 +02:00
path.go common: delete MakeName (#27023) 2023-04-03 03:51:31 -04:00
pointer.libevm.go feat(core/types): fine-grained Body RLP override (#109) 2025-02-05 10:52:28 +00:00
size.go core, cmd, vendor: fixes and database inspection tool (#15) 2019-05-16 10:39:34 +03:00
size_test.go common: increase StorageSize test coverage (#25188) 2022-06-29 12:13:00 +02:00
test_utils.go all: replace uses of ioutil with io and os (#24869) 2022-05-16 11:59:35 +02:00
types.go [AUTO] rename Go module + update internal import paths 2024-10-17 01:49:47 +00:00
types_test.go log: avoid stack lookups when not needed/used (#28069) 2023-09-07 08:48:49 -04:00