From cc66c49930bf44bd35f5fc637586418b0be2e661 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Thu, 7 Nov 2019 14:56:47 -0600 Subject: [PATCH 1/6] basefee fields and serialization --- cmd/clef/main.go | 1 + core/types/block.go | 159 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) diff --git a/cmd/clef/main.go b/cmd/clef/main.go index d34f8c28d2d9..4522f76969e5 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -775,6 +775,7 @@ func testExternalUI(api *core.SignerAPI) { []byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"), common.HexToHash("0x0000H45H"), types.BlockNonce{}, + nil, } cliqueRlp, err := rlp.EncodeToBytes(cliqueHeader) if err != nil { diff --git a/core/types/block.go b/core/types/block.go index b0ec7fc77d68..3e3b13a534db 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -84,6 +84,7 @@ type Header struct { Extra []byte `json:"extraData" gencodec:"required"` MixDigest common.Hash `json:"mixHash"` Nonce BlockNonce `json:"nonce"` + BaseFee *big.Int `json:"baseFee" rlp:"nil"` } // field type overrides for gencodec @@ -97,6 +98,164 @@ type headerMarshaling struct { Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON } +// legacyHeader is used to encode headers without the BaseFee field +type legacyHeader struct { + ParentHash common.Hash `json:"parentHash" gencodec:"required"` + UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"` + Coinbase common.Address `json:"miner" gencodec:"required"` + Root common.Hash `json:"stateRoot" gencodec:"required"` + TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` + ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` + Bloom Bloom `json:"logsBloom" gencodec:"required"` + Difficulty *big.Int `json:"difficulty" gencodec:"required"` + Number *big.Int `json:"number" gencodec:"required"` + GasLimit uint64 `json:"gasLimit" gencodec:"required"` + GasUsed uint64 `json:"gasUsed" gencodec:"required"` + Time uint64 `json:"timestamp" gencodec:"required"` + Extra []byte `json:"extraData" gencodec:"required"` + MixDigest common.Hash `json:"mixHash"` + Nonce BlockNonce `json:"nonce"` +} + +func (h *Header) EncodeRLP(w io.Writer) error { + if h.BaseFee == nil { + legacyH := &legacyHeader{ + ParentHash: h.ParentHash, + UncleHash: h.UncleHash, + Coinbase: h.Coinbase, + Root: h.Root, + TxHash: h.TxHash, + ReceiptHash: h.ReceiptHash, + Bloom: h.Bloom, + Difficulty: h.Difficulty, + Number: h.Number, + GasLimit: h.GasLimit, + GasUsed: h.GasUsed, + Time: h.Time, + Extra: h.Extra, + MixDigest: h.MixDigest, + Nonce: h.Nonce, + } + return rlp.Encode(w, legacyH) + } + return rlp.Encode(w, h) +} + +func (h *Header) DecodeRLP(s *rlp.Stream) error { + _, err := s.List() + if err != nil { + return err + } + parentHash := new(common.Hash) + if err = s.Decode(parentHash); err != nil { + return err + } + uncleHash := new(common.Hash) + if err = s.Decode(uncleHash); err != nil { + return err + } + coinbase := new(common.Address) + if err = s.Decode(coinbase); err != nil { + return err + } + root := new(common.Hash) + if err = s.Decode(root); err != nil { + return err + } + txHash := new(common.Hash) + if err = s.Decode(txHash); err != nil { + return err + } + receiptHash := new(common.Hash) + if err = s.Decode(receiptHash); err != nil { + return err + } + bloom := new(Bloom) + if err = s.Decode(bloom); err != nil { + return err + } + difficulty := new(big.Int) + if err = s.Decode(difficulty); err != nil { + return err + } + number := new(big.Int) + if err = s.Decode(number); err != nil { + return err + } + gasLimit := new(uint64) + if err = s.Decode(gasLimit); err != nil { + return err + } + gasUsed := new(uint64) + if err = s.Decode(gasUsed); err != nil { + return err + } + time := new(uint64) + if err = s.Decode(time); err != nil { + return err + } + extra := new([]byte) + if err = s.Decode(extra); err != nil { + return err + } + mixDigest := new(common.Hash) + if err = s.Decode(mixDigest); err != nil { + return err + } + nonce := new(BlockNonce) + if err = s.Decode(nonce); err != nil { + return err + } + // if this is the end of the list then we are decoding a legacy header + if err = s.ListEnd(); err == nil { + h.ParentHash = *parentHash + h.UncleHash = *uncleHash + h.Coinbase = *coinbase + h.Root = *root + h.TxHash = *txHash + h.ReceiptHash = *receiptHash + h.Bloom = *bloom + h.Difficulty = difficulty + h.Number = number + h.GasLimit = *gasLimit + h.GasUsed = *gasUsed + h.Time = *time + h.Extra = *extra + h.MixDigest = *mixDigest + h.Nonce = *nonce + return nil + } + // if we are not at the end of the list, continue decoding the 1559 header fields + if err != rlp.ErrNotAtEOL { + return err + } + baseFee := new(big.Int) + if err = s.Decode(baseFee); err != nil { + return err + } + // we should now be at the end of the list even for a 1559 transaction + if err = s.ListEnd(); err != nil { + return err + } + h.ParentHash = *parentHash + h.UncleHash = *uncleHash + h.Coinbase = *coinbase + h.Root = *root + h.TxHash = *txHash + h.ReceiptHash = *receiptHash + h.Bloom = *bloom + h.Difficulty = difficulty + h.Number = number + h.GasLimit = *gasLimit + h.GasUsed = *gasUsed + h.Time = *time + h.Extra = *extra + h.MixDigest = *mixDigest + h.Nonce = *nonce + h.BaseFee = baseFee + return nil +} + // Hash returns the block hash of the header, which is simply the keccak256 hash of its // RLP encoding. func (h *Header) Hash() common.Hash { From 35d0d2e16b0dfc77bd28a9c6b9e2226495b81648 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Thu, 7 Nov 2019 19:07:08 -0600 Subject: [PATCH 2/6] gencodec for header; block method to retrieve basefee --- core/types/block.go | 2 ++ core/types/gen_header_json.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/core/types/block.go b/core/types/block.go index 3e3b13a534db..2fdd1d16d3a5 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -95,6 +95,7 @@ type headerMarshaling struct { GasUsed hexutil.Uint64 Time hexutil.Uint64 Extra hexutil.Bytes + BaseFee *hexutil.Big Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON } @@ -477,6 +478,7 @@ func (b *Block) TxHash() common.Hash { return b.header.TxHash } func (b *Block) ReceiptHash() common.Hash { return b.header.ReceiptHash } func (b *Block) UncleHash() common.Hash { return b.header.UncleHash } func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Extra) } +func (b *Block) BaseFee() *big.Int { return b.header.BaseFee } func (b *Block) Header() *Header { return CopyHeader(b.header) } diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index 4212b8d94d25..348079cd84b3 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -31,6 +31,7 @@ func (h Header) MarshalJSON() ([]byte, error) { Extra hexutil.Bytes `json:"extraData" gencodec:"required"` MixDigest common.Hash `json:"mixHash"` Nonce BlockNonce `json:"nonce"` + BaseFee *hexutil.Big `json:"baseFee" rlp:"nil"` Hash common.Hash `json:"hash"` } var enc Header @@ -49,6 +50,7 @@ func (h Header) MarshalJSON() ([]byte, error) { enc.Extra = h.Extra enc.MixDigest = h.MixDigest enc.Nonce = h.Nonce + enc.BaseFee = (*hexutil.Big)(h.BaseFee) enc.Hash = h.Hash() return json.Marshal(&enc) } @@ -71,6 +73,7 @@ func (h *Header) UnmarshalJSON(input []byte) error { Extra *hexutil.Bytes `json:"extraData" gencodec:"required"` MixDigest *common.Hash `json:"mixHash"` Nonce *BlockNonce `json:"nonce"` + BaseFee *hexutil.Big `json:"baseFee" rlp:"nil"` } var dec Header if err := json.Unmarshal(input, &dec); err != nil { @@ -134,5 +137,8 @@ func (h *Header) UnmarshalJSON(input []byte) error { if dec.Nonce != nil { h.Nonce = *dec.Nonce } + if dec.BaseFee != nil { + h.BaseFee = (*big.Int)(dec.BaseFee) + } return nil } From 19b7ce17d753b1ab14a9eaf22d82eff141efd5ea Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Fri, 15 Nov 2019 15:39:56 -0600 Subject: [PATCH 3/6] add BaseFee field to RPCMarshalHeader --- internal/ethapi/api.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 26ab14c7d251..e4294c1e74e2 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1045,6 +1045,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} { "timestamp": hexutil.Uint64(head.Time), "transactionsRoot": head.TxHash, "receiptsRoot": head.ReceiptHash, + "baseFee": (*hexutil.Big)(head.BaseFee), } } From 854499f2b80b2495f54599390bd6f5f8b6181360 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 18 Nov 2019 14:12:41 -0600 Subject: [PATCH 4/6] use anon struct in header encode to prevent recursive loop --- core/types/block.go | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/core/types/block.go b/core/types/block.go index 2fdd1d16d3a5..3950ad4f3a84 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -139,7 +139,42 @@ func (h *Header) EncodeRLP(w io.Writer) error { } return rlp.Encode(w, legacyH) } - return rlp.Encode(w, h) + encHeader := struct { + ParentHash common.Hash + UncleHash common.Hash + Coinbase common.Address + Root common.Hash + TxHash common.Hash + ReceiptHash common.Hash + Bloom Bloom + Difficulty *big.Int + Number *big.Int + GasLimit uint64 + GasUsed uint64 + Time uint64 + Extra []byte + MixDigest common.Hash + Nonce BlockNonce + BaseFee *big.Int + }{ + ParentHash: h.ParentHash, + UncleHash: h.UncleHash, + Coinbase: h.Coinbase, + Root: h.Root, + TxHash: h.TxHash, + ReceiptHash: h.ReceiptHash, + Bloom: h.Bloom, + Difficulty: h.Difficulty, + Number: h.Number, + GasLimit: h.GasLimit, + GasUsed: h.GasUsed, + Time: h.Time, + Extra: h.Extra, + MixDigest: h.MixDigest, + Nonce: h.Nonce, + BaseFee: h.BaseFee, + } + return rlp.Encode(w, encHeader) } func (h *Header) DecodeRLP(s *rlp.Stream) error { From bc03b9cf164954142dd0be7f68786af27ec1f611 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Mon, 18 Nov 2019 14:12:53 -0600 Subject: [PATCH 5/6] eip1559 header decode/encode unit tests --- core/types/block_test.go | 100 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/core/types/block_test.go b/core/types/block_test.go index f861053b4c16..5552aec42305 100644 --- a/core/types/block_test.go +++ b/core/types/block_test.go @@ -18,6 +18,11 @@ package types import ( "bytes" + + "github.com/ethereum/go-ethereum/params" + + //"fmt" + //"github.com/ethereum/go-ethereum/params" "math/big" "reflect" "testing" @@ -64,6 +69,101 @@ func TestBlockEncoding(t *testing.T) { } } +/* +type Header struct { + ParentHash common.Hash `json:"parentHash" gencodec:"required"` + UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"` + Coinbase common.Address `json:"miner" gencodec:"required"` + Root common.Hash `json:"stateRoot" gencodec:"required"` + TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` + ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` + Bloom Bloom `json:"logsBloom" gencodec:"required"` + Difficulty *big.Int `json:"difficulty" gencodec:"required"` + Number *big.Int `json:"number" gencodec:"required"` + GasLimit uint64 `json:"gasLimit" gencodec:"required"` + GasUsed uint64 `json:"gasUsed" gencodec:"required"` + Time uint64 `json:"timestamp" gencodec:"required"` + Extra []byte `json:"extraData" gencodec:"required"` + MixDigest common.Hash `json:"mixHash"` + Nonce BlockNonce `json:"nonce"` + BaseFee *big.Int `json:"baseFee" rlp:"nil"` +} +*/ + +func TestEIP1559BlockEncoding(t *testing.T) { + tx, err := decodeTx(common.Hex2Bytes("f86903808207d094b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a82554483030d40830c35001ba0612a9c962f0ac2841c671c021e45aeaa23f2892bf34da5d32d7948754cf078bda03a350e0e4e1ff5299228eb921af7c0435dbabd5b3d17f79c925864192ca9d126")) + if err != nil { + t.Fatal(err) + } + txs := Transactions{tx} + header := &Header{ + ParentHash: common.HexToHash("0x"), + Coinbase: common.HexToAddress("8888f1f195afa192cfee860698584c030f4c9db1"), + Root: common.HexToHash("ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017"), + Difficulty: big.NewInt(131072), + Number: big.NewInt(2675001), + GasLimit: 3141592, + GasUsed: 21000, + Time: 1426516743, + MixDigest: common.HexToHash("bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff498"), + Nonce: EncodeNonce(11617697748499542468), + BaseFee: big.NewInt(800000), + } + hash := header.Hash() + rct := NewReceipt([]byte{0}, false, 800000) + rcts := Receipts{rct} + rcts.DeriveFields(params.MainnetChainConfig, hash, 2675001, txs) + block := NewBlock(header, txs, nil, rcts) + blockBytes, err := rlp.EncodeToBytes(block) + if err != nil { + t.Fatal(err) + } + expected := common.FromHex("f90271f90200a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a0ed048395d4a0847b0cecfa3f649a9f4e56fd9813cb1bae507fb8a5a8a45009c6a0e596313d377d2ebcd789a5a17bbd6c6cb458be3f3c896db1e307865aa33acea2b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200008328d139832fefd8825208845506eb0780a0bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff49888a13a5a8c8f2bb1c4830c3500f86bf86903808207d094b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a82554483030d40830c35001ba0612a9c962f0ac2841c671c021e45aeaa23f2892bf34da5d32d7948754cf078bda03a350e0e4e1ff5299228eb921af7c0435dbabd5b3d17f79c925864192ca9d126c0") + if !bytes.Equal(blockBytes, expected) { + t.Errorf("encoded block mismatch:\ngot: %x\nwant: %x", blockBytes, expected) + } +} + +func TestEIP1559BlockDecoding(t *testing.T) { + blockEnc := common.FromHex("f90271f90200a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a0ed048395d4a0847b0cecfa3f649a9f4e56fd9813cb1bae507fb8a5a8a45009c6a0e596313d377d2ebcd789a5a17bbd6c6cb458be3f3c896db1e307865aa33acea2b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200008328d139832fefd8825208845506eb0780a0bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff49888a13a5a8c8f2bb1c4830c3500f86bf86903808207d094b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a82554483030d40830c35001ba0612a9c962f0ac2841c671c021e45aeaa23f2892bf34da5d32d7948754cf078bda03a350e0e4e1ff5299228eb921af7c0435dbabd5b3d17f79c925864192ca9d126c0") + var block Block + if err := rlp.DecodeBytes(blockEnc, &block); err != nil { + t.Fatal("decode error: ", err) + } + + check := func(f string, got, want interface{}) { + if !reflect.DeepEqual(got, want) { + t.Errorf("%s mismatch: got %v, want %v", f, got, want) + } + } + check("Difficulty", block.Difficulty(), big.NewInt(131072)) + check("GasLimit", block.GasLimit(), uint64(3141592)) + check("GasUsed", block.GasUsed(), uint64(21000)) + check("Coinbase", block.Coinbase(), common.HexToAddress("8888f1f195afa192cfee860698584c030f4c9db1")) + check("MixDigest", block.MixDigest(), common.HexToHash("bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff498")) + check("Root", block.Root(), common.HexToHash("ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017")) + check("Hash", block.Hash(), common.HexToHash("112545e5bd6c278a01e46061467f23b9e690685d28df917a5ad184171b095770")) + check("Nonce", block.Nonce(), uint64(0xa13a5a8c8f2bb1c4)) + check("Time", block.Time(), uint64(1426516743)) + check("Size", block.Size(), common.StorageSize(len(blockEnc))) + check("BaseFee", block.BaseFee(), big.NewInt(800000)) + + tx1, err := decodeTx(common.Hex2Bytes("f86903808207d094b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a82554483030d40830c35001ba0612a9c962f0ac2841c671c021e45aeaa23f2892bf34da5d32d7948754cf078bda03a350e0e4e1ff5299228eb921af7c0435dbabd5b3d17f79c925864192ca9d126")) + if err != nil { + t.Fatal(err) + } + check("len(Transactions)", len(block.Transactions()), 1) + check("Transactions[0].Hash", block.Transactions()[0].Hash(), tx1.Hash()) + + ourBlockEnc, err := rlp.EncodeToBytes(&block) + if err != nil { + t.Fatal("encode error: ", err) + } + if !bytes.Equal(ourBlockEnc, blockEnc) { + t.Errorf("encoded block mismatch:\ngot: %x\nwant: %x", ourBlockEnc, blockEnc) + } +} + func TestUncleHash(t *testing.T) { uncles := make([]*Header, 0) h := CalcUncleHash(uncles) From 0d17045855ba5ee21e110c86d8d395c9d11d538b Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Wed, 20 Nov 2019 15:02:50 -0600 Subject: [PATCH 6/6] simplify EncodeRLP; cleanup --- core/types/block.go | 112 +++++++++++++-------------------------- core/types/block_test.go | 21 -------- 2 files changed, 38 insertions(+), 95 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index 3950ad4f3a84..2d600cf2a14b 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -99,84 +99,48 @@ type headerMarshaling struct { Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON } -// legacyHeader is used to encode headers without the BaseFee field -type legacyHeader struct { - ParentHash common.Hash `json:"parentHash" gencodec:"required"` - UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"` - Coinbase common.Address `json:"miner" gencodec:"required"` - Root common.Hash `json:"stateRoot" gencodec:"required"` - TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` - ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` - Bloom Bloom `json:"logsBloom" gencodec:"required"` - Difficulty *big.Int `json:"difficulty" gencodec:"required"` - Number *big.Int `json:"number" gencodec:"required"` - GasLimit uint64 `json:"gasLimit" gencodec:"required"` - GasUsed uint64 `json:"gasUsed" gencodec:"required"` - Time uint64 `json:"timestamp" gencodec:"required"` - Extra []byte `json:"extraData" gencodec:"required"` - MixDigest common.Hash `json:"mixHash"` - Nonce BlockNonce `json:"nonce"` -} - +// EncodeRLP implements rlp.Encoder func (h *Header) EncodeRLP(w io.Writer) error { if h.BaseFee == nil { - legacyH := &legacyHeader{ - ParentHash: h.ParentHash, - UncleHash: h.UncleHash, - Coinbase: h.Coinbase, - Root: h.Root, - TxHash: h.TxHash, - ReceiptHash: h.ReceiptHash, - Bloom: h.Bloom, - Difficulty: h.Difficulty, - Number: h.Number, - GasLimit: h.GasLimit, - GasUsed: h.GasUsed, - Time: h.Time, - Extra: h.Extra, - MixDigest: h.MixDigest, - Nonce: h.Nonce, - } - return rlp.Encode(w, legacyH) - } - encHeader := struct { - ParentHash common.Hash - UncleHash common.Hash - Coinbase common.Address - Root common.Hash - TxHash common.Hash - ReceiptHash common.Hash - Bloom Bloom - Difficulty *big.Int - Number *big.Int - GasLimit uint64 - GasUsed uint64 - Time uint64 - Extra []byte - MixDigest common.Hash - Nonce BlockNonce - BaseFee *big.Int - }{ - ParentHash: h.ParentHash, - UncleHash: h.UncleHash, - Coinbase: h.Coinbase, - Root: h.Root, - TxHash: h.TxHash, - ReceiptHash: h.ReceiptHash, - Bloom: h.Bloom, - Difficulty: h.Difficulty, - Number: h.Number, - GasLimit: h.GasLimit, - GasUsed: h.GasUsed, - Time: h.Time, - Extra: h.Extra, - MixDigest: h.MixDigest, - Nonce: h.Nonce, - BaseFee: h.BaseFee, - } - return rlp.Encode(w, encHeader) + return rlp.Encode(w, []interface{}{ + h.ParentHash, + h.UncleHash, + h.Coinbase, + h.Root, + h.TxHash, + h.ReceiptHash, + h.Bloom, + h.Difficulty, + h.Number, + h.GasLimit, + h.GasUsed, + h.Time, + h.Extra, + h.MixDigest, + h.Nonce, + }) + } + return rlp.Encode(w, []interface{}{ + h.ParentHash, + h.UncleHash, + h.Coinbase, + h.Root, + h.TxHash, + h.ReceiptHash, + h.Bloom, + h.Difficulty, + h.Number, + h.GasLimit, + h.GasUsed, + h.Time, + h.Extra, + h.MixDigest, + h.Nonce, + h.BaseFee, + }) } +// DecodeRLP implements rlp.Decoder func (h *Header) DecodeRLP(s *rlp.Stream) error { _, err := s.List() if err != nil { diff --git a/core/types/block_test.go b/core/types/block_test.go index 5552aec42305..9436af125fa3 100644 --- a/core/types/block_test.go +++ b/core/types/block_test.go @@ -69,27 +69,6 @@ func TestBlockEncoding(t *testing.T) { } } -/* -type Header struct { - ParentHash common.Hash `json:"parentHash" gencodec:"required"` - UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"` - Coinbase common.Address `json:"miner" gencodec:"required"` - Root common.Hash `json:"stateRoot" gencodec:"required"` - TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` - ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` - Bloom Bloom `json:"logsBloom" gencodec:"required"` - Difficulty *big.Int `json:"difficulty" gencodec:"required"` - Number *big.Int `json:"number" gencodec:"required"` - GasLimit uint64 `json:"gasLimit" gencodec:"required"` - GasUsed uint64 `json:"gasUsed" gencodec:"required"` - Time uint64 `json:"timestamp" gencodec:"required"` - Extra []byte `json:"extraData" gencodec:"required"` - MixDigest common.Hash `json:"mixHash"` - Nonce BlockNonce `json:"nonce"` - BaseFee *big.Int `json:"baseFee" rlp:"nil"` -} -*/ - func TestEIP1559BlockEncoding(t *testing.T) { tx, err := decodeTx(common.Hex2Bytes("f86903808207d094b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a82554483030d40830c35001ba0612a9c962f0ac2841c671c021e45aeaa23f2892bf34da5d32d7948754cf078bda03a350e0e4e1ff5299228eb921af7c0435dbabd5b3d17f79c925864192ca9d126")) if err != nil {