mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
core/types: add handcrafted and generated rlp encoders
This commit is contained in:
parent
89a5581473
commit
9a070f7ab1
4 changed files with 63 additions and 63 deletions
|
|
@ -555,88 +555,88 @@ func HeaderParentHashFromRLP(header []byte) common.Hash {
|
||||||
return common.BytesToHash(parentHash)
|
return common.BytesToHash(parentHash)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj *Header) DecodeRLP(dec *rlp.Stream) error {
|
func (h *Header) DecodeRLP(dec *rlp.Stream) error {
|
||||||
var err error
|
var err error
|
||||||
{
|
{
|
||||||
if _, err := dec.List(); err != nil {
|
if _, err := dec.List(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// ParentHash:
|
// ParentHash:
|
||||||
if err := dec.ReadBytes(obj.ParentHash[:]); err != nil {
|
if err := dec.ReadBytes(h.ParentHash[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// UncleHash:
|
// UncleHash:
|
||||||
if err := dec.ReadBytes(obj.UncleHash[:]); err != nil {
|
if err := dec.ReadBytes(h.UncleHash[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Coinbase:
|
// Coinbase:
|
||||||
if err := dec.ReadBytes(obj.Coinbase[:]); err != nil {
|
if err := dec.ReadBytes(h.Coinbase[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Root:
|
// Root:
|
||||||
if err := dec.ReadBytes(obj.Root[:]); err != nil {
|
if err := dec.ReadBytes(h.Root[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// TxHash:
|
// TxHash:
|
||||||
if err := dec.ReadBytes(obj.TxHash[:]); err != nil {
|
if err := dec.ReadBytes(h.TxHash[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// ReceiptHash:
|
// ReceiptHash:
|
||||||
if err := dec.ReadBytes(obj.ReceiptHash[:]); err != nil {
|
if err := dec.ReadBytes(h.ReceiptHash[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Bloom:
|
// Bloom:
|
||||||
if err := dec.ReadBytes(obj.Bloom[:]); err != nil {
|
if err := dec.ReadBytes(h.Bloom[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Difficulty:
|
// Difficulty:
|
||||||
obj.Difficulty, err = dec.BigInt()
|
h.Difficulty, err = dec.BigInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Number:
|
// Number:
|
||||||
obj.Number, err = dec.BigInt()
|
h.Number, err = dec.BigInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
// GasLimit:
|
// GasLimit:
|
||||||
obj.GasLimit, err = dec.Uint64()
|
h.GasLimit, err = dec.Uint64()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// GasUsed:
|
// GasUsed:
|
||||||
obj.GasUsed, err = dec.Uint64()
|
h.GasUsed, err = dec.Uint64()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Time:
|
// Time:
|
||||||
obj.Time, err = dec.Uint64()
|
h.Time, err = dec.Uint64()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Extra:
|
// Extra:
|
||||||
obj.Extra, err = dec.Bytes()
|
h.Extra, err = dec.Bytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// MixDigest:
|
// MixDigest:
|
||||||
if err := dec.ReadBytes(obj.MixDigest[:]); err != nil {
|
if err := dec.ReadBytes(h.MixDigest[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Nonce:
|
// Nonce:
|
||||||
if err := dec.ReadBytes(obj.Nonce[:]); err != nil {
|
if err := dec.ReadBytes(h.Nonce[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// BaseFee:
|
// BaseFee:
|
||||||
if dec.MoreDataInList() {
|
if dec.MoreDataInList() {
|
||||||
obj.BaseFee, err = dec.BigInt()
|
h.BaseFee, err = dec.BigInt()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// WithdrawalsHash:
|
// WithdrawalsHash:
|
||||||
if dec.MoreDataInList() {
|
if dec.MoreDataInList() {
|
||||||
if err := dec.ReadBytes(obj.WithdrawalsHash[:]); err != nil {
|
if err := dec.ReadBytes(h.WithdrawalsHash[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// BlobGasUsed:
|
// BlobGasUsed:
|
||||||
|
|
@ -645,22 +645,22 @@ func (obj *Header) DecodeRLP(dec *rlp.Stream) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
obj.BlobGasUsed = &_tmp18
|
h.BlobGasUsed = &_tmp18
|
||||||
// ExcessBlobGas:
|
// ExcessBlobGas:
|
||||||
if dec.MoreDataInList() {
|
if dec.MoreDataInList() {
|
||||||
_tmp19, err := dec.Uint64()
|
_tmp19, err := dec.Uint64()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
obj.ExcessBlobGas = &_tmp19
|
h.ExcessBlobGas = &_tmp19
|
||||||
// ParentBeaconRoot:
|
// ParentBeaconRoot:
|
||||||
if dec.MoreDataInList() {
|
if dec.MoreDataInList() {
|
||||||
if err := dec.ReadBytes(obj.ParentBeaconRoot[:]); err != nil {
|
if err := dec.ReadBytes(h.ParentBeaconRoot[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// RequestsHash:
|
// RequestsHash:
|
||||||
if dec.MoreDataInList() {
|
if dec.MoreDataInList() {
|
||||||
if err := dec.ReadBytes(obj.RequestsHash[:]); err != nil {
|
if err := dec.ReadBytes(h.RequestsHash[:]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import "github.com/ethereum/go-ethereum/common"
|
|
||||||
import "github.com/ethereum/go-ethereum/rlp"
|
import "github.com/ethereum/go-ethereum/rlp"
|
||||||
import "github.com/holiman/uint256"
|
|
||||||
import "io"
|
import "io"
|
||||||
|
|
||||||
func (obj *StateAccount) EncodeRLP(_w io.Writer) error {
|
func (obj *StateAccount) EncodeRLP(_w io.Writer) error {
|
||||||
|
|
@ -21,41 +19,3 @@ func (obj *StateAccount) EncodeRLP(_w io.Writer) error {
|
||||||
w.ListEnd(_tmp0)
|
w.ListEnd(_tmp0)
|
||||||
return w.Flush()
|
return w.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (obj *StateAccount) DecodeRLP(dec *rlp.Stream) error {
|
|
||||||
var _tmp0 StateAccount
|
|
||||||
{
|
|
||||||
if _, err := dec.List(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Nonce:
|
|
||||||
_tmp1, err := dec.Uint64()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_tmp0.Nonce = _tmp1
|
|
||||||
// Balance:
|
|
||||||
var _tmp2 uint256.Int
|
|
||||||
if err := dec.ReadUint256(&_tmp2); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_tmp0.Balance = &_tmp2
|
|
||||||
// Root:
|
|
||||||
var _tmp3 common.Hash
|
|
||||||
if err := dec.ReadBytes(_tmp3[:]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_tmp0.Root = _tmp3
|
|
||||||
// CodeHash:
|
|
||||||
_tmp4, err := dec.Bytes()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_tmp0.CodeHash = _tmp4
|
|
||||||
if err := dec.ListEnd(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*obj = _tmp0
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
"github.com/holiman/uint256"
|
"github.com/holiman/uint256"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate go run ../../rlp/rlpgen -type StateAccount -out gen_account_rlp.go
|
//go:generate go run ../../rlp/rlpgen -type StateAccount -decoder=false -out gen_account_rlp.go
|
||||||
|
|
||||||
// StateAccount is the Ethereum consensus representation of accounts.
|
// StateAccount is the Ethereum consensus representation of accounts.
|
||||||
// These objects are stored in the main account trie.
|
// These objects are stored in the main account trie.
|
||||||
|
|
@ -35,6 +35,37 @@ type StateAccount struct {
|
||||||
CodeHash []byte
|
CodeHash []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (obj *StateAccount) DecodeRLP(dec *rlp.Stream) error {
|
||||||
|
var err error
|
||||||
|
{
|
||||||
|
if _, err := dec.List(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Nonce:
|
||||||
|
obj.Nonce, err = dec.Uint64()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Balance:
|
||||||
|
if err := dec.ReadUint256(obj.Balance); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Root:
|
||||||
|
if err := dec.ReadBytes(obj.Root[:]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// CodeHash:
|
||||||
|
obj.CodeHash, err = dec.Bytes()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := dec.ListEnd(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// NewEmptyStateAccount constructs an empty state account.
|
// NewEmptyStateAccount constructs an empty state account.
|
||||||
func NewEmptyStateAccount() *StateAccount {
|
func NewEmptyStateAccount() *StateAccount {
|
||||||
return &StateAccount{
|
return &StateAccount{
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,15 @@ func benchRLP(b *testing.B, encode bool) {
|
||||||
"full-block",
|
"full-block",
|
||||||
makeBenchBlock(),
|
makeBenchBlock(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"state-account",
|
||||||
|
&StateAccount{
|
||||||
|
Nonce: 0,
|
||||||
|
Balance: uint256.NewInt(0),
|
||||||
|
Root: common.Hash{},
|
||||||
|
CodeHash: make([]byte, 32),
|
||||||
|
},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
if encode {
|
if encode {
|
||||||
b.Run(tc.name, func(b *testing.B) {
|
b.Run(tc.name, func(b *testing.B) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue