Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 2be5a7b

Browse files
committed
feat(core/types): Body hooks for RLP encoding
1 parent f133755 commit 2be5a7b

File tree

6 files changed

+86
-6
lines changed

6 files changed

+86
-6
lines changed

accounts/abi/bind/bind_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,7 @@ func golangBindings(t *testing.T, overload bool) {
21792179
if out, err := replacer.CombinedOutput(); err != nil {
21802180
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
21812181
}
2182-
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/[email protected]", "-replace", "github.com/ava-labs/libevm=github.com/ava-labs/[email protected]20250113230013-d10c4a3d1ff2")
2182+
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/[email protected]", "-replace", "github.com/ava-labs/libevm=github.com/ava-labs/[email protected]20250121171435-edebe134329f")
21832183
replacer.Dir = pkg
21842184
if out, err := replacer.CombinedOutput(); err != nil {
21852185
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)

core/types/body_ext.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// (c) 2024, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package types
5+
6+
import (
7+
"io"
8+
9+
ethtypes "github.com/ava-labs/libevm/core/types"
10+
"github.com/ava-labs/libevm/rlp"
11+
)
12+
13+
// BodyExtra is a struct that contains extra fields used by Avalanche
14+
// in the body.
15+
// This type uses BodySerializable to encode and decode the extra fields
16+
// along with the upstream type for compatibility with existing network blocks.
17+
type BodyExtra struct {
18+
version uint32
19+
extData *[]byte
20+
21+
// Fields removed from geth:
22+
// - withdrawals Withdrawals
23+
}
24+
25+
func (b *BodyExtra) EncodeRLP(eth *ethtypes.Body, writer io.Writer) error {
26+
out := new(bodySerializable)
27+
28+
out.updateFromEth(eth)
29+
out.updateFromExtras(b)
30+
31+
return rlp.Encode(writer, out)
32+
}
33+
34+
func (b *BodyExtra) DecodeRLP(eth *ethtypes.Body, stream *rlp.Stream) error {
35+
in := new(bodySerializable)
36+
if err := stream.Decode(in); err != nil {
37+
return err
38+
}
39+
40+
in.updateToEth(eth)
41+
in.updateToExtras(b)
42+
43+
return nil
44+
}
45+
46+
// bodySerializable defines the body in the Ethereum blockchain,
47+
// as it is to be serialized into RLP.
48+
type bodySerializable struct {
49+
Transactions []*Transaction
50+
Uncles []*Header
51+
Version uint32
52+
ExtData *[]byte `rlp:"nil"`
53+
}
54+
55+
// updateFromEth updates the [*bodySerializable] from the [*ethtypes.Body].
56+
func (b *bodySerializable) updateFromEth(eth *ethtypes.Body) {
57+
b.Transactions = eth.Transactions
58+
b.Uncles = eth.Uncles
59+
}
60+
61+
// updateToEth updates the [*ethtypes.Body] from the [*bodySerializable].
62+
func (b *bodySerializable) updateToEth(eth *ethtypes.Body) {
63+
eth.Transactions = b.Transactions
64+
eth.Uncles = b.Uncles
65+
}
66+
67+
// updateFromExtras updates the [*bodySerializable] from the [*BodyExtra].
68+
func (b *bodySerializable) updateFromExtras(extras *BodyExtra) {
69+
b.Version = extras.version
70+
b.ExtData = extras.extData
71+
}
72+
73+
// updateToExtras updates the [*BodyExtra] from the [*bodySerializable].
74+
func (b *bodySerializable) updateToExtras(extras *BodyExtra) {
75+
extras.version = b.Version
76+
extras.extData = b.ExtData
77+
}

core/types/libevm.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import (
1010
type isMultiCoin bool
1111

1212
var (
13-
extras = ethtypes.RegisterExtras[HeaderExtra, *HeaderExtra, isMultiCoin]()
13+
extras = ethtypes.RegisterExtras[
14+
HeaderExtra, *HeaderExtra,
15+
BodyExtra, *BodyExtra,
16+
isMultiCoin]()
1417
IsMultiCoinPayloads = extras.StateAccount
1518
)
1619

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,4 @@ require (
136136
rsc.io/tmplfunc v0.0.3 // indirect
137137
)
138138

139-
replace github.com/ava-labs/libevm => github.com/ava-labs/libevm v0.0.0-20250113230013-d10c4a3d1ff2
139+
replace github.com/ava-labs/libevm => github.com/ava-labs/libevm v0.0.0-20250121171435-edebe134329f

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax
5858
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
5959
github.com/ava-labs/avalanchego v1.12.1-0.20250107220127-32f58b4fa9c8 h1:qN3MOBHB//Ynhgt5Vys3iVe42Sr0EWSeN18VL3ecXzE=
6060
github.com/ava-labs/avalanchego v1.12.1-0.20250107220127-32f58b4fa9c8/go.mod h1:2B7+E5neLvkOr2zursGhebjU26d4AfB7RazPxBs8hHg=
61-
github.com/ava-labs/libevm v0.0.0-20250113230013-d10c4a3d1ff2 h1:eLyCq3xjpS6CDcZaVdAQaUim9qThl3buQjOlmcER8oQ=
62-
github.com/ava-labs/libevm v0.0.0-20250113230013-d10c4a3d1ff2/go.mod h1:M8TCw2g1D5GBB7hu7g1F4aot5bRHGSxnBawNVmHE9Z0=
61+
github.com/ava-labs/libevm v0.0.0-20250121171435-edebe134329f h1:r83FXbNY2MeQ1SaKmmVTWkDTAtZOs4mX8nme+nzpZU0=
62+
github.com/ava-labs/libevm v0.0.0-20250121171435-edebe134329f/go.mod h1:M8TCw2g1D5GBB7hu7g1F4aot5bRHGSxnBawNVmHE9Z0=
6363
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
6464
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
6565
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=

scripts/tests.e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ git checkout -B "test-${AVALANCHE_VERSION}" "${AVALANCHE_VERSION}"
4545

4646
echo "updating coreth dependency to point to ${CORETH_PATH}"
4747
go mod edit -replace "github.com/ava-labs/coreth=${CORETH_PATH}"
48-
go mod edit -replace "github.com/ava-labs/libevm=github.com/ava-labs/[email protected]20250113230013-d10c4a3d1ff2"
48+
go mod edit -replace "github.com/ava-labs/libevm=github.com/ava-labs/[email protected]20250121171435-edebe134329f"
4949
go mod tidy
5050

5151
echo "building avalanchego"

0 commit comments

Comments
 (0)