forked from cerc-io/plugeth
core/types: faster RLP encoding of Header, StateAcccount, ReceiptForStorage (#24420)
This change makes use of the new code generator rlp/rlpgen to improve the performance of RLP encoding for Header and StateAccount. It also speeds up encoding of ReceiptForStorage using the new rlp.EncoderBuffer API. The change is much less transparent than I wanted it to be, because Header and StateAccount now have an EncodeRLP method defined with pointer receiver. It used to be possible to encode non-pointer values of these types, but the new method prevents that and attempting to encode unadressable values (even if part of another value) will return an error. The error can be surprising and may pop up in places that previously didn't expect any errors. To make things work, I also needed to update all code paths (mostly in unit tests) that lead to encoding of non-pointer values, and pass a pointer instead. Benchmark results: name old time/op new time/op delta EncodeRLP/legacy-header-8 328ns ± 0% 237ns ± 1% -27.63% (p=0.000 n=8+8) EncodeRLP/london-header-8 353ns ± 0% 247ns ± 1% -30.06% (p=0.000 n=8+8) EncodeRLP/receipt-for-storage-8 237ns ± 0% 123ns ± 0% -47.86% (p=0.000 n=8+7) EncodeRLP/receipt-full-8 297ns ± 0% 301ns ± 1% +1.39% (p=0.000 n=8+8) name old speed new speed delta EncodeRLP/legacy-header-8 1.66GB/s ± 0% 2.29GB/s ± 1% +38.19% (p=0.000 n=8+8) EncodeRLP/london-header-8 1.55GB/s ± 0% 2.22GB/s ± 1% +42.99% (p=0.000 n=8+8) EncodeRLP/receipt-for-storage-8 38.0MB/s ± 0% 64.8MB/s ± 0% +70.48% (p=0.000 n=8+7) EncodeRLP/receipt-full-8 910MB/s ± 0% 897MB/s ± 1% -1.37% (p=0.000 n=8+8) name old alloc/op new alloc/op delta EncodeRLP/legacy-header-8 0.00B 0.00B ~ (all equal) EncodeRLP/london-header-8 0.00B 0.00B ~ (all equal) EncodeRLP/receipt-for-storage-8 64.0B ± 0% 0.0B -100.00% (p=0.000 n=8+8) EncodeRLP/receipt-full-8 320B ± 0% 320B ± 0% ~ (all equal)
This commit is contained in:
parent
06aaeed1a6
commit
d6f49bf764
@ -22,7 +22,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate gencodec -type AccessTuple -out gen_access_tuple.go
|
//go:generate go run github.com/fjl/gencodec@latest -type AccessTuple -out gen_access_tuple.go
|
||||||
|
|
||||||
// AccessList is an EIP-2930 access list.
|
// AccessList is an EIP-2930 access list.
|
||||||
type AccessList []AccessTuple
|
type AccessList []AccessTuple
|
||||||
|
@ -63,7 +63,8 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
|
|||||||
return hexutil.UnmarshalFixedText("BlockNonce", input, n[:])
|
return hexutil.UnmarshalFixedText("BlockNonce", input, n[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate gencodec -type Header -field-override headerMarshaling -out gen_header_json.go
|
//go:generate go run github.com/fjl/gencodec@latest -type Header -field-override headerMarshaling -out gen_header_json.go
|
||||||
|
//go:generate go run ../../rlp/rlpgen -type Header -out gen_header_rlp.go
|
||||||
|
|
||||||
// Header represents a block header in the Ethereum blockchain.
|
// Header represents a block header in the Ethereum blockchain.
|
||||||
type Header struct {
|
type Header struct {
|
||||||
|
@ -285,7 +285,7 @@ func makeBenchBlock() *Block {
|
|||||||
func TestRlpDecodeParentHash(t *testing.T) {
|
func TestRlpDecodeParentHash(t *testing.T) {
|
||||||
// A minimum one
|
// A minimum one
|
||||||
want := common.HexToHash("0x112233445566778899001122334455667788990011223344556677889900aabb")
|
want := common.HexToHash("0x112233445566778899001122334455667788990011223344556677889900aabb")
|
||||||
if rlpData, err := rlp.EncodeToBytes(Header{ParentHash: want}); err != nil {
|
if rlpData, err := rlp.EncodeToBytes(&Header{ParentHash: want}); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if have := HeaderParentHashFromRLP(rlpData); have != want {
|
if have := HeaderParentHashFromRLP(rlpData); have != want {
|
||||||
@ -299,7 +299,7 @@ func TestRlpDecodeParentHash(t *testing.T) {
|
|||||||
// | BaseFee | dynamic| *big.Int | 64 bits |
|
// | BaseFee | dynamic| *big.Int | 64 bits |
|
||||||
mainnetTd := new(big.Int)
|
mainnetTd := new(big.Int)
|
||||||
mainnetTd.SetString("5ad3c2c71bbff854908", 16)
|
mainnetTd.SetString("5ad3c2c71bbff854908", 16)
|
||||||
if rlpData, err := rlp.EncodeToBytes(Header{
|
if rlpData, err := rlp.EncodeToBytes(&Header{
|
||||||
ParentHash: want,
|
ParentHash: want,
|
||||||
Difficulty: mainnetTd,
|
Difficulty: mainnetTd,
|
||||||
Number: new(big.Int).SetUint64(math.MaxUint64),
|
Number: new(big.Int).SetUint64(math.MaxUint64),
|
||||||
@ -316,7 +316,7 @@ func TestRlpDecodeParentHash(t *testing.T) {
|
|||||||
{
|
{
|
||||||
// The rlp-encoding of the heder belowCauses _total_ length of 65540,
|
// The rlp-encoding of the heder belowCauses _total_ length of 65540,
|
||||||
// which is the first to blow the fast-path.
|
// which is the first to blow the fast-path.
|
||||||
h := Header{
|
h := &Header{
|
||||||
ParentHash: want,
|
ParentHash: want,
|
||||||
Extra: make([]byte, 65041),
|
Extra: make([]byte, 65041),
|
||||||
}
|
}
|
||||||
|
27
core/types/gen_account_rlp.go
Normal file
27
core/types/gen_account_rlp.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Code generated by rlpgen. DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:build !norlpgen
|
||||||
|
// +build !norlpgen
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
import "github.com/ethereum/go-ethereum/rlp"
|
||||||
|
import "io"
|
||||||
|
|
||||||
|
func (obj *StateAccount) EncodeRLP(_w io.Writer) error {
|
||||||
|
w := rlp.NewEncoderBuffer(_w)
|
||||||
|
_tmp0 := w.List()
|
||||||
|
w.WriteUint64(obj.Nonce)
|
||||||
|
if obj.Balance == nil {
|
||||||
|
w.Write(rlp.EmptyString)
|
||||||
|
} else {
|
||||||
|
if obj.Balance.Sign() == -1 {
|
||||||
|
return rlp.ErrNegativeBigInt
|
||||||
|
}
|
||||||
|
w.WriteBigInt(obj.Balance)
|
||||||
|
}
|
||||||
|
w.WriteBytes(obj.Root[:])
|
||||||
|
w.WriteBytes(obj.CodeHash)
|
||||||
|
w.ListEnd(_tmp0)
|
||||||
|
return w.Flush()
|
||||||
|
}
|
56
core/types/gen_header_rlp.go
Normal file
56
core/types/gen_header_rlp.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Code generated by rlpgen. DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:build !norlpgen
|
||||||
|
// +build !norlpgen
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
import "github.com/ethereum/go-ethereum/rlp"
|
||||||
|
import "io"
|
||||||
|
|
||||||
|
func (obj *Header) EncodeRLP(_w io.Writer) error {
|
||||||
|
w := rlp.NewEncoderBuffer(_w)
|
||||||
|
_tmp0 := w.List()
|
||||||
|
w.WriteBytes(obj.ParentHash[:])
|
||||||
|
w.WriteBytes(obj.UncleHash[:])
|
||||||
|
w.WriteBytes(obj.Coinbase[:])
|
||||||
|
w.WriteBytes(obj.Root[:])
|
||||||
|
w.WriteBytes(obj.TxHash[:])
|
||||||
|
w.WriteBytes(obj.ReceiptHash[:])
|
||||||
|
w.WriteBytes(obj.Bloom[:])
|
||||||
|
if obj.Difficulty == nil {
|
||||||
|
w.Write(rlp.EmptyString)
|
||||||
|
} else {
|
||||||
|
if obj.Difficulty.Sign() == -1 {
|
||||||
|
return rlp.ErrNegativeBigInt
|
||||||
|
}
|
||||||
|
w.WriteBigInt(obj.Difficulty)
|
||||||
|
}
|
||||||
|
if obj.Number == nil {
|
||||||
|
w.Write(rlp.EmptyString)
|
||||||
|
} else {
|
||||||
|
if obj.Number.Sign() == -1 {
|
||||||
|
return rlp.ErrNegativeBigInt
|
||||||
|
}
|
||||||
|
w.WriteBigInt(obj.Number)
|
||||||
|
}
|
||||||
|
w.WriteUint64(obj.GasLimit)
|
||||||
|
w.WriteUint64(obj.GasUsed)
|
||||||
|
w.WriteUint64(obj.Time)
|
||||||
|
w.WriteBytes(obj.Extra)
|
||||||
|
w.WriteBytes(obj.MixDigest[:])
|
||||||
|
w.WriteBytes(obj.Nonce[:])
|
||||||
|
_tmp1 := obj.BaseFee != nil
|
||||||
|
if _tmp1 {
|
||||||
|
if obj.BaseFee == nil {
|
||||||
|
w.Write(rlp.EmptyString)
|
||||||
|
} else {
|
||||||
|
if obj.BaseFee.Sign() == -1 {
|
||||||
|
return rlp.ErrNegativeBigInt
|
||||||
|
}
|
||||||
|
w.WriteBigInt(obj.BaseFee)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.ListEnd(_tmp0)
|
||||||
|
return w.Flush()
|
||||||
|
}
|
23
core/types/gen_log_rlp.go
Normal file
23
core/types/gen_log_rlp.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// Code generated by rlpgen. DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:build !norlpgen
|
||||||
|
// +build !norlpgen
|
||||||
|
|
||||||
|
package types
|
||||||
|
|
||||||
|
import "github.com/ethereum/go-ethereum/rlp"
|
||||||
|
import "io"
|
||||||
|
|
||||||
|
func (obj *rlpLog) EncodeRLP(_w io.Writer) error {
|
||||||
|
w := rlp.NewEncoderBuffer(_w)
|
||||||
|
_tmp0 := w.List()
|
||||||
|
w.WriteBytes(obj.Address[:])
|
||||||
|
_tmp1 := w.List()
|
||||||
|
for _, _tmp2 := range obj.Topics {
|
||||||
|
w.WriteBytes(_tmp2[:])
|
||||||
|
}
|
||||||
|
w.ListEnd(_tmp1)
|
||||||
|
w.WriteBytes(obj.Data)
|
||||||
|
w.ListEnd(_tmp0)
|
||||||
|
return w.Flush()
|
||||||
|
}
|
@ -24,7 +24,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate gencodec -type Log -field-override logMarshaling -out gen_log_json.go
|
//go:generate go run github.com/fjl/gencodec@latest -type Log -field-override logMarshaling -out gen_log_json.go
|
||||||
|
|
||||||
// Log represents a contract log event. These events are generated by the LOG opcode and
|
// Log represents a contract log event. These events are generated by the LOG opcode and
|
||||||
// stored/indexed by the node.
|
// stored/indexed by the node.
|
||||||
@ -62,15 +62,14 @@ type logMarshaling struct {
|
|||||||
Index hexutil.Uint
|
Index hexutil.Uint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:generate go run ../../rlp/rlpgen -type rlpLog -out gen_log_rlp.go
|
||||||
|
|
||||||
type rlpLog struct {
|
type rlpLog struct {
|
||||||
Address common.Address
|
Address common.Address
|
||||||
Topics []common.Hash
|
Topics []common.Hash
|
||||||
Data []byte
|
Data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// rlpStorageLog is the storage encoding of a log.
|
|
||||||
type rlpStorageLog rlpLog
|
|
||||||
|
|
||||||
// legacyRlpStorageLog is the previous storage encoding of a log including some redundant fields.
|
// legacyRlpStorageLog is the previous storage encoding of a log including some redundant fields.
|
||||||
type legacyRlpStorageLog struct {
|
type legacyRlpStorageLog struct {
|
||||||
Address common.Address
|
Address common.Address
|
||||||
@ -85,7 +84,8 @@ type legacyRlpStorageLog struct {
|
|||||||
|
|
||||||
// EncodeRLP implements rlp.Encoder.
|
// EncodeRLP implements rlp.Encoder.
|
||||||
func (l *Log) EncodeRLP(w io.Writer) error {
|
func (l *Log) EncodeRLP(w io.Writer) error {
|
||||||
return rlp.Encode(w, rlpLog{Address: l.Address, Topics: l.Topics, Data: l.Data})
|
rl := rlpLog{Address: l.Address, Topics: l.Topics, Data: l.Data}
|
||||||
|
return rlp.Encode(w, &rl)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodeRLP implements rlp.Decoder.
|
// DecodeRLP implements rlp.Decoder.
|
||||||
@ -104,11 +104,8 @@ type LogForStorage Log
|
|||||||
|
|
||||||
// EncodeRLP implements rlp.Encoder.
|
// EncodeRLP implements rlp.Encoder.
|
||||||
func (l *LogForStorage) EncodeRLP(w io.Writer) error {
|
func (l *LogForStorage) EncodeRLP(w io.Writer) error {
|
||||||
return rlp.Encode(w, rlpStorageLog{
|
rl := rlpLog{Address: l.Address, Topics: l.Topics, Data: l.Data}
|
||||||
Address: l.Address,
|
return rlp.Encode(w, &rl)
|
||||||
Topics: l.Topics,
|
|
||||||
Data: l.Data,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodeRLP implements rlp.Decoder.
|
// DecodeRLP implements rlp.Decoder.
|
||||||
@ -119,7 +116,7 @@ func (l *LogForStorage) DecodeRLP(s *rlp.Stream) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var dec rlpStorageLog
|
var dec rlpLog
|
||||||
err = rlp.DecodeBytes(blob, &dec)
|
err = rlp.DecodeBytes(blob, &dec)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
*l = LogForStorage{
|
*l = LogForStorage{
|
||||||
|
@ -31,7 +31,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate gencodec -type Receipt -field-override receiptMarshaling -out gen_receipt_json.go
|
//go:generate go run github.com/fjl/gencodec@latest -type Receipt -field-override receiptMarshaling -out gen_receipt_json.go
|
||||||
|
|
||||||
var (
|
var (
|
||||||
receiptStatusFailedRLP = []byte{}
|
receiptStatusFailedRLP = []byte{}
|
||||||
@ -287,16 +287,20 @@ type ReceiptForStorage Receipt
|
|||||||
|
|
||||||
// EncodeRLP implements rlp.Encoder, and flattens all content fields of a receipt
|
// EncodeRLP implements rlp.Encoder, and flattens all content fields of a receipt
|
||||||
// into an RLP stream.
|
// into an RLP stream.
|
||||||
func (r *ReceiptForStorage) EncodeRLP(w io.Writer) error {
|
func (r *ReceiptForStorage) EncodeRLP(_w io.Writer) error {
|
||||||
enc := &storedReceiptRLP{
|
w := rlp.NewEncoderBuffer(_w)
|
||||||
PostStateOrStatus: (*Receipt)(r).statusEncoding(),
|
outerList := w.List()
|
||||||
CumulativeGasUsed: r.CumulativeGasUsed,
|
w.WriteBytes((*Receipt)(r).statusEncoding())
|
||||||
Logs: make([]*LogForStorage, len(r.Logs)),
|
w.WriteUint64(r.CumulativeGasUsed)
|
||||||
|
logList := w.List()
|
||||||
|
for _, log := range r.Logs {
|
||||||
|
if err := rlp.Encode(w, log); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
for i, log := range r.Logs {
|
|
||||||
enc.Logs[i] = (*LogForStorage)(log)
|
|
||||||
}
|
}
|
||||||
return rlp.Encode(w, enc)
|
w.ListEnd(logList)
|
||||||
|
w.ListEnd(outerList)
|
||||||
|
return w.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodeRLP implements rlp.Decoder, and loads both consensus and implementation
|
// DecodeRLP implements rlp.Decoder, and loads both consensus and implementation
|
||||||
|
@ -22,6 +22,8 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:generate go run ../../rlp/rlpgen -type StateAccount -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.
|
||||||
type StateAccount struct {
|
type StateAccount struct {
|
||||||
|
@ -570,7 +570,7 @@ func testCheckpointChallenge(t *testing.T, syncmode downloader.SyncMode, checkpo
|
|||||||
t.Fatalf("failed to answer challenge: %v", err)
|
t.Fatalf("failed to answer challenge: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
responseRlp, _ := rlp.EncodeToBytes(types.Header{Number: response.Number})
|
responseRlp, _ := rlp.EncodeToBytes(&types.Header{Number: response.Number})
|
||||||
if err := remote.ReplyBlockHeadersRLP(request.RequestId, []rlp.RawValue{responseRlp}); err != nil {
|
if err := remote.ReplyBlockHeadersRLP(request.RequestId, []rlp.RawValue{responseRlp}); err != nil {
|
||||||
t.Fatalf("failed to answer challenge: %v", err)
|
t.Fatalf("failed to answer challenge: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -264,11 +264,11 @@ func testGetBlockHeaders(t *testing.T, protocol uint) {
|
|||||||
headers = append(headers, backend.chain.GetBlockByHash(hash).Header())
|
headers = append(headers, backend.chain.GetBlockByHash(hash).Header())
|
||||||
}
|
}
|
||||||
// Send the hash request and verify the response
|
// Send the hash request and verify the response
|
||||||
p2p.Send(peer.app, GetBlockHeadersMsg, GetBlockHeadersPacket66{
|
p2p.Send(peer.app, GetBlockHeadersMsg, &GetBlockHeadersPacket66{
|
||||||
RequestId: 123,
|
RequestId: 123,
|
||||||
GetBlockHeadersPacket: tt.query,
|
GetBlockHeadersPacket: tt.query,
|
||||||
})
|
})
|
||||||
if err := p2p.ExpectMsg(peer.app, BlockHeadersMsg, BlockHeadersPacket66{
|
if err := p2p.ExpectMsg(peer.app, BlockHeadersMsg, &BlockHeadersPacket66{
|
||||||
RequestId: 123,
|
RequestId: 123,
|
||||||
BlockHeadersPacket: headers,
|
BlockHeadersPacket: headers,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -279,14 +279,12 @@ func testGetBlockHeaders(t *testing.T, protocol uint) {
|
|||||||
if origin := backend.chain.GetBlockByNumber(tt.query.Origin.Number); origin != nil {
|
if origin := backend.chain.GetBlockByNumber(tt.query.Origin.Number); origin != nil {
|
||||||
tt.query.Origin.Hash, tt.query.Origin.Number = origin.Hash(), 0
|
tt.query.Origin.Hash, tt.query.Origin.Number = origin.Hash(), 0
|
||||||
|
|
||||||
p2p.Send(peer.app, GetBlockHeadersMsg, GetBlockHeadersPacket66{
|
p2p.Send(peer.app, GetBlockHeadersMsg, &GetBlockHeadersPacket66{
|
||||||
RequestId: 456,
|
RequestId: 456,
|
||||||
GetBlockHeadersPacket: tt.query,
|
GetBlockHeadersPacket: tt.query,
|
||||||
})
|
})
|
||||||
if err := p2p.ExpectMsg(peer.app, BlockHeadersMsg, BlockHeadersPacket66{
|
expected := &BlockHeadersPacket66{RequestId: 456, BlockHeadersPacket: headers}
|
||||||
RequestId: 456,
|
if err := p2p.ExpectMsg(peer.app, BlockHeadersMsg, expected); err != nil {
|
||||||
BlockHeadersPacket: headers,
|
|
||||||
}); err != nil {
|
|
||||||
t.Errorf("test %d by hash: headers mismatch: %v", i, err)
|
t.Errorf("test %d by hash: headers mismatch: %v", i, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -364,11 +362,11 @@ func testGetBlockBodies(t *testing.T, protocol uint) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Send the hash request and verify the response
|
// Send the hash request and verify the response
|
||||||
p2p.Send(peer.app, GetBlockBodiesMsg, GetBlockBodiesPacket66{
|
p2p.Send(peer.app, GetBlockBodiesMsg, &GetBlockBodiesPacket66{
|
||||||
RequestId: 123,
|
RequestId: 123,
|
||||||
GetBlockBodiesPacket: hashes,
|
GetBlockBodiesPacket: hashes,
|
||||||
})
|
})
|
||||||
if err := p2p.ExpectMsg(peer.app, BlockBodiesMsg, BlockBodiesPacket66{
|
if err := p2p.ExpectMsg(peer.app, BlockBodiesMsg, &BlockBodiesPacket66{
|
||||||
RequestId: 123,
|
RequestId: 123,
|
||||||
BlockBodiesPacket: bodies,
|
BlockBodiesPacket: bodies,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -436,7 +434,7 @@ func testGetNodeData(t *testing.T, protocol uint) {
|
|||||||
it.Release()
|
it.Release()
|
||||||
|
|
||||||
// Request all hashes.
|
// Request all hashes.
|
||||||
p2p.Send(peer.app, GetNodeDataMsg, GetNodeDataPacket66{
|
p2p.Send(peer.app, GetNodeDataMsg, &GetNodeDataPacket66{
|
||||||
RequestId: 123,
|
RequestId: 123,
|
||||||
GetNodeDataPacket: hashes,
|
GetNodeDataPacket: hashes,
|
||||||
})
|
})
|
||||||
@ -546,11 +544,11 @@ func testGetBlockReceipts(t *testing.T, protocol uint) {
|
|||||||
receipts = append(receipts, backend.chain.GetReceiptsByHash(block.Hash()))
|
receipts = append(receipts, backend.chain.GetReceiptsByHash(block.Hash()))
|
||||||
}
|
}
|
||||||
// Send the hash request and verify the response
|
// Send the hash request and verify the response
|
||||||
p2p.Send(peer.app, GetReceiptsMsg, GetReceiptsPacket66{
|
p2p.Send(peer.app, GetReceiptsMsg, &GetReceiptsPacket66{
|
||||||
RequestId: 123,
|
RequestId: 123,
|
||||||
GetReceiptsPacket: hashes,
|
GetReceiptsPacket: hashes,
|
||||||
})
|
})
|
||||||
if err := p2p.ExpectMsg(peer.app, ReceiptsMsg, ReceiptsPacket66{
|
if err := p2p.ExpectMsg(peer.app, ReceiptsMsg, &ReceiptsPacket66{
|
||||||
RequestId: 123,
|
RequestId: 123,
|
||||||
ReceiptsPacket: receipts,
|
ReceiptsPacket: receipts,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
@ -241,7 +241,7 @@ func (p *Peer) ReplyPooledTransactionsRLP(id uint64, hashes []common.Hash, txs [
|
|||||||
p.knownTxs.Add(hashes...)
|
p.knownTxs.Add(hashes...)
|
||||||
|
|
||||||
// Not packed into PooledTransactionsPacket to avoid RLP decoding
|
// Not packed into PooledTransactionsPacket to avoid RLP decoding
|
||||||
return p2p.Send(p.rw, PooledTransactionsMsg, PooledTransactionsRLPPacket66{
|
return p2p.Send(p.rw, PooledTransactionsMsg, &PooledTransactionsRLPPacket66{
|
||||||
RequestId: id,
|
RequestId: id,
|
||||||
PooledTransactionsRLPPacket: txs,
|
PooledTransactionsRLPPacket: txs,
|
||||||
})
|
})
|
||||||
@ -298,7 +298,7 @@ func (p *Peer) AsyncSendNewBlock(block *types.Block, td *big.Int) {
|
|||||||
|
|
||||||
// ReplyBlockHeaders is the eth/66 version of SendBlockHeaders.
|
// ReplyBlockHeaders is the eth/66 version of SendBlockHeaders.
|
||||||
func (p *Peer) ReplyBlockHeadersRLP(id uint64, headers []rlp.RawValue) error {
|
func (p *Peer) ReplyBlockHeadersRLP(id uint64, headers []rlp.RawValue) error {
|
||||||
return p2p.Send(p.rw, BlockHeadersMsg, BlockHeadersRLPPacket66{
|
return p2p.Send(p.rw, BlockHeadersMsg, &BlockHeadersRLPPacket66{
|
||||||
RequestId: id,
|
RequestId: id,
|
||||||
BlockHeadersRLPPacket: headers,
|
BlockHeadersRLPPacket: headers,
|
||||||
})
|
})
|
||||||
@ -307,7 +307,7 @@ func (p *Peer) ReplyBlockHeadersRLP(id uint64, headers []rlp.RawValue) error {
|
|||||||
// ReplyBlockBodiesRLP is the eth/66 version of SendBlockBodiesRLP.
|
// ReplyBlockBodiesRLP is the eth/66 version of SendBlockBodiesRLP.
|
||||||
func (p *Peer) ReplyBlockBodiesRLP(id uint64, bodies []rlp.RawValue) error {
|
func (p *Peer) ReplyBlockBodiesRLP(id uint64, bodies []rlp.RawValue) error {
|
||||||
// Not packed into BlockBodiesPacket to avoid RLP decoding
|
// Not packed into BlockBodiesPacket to avoid RLP decoding
|
||||||
return p2p.Send(p.rw, BlockBodiesMsg, BlockBodiesRLPPacket66{
|
return p2p.Send(p.rw, BlockBodiesMsg, &BlockBodiesRLPPacket66{
|
||||||
RequestId: id,
|
RequestId: id,
|
||||||
BlockBodiesRLPPacket: bodies,
|
BlockBodiesRLPPacket: bodies,
|
||||||
})
|
})
|
||||||
@ -315,7 +315,7 @@ func (p *Peer) ReplyBlockBodiesRLP(id uint64, bodies []rlp.RawValue) error {
|
|||||||
|
|
||||||
// ReplyNodeData is the eth/66 response to GetNodeData.
|
// ReplyNodeData is the eth/66 response to GetNodeData.
|
||||||
func (p *Peer) ReplyNodeData(id uint64, data [][]byte) error {
|
func (p *Peer) ReplyNodeData(id uint64, data [][]byte) error {
|
||||||
return p2p.Send(p.rw, NodeDataMsg, NodeDataPacket66{
|
return p2p.Send(p.rw, NodeDataMsg, &NodeDataPacket66{
|
||||||
RequestId: id,
|
RequestId: id,
|
||||||
NodeDataPacket: data,
|
NodeDataPacket: data,
|
||||||
})
|
})
|
||||||
@ -323,7 +323,7 @@ func (p *Peer) ReplyNodeData(id uint64, data [][]byte) error {
|
|||||||
|
|
||||||
// ReplyReceiptsRLP is the eth/66 response to GetReceipts.
|
// ReplyReceiptsRLP is the eth/66 response to GetReceipts.
|
||||||
func (p *Peer) ReplyReceiptsRLP(id uint64, receipts []rlp.RawValue) error {
|
func (p *Peer) ReplyReceiptsRLP(id uint64, receipts []rlp.RawValue) error {
|
||||||
return p2p.Send(p.rw, ReceiptsMsg, ReceiptsRLPPacket66{
|
return p2p.Send(p.rw, ReceiptsMsg, &ReceiptsRLPPacket66{
|
||||||
RequestId: id,
|
RequestId: id,
|
||||||
ReceiptsRLPPacket: receipts,
|
ReceiptsRLPPacket: receipts,
|
||||||
})
|
})
|
||||||
|
@ -1349,7 +1349,7 @@ func makeAccountTrieNoStorage(n int) (*trie.Trie, entrySlice) {
|
|||||||
accTrie, _ := trie.New(common.Hash{}, db)
|
accTrie, _ := trie.New(common.Hash{}, db)
|
||||||
var entries entrySlice
|
var entries entrySlice
|
||||||
for i := uint64(1); i <= uint64(n); i++ {
|
for i := uint64(1); i <= uint64(n); i++ {
|
||||||
value, _ := rlp.EncodeToBytes(types.StateAccount{
|
value, _ := rlp.EncodeToBytes(&types.StateAccount{
|
||||||
Nonce: i,
|
Nonce: i,
|
||||||
Balance: big.NewInt(int64(i)),
|
Balance: big.NewInt(int64(i)),
|
||||||
Root: emptyRoot,
|
Root: emptyRoot,
|
||||||
@ -1394,7 +1394,7 @@ func makeBoundaryAccountTrie(n int) (*trie.Trie, entrySlice) {
|
|||||||
}
|
}
|
||||||
// Fill boundary accounts
|
// Fill boundary accounts
|
||||||
for i := 0; i < len(boundaries); i++ {
|
for i := 0; i < len(boundaries); i++ {
|
||||||
value, _ := rlp.EncodeToBytes(types.StateAccount{
|
value, _ := rlp.EncodeToBytes(&types.StateAccount{
|
||||||
Nonce: uint64(0),
|
Nonce: uint64(0),
|
||||||
Balance: big.NewInt(int64(i)),
|
Balance: big.NewInt(int64(i)),
|
||||||
Root: emptyRoot,
|
Root: emptyRoot,
|
||||||
@ -1406,7 +1406,7 @@ func makeBoundaryAccountTrie(n int) (*trie.Trie, entrySlice) {
|
|||||||
}
|
}
|
||||||
// Fill other accounts if required
|
// Fill other accounts if required
|
||||||
for i := uint64(1); i <= uint64(n); i++ {
|
for i := uint64(1); i <= uint64(n); i++ {
|
||||||
value, _ := rlp.EncodeToBytes(types.StateAccount{
|
value, _ := rlp.EncodeToBytes(&types.StateAccount{
|
||||||
Nonce: i,
|
Nonce: i,
|
||||||
Balance: big.NewInt(int64(i)),
|
Balance: big.NewInt(int64(i)),
|
||||||
Root: emptyRoot,
|
Root: emptyRoot,
|
||||||
@ -1442,7 +1442,7 @@ func makeAccountTrieWithStorageWithUniqueStorage(accounts, slots int, code bool)
|
|||||||
stTrie, stEntries := makeStorageTrieWithSeed(uint64(slots), i, db)
|
stTrie, stEntries := makeStorageTrieWithSeed(uint64(slots), i, db)
|
||||||
stRoot := stTrie.Hash()
|
stRoot := stTrie.Hash()
|
||||||
stTrie.Commit(nil)
|
stTrie.Commit(nil)
|
||||||
value, _ := rlp.EncodeToBytes(types.StateAccount{
|
value, _ := rlp.EncodeToBytes(&types.StateAccount{
|
||||||
Nonce: i,
|
Nonce: i,
|
||||||
Balance: big.NewInt(int64(i)),
|
Balance: big.NewInt(int64(i)),
|
||||||
Root: stRoot,
|
Root: stRoot,
|
||||||
@ -1489,7 +1489,7 @@ func makeAccountTrieWithStorage(accounts, slots int, code, boundary bool) (*trie
|
|||||||
if code {
|
if code {
|
||||||
codehash = getCodeHash(i)
|
codehash = getCodeHash(i)
|
||||||
}
|
}
|
||||||
value, _ := rlp.EncodeToBytes(types.StateAccount{
|
value, _ := rlp.EncodeToBytes(&types.StateAccount{
|
||||||
Nonce: i,
|
Nonce: i,
|
||||||
Balance: big.NewInt(int64(i)),
|
Balance: big.NewInt(int64(i)),
|
||||||
Root: stRoot,
|
Root: stRoot,
|
||||||
|
@ -213,7 +213,7 @@ func (p *peerCommons) sendReceiveHandshake(sendList keyValueList) (keyValueList,
|
|||||||
)
|
)
|
||||||
// Send out own handshake in a new thread
|
// Send out own handshake in a new thread
|
||||||
go func() {
|
go func() {
|
||||||
errc <- p2p.Send(p.rw, StatusMsg, sendList)
|
errc <- p2p.Send(p.rw, StatusMsg, &sendList)
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
// In the mean time retrieve the remote status message
|
// In the mean time retrieve the remote status message
|
||||||
@ -421,7 +421,7 @@ func sendRequest(w p2p.MsgWriter, msgcode, reqID uint64, data interface{}) error
|
|||||||
ReqID uint64
|
ReqID uint64
|
||||||
Data interface{}
|
Data interface{}
|
||||||
}
|
}
|
||||||
return p2p.Send(w, msgcode, req{reqID, data})
|
return p2p.Send(w, msgcode, &req{reqID, data})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *serverPeer) sendRequest(msgcode, reqID uint64, data interface{}, amount int) error {
|
func (p *serverPeer) sendRequest(msgcode, reqID uint64, data interface{}, amount int) error {
|
||||||
@ -871,7 +871,7 @@ func (r *reply) send(bv uint64) error {
|
|||||||
ReqID, BV uint64
|
ReqID, BV uint64
|
||||||
Data rlp.RawValue
|
Data rlp.RawValue
|
||||||
}
|
}
|
||||||
return p2p.Send(r.w, r.msgcode, resp{r.reqID, bv, r.data})
|
return p2p.Send(r.w, r.msgcode, &resp{r.reqID, bv, r.data})
|
||||||
}
|
}
|
||||||
|
|
||||||
// size returns the RLP encoded size of the message data
|
// size returns the RLP encoded size of the message data
|
||||||
|
@ -356,7 +356,7 @@ func (p *testPeer) handshakeWithServer(t *testing.T, td *big.Int, head common.Ha
|
|||||||
if err := p2p.ExpectMsg(p.app, StatusMsg, nil); err != nil {
|
if err := p2p.ExpectMsg(p.app, StatusMsg, nil); err != nil {
|
||||||
t.Fatalf("status recv: %v", err)
|
t.Fatalf("status recv: %v", err)
|
||||||
}
|
}
|
||||||
if err := p2p.Send(p.app, StatusMsg, sendList); err != nil {
|
if err := p2p.Send(p.app, StatusMsg, &sendList); err != nil {
|
||||||
t.Fatalf("status send: %v", err)
|
t.Fatalf("status send: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -389,7 +389,7 @@ func (p *testPeer) handshakeWithClient(t *testing.T, td *big.Int, head common.Ha
|
|||||||
if err := p2p.ExpectMsg(p.app, StatusMsg, nil); err != nil {
|
if err := p2p.ExpectMsg(p.app, StatusMsg, nil); err != nil {
|
||||||
t.Fatalf("status recv: %v", err)
|
t.Fatalf("status recv: %v", err)
|
||||||
}
|
}
|
||||||
if err := p2p.Send(p.app, StatusMsg, sendList); err != nil {
|
if err := p2p.Send(p.app, StatusMsg, &sendList); err != nil {
|
||||||
t.Fatalf("status send: %v", err)
|
t.Fatalf("status send: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ func (t *testService) Stop() error {
|
|||||||
// message with the given code
|
// message with the given code
|
||||||
func (t *testService) handshake(rw p2p.MsgReadWriter, code uint64) error {
|
func (t *testService) handshake(rw p2p.MsgReadWriter, code uint64) error {
|
||||||
errc := make(chan error, 2)
|
errc := make(chan error, 2)
|
||||||
go func() { errc <- p2p.Send(rw, code, struct{}{}) }()
|
go func() { errc <- p2p.SendItems(rw, code) }()
|
||||||
go func() { errc <- p2p.ExpectMsg(rw, code, struct{}{}) }()
|
go func() { errc <- p2p.ExpectMsg(rw, code, struct{}{}) }()
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
if err := <-errc; err != nil {
|
if err := <-errc; err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user