-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core/types):
Body
hooks for RLP encoding
- Loading branch information
Showing
6 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2179,7 +2179,7 @@ func golangBindings(t *testing.T, overload bool) { | |
if out, err := replacer.CombinedOutput(); err != nil { | ||
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out) | ||
} | ||
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") | ||
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") | ||
replacer.Dir = pkg | ||
if out, err := replacer.CombinedOutput(); err != nil { | ||
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// (c) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package types | ||
|
||
import ( | ||
"io" | ||
|
||
ethtypes "github.com/ava-labs/libevm/core/types" | ||
"github.com/ava-labs/libevm/rlp" | ||
) | ||
|
||
// BodyExtra is a struct that contains extra fields used by Avalanche | ||
// in the body. | ||
// This type uses BodySerializable to encode and decode the extra fields | ||
// along with the upstream type for compatibility with existing network blocks. | ||
type BodyExtra struct { | ||
version uint32 | ||
extData *[]byte | ||
|
||
// Fields removed from geth: | ||
// - withdrawals Withdrawals | ||
} | ||
|
||
func (b *BodyExtra) EncodeRLP(eth *ethtypes.Body, writer io.Writer) error { | ||
out := new(bodySerializable) | ||
|
||
out.updateFromEth(eth) | ||
out.updateFromExtras(b) | ||
|
||
return rlp.Encode(writer, out) | ||
} | ||
|
||
func (b *BodyExtra) DecodeRLP(eth *ethtypes.Body, stream *rlp.Stream) error { | ||
in := new(bodySerializable) | ||
if err := stream.Decode(in); err != nil { | ||
return err | ||
} | ||
|
||
in.updateToEth(eth) | ||
in.updateToExtras(b) | ||
|
||
return nil | ||
} | ||
|
||
// bodySerializable defines the body in the Ethereum blockchain, | ||
// as it is to be serialized into RLP. | ||
type bodySerializable struct { | ||
Transactions []*Transaction | ||
Uncles []*Header | ||
Version uint32 | ||
ExtData *[]byte `rlp:"nil"` | ||
} | ||
|
||
// updateFromEth updates the [*bodySerializable] from the [*ethtypes.Body]. | ||
func (b *bodySerializable) updateFromEth(eth *ethtypes.Body) { | ||
b.Transactions = eth.Transactions | ||
b.Uncles = eth.Uncles | ||
} | ||
|
||
// updateToEth updates the [*ethtypes.Body] from the [*bodySerializable]. | ||
func (b *bodySerializable) updateToEth(eth *ethtypes.Body) { | ||
eth.Transactions = b.Transactions | ||
eth.Uncles = b.Uncles | ||
} | ||
|
||
// updateFromExtras updates the [*bodySerializable] from the [*BodyExtra]. | ||
func (b *bodySerializable) updateFromExtras(extras *BodyExtra) { | ||
b.Version = extras.version | ||
b.ExtData = extras.extData | ||
} | ||
|
||
// updateToExtras updates the [*BodyExtra] from the [*bodySerializable]. | ||
func (b *bodySerializable) updateToExtras(extras *BodyExtra) { | ||
extras.version = b.Version | ||
extras.extData = b.ExtData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ git checkout -B "test-${AVALANCHE_VERSION}" "${AVALANCHE_VERSION}" | |
|
||
echo "updating coreth dependency to point to ${CORETH_PATH}" | ||
go mod edit -replace "github.com/ava-labs/coreth=${CORETH_PATH}" | ||
go mod edit -replace "github.com/ava-labs/libevm=github.com/ava-labs/[email protected]20250113230013-d10c4a3d1ff2" | ||
go mod edit -replace "github.com/ava-labs/libevm=github.com/ava-labs/[email protected]20250121171435-edebe134329f" | ||
go mod tidy | ||
|
||
echo "building avalanchego" | ||
|