From 4729954a7836ddd9cc6201044f4d22fa3977f6f9 Mon Sep 17 00:00:00 2001 From: Rongjian Lan Date: Wed, 28 Nov 2018 12:59:03 -0800 Subject: [PATCH] Remove Uncle block hash from block model --- consensus/bft.go | 1 - core/rawdb/accessors_chain_test.go | 2 - core/types/block.go | 2 - core/types/block_test.go | 70 ------------------------------ core/types/gen_header_json.go | 7 --- 5 files changed, 82 deletions(-) delete mode 100644 core/types/block_test.go diff --git a/consensus/bft.go b/consensus/bft.go index d8fc9247a..eb37cda21 100644 --- a/consensus/bft.go +++ b/consensus/bft.go @@ -90,7 +90,6 @@ func (bft *Bft) SealHash(header *types.Header) (hash common.Hash) { rlp.Encode(hasher, []interface{}{ header.ParentHash, - header.UncleHash, header.Coinbase, header.Root, header.TxHash, diff --git a/core/rawdb/accessors_chain_test.go b/core/rawdb/accessors_chain_test.go index b2289d81e..526842d55 100644 --- a/core/rawdb/accessors_chain_test.go +++ b/core/rawdb/accessors_chain_test.go @@ -106,7 +106,6 @@ func TestBlockStorage(t *testing.T) { // Create a test block to move around the database and make sure it's really new block := types.NewBlockWithHeader(&types.Header{ Extra: []byte("test block"), - UncleHash: types.EmptyUncleHash, TxHash: types.EmptyRootHash, ReceiptHash: types.EmptyRootHash, }) @@ -154,7 +153,6 @@ func TestPartialBlockStorage(t *testing.T) { db := ethdb.NewMemDatabase() block := types.NewBlockWithHeader(&types.Header{ Extra: []byte("test block"), - UncleHash: types.EmptyUncleHash, TxHash: types.EmptyRootHash, ReceiptHash: types.EmptyRootHash, }) diff --git a/core/types/block.go b/core/types/block.go index 14e22686a..cdd53a375 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -69,7 +69,6 @@ func (n *BlockNonce) UnmarshalText(input []byte) error { // Header represents a block header in the Ethereum blockchain. 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"` @@ -287,7 +286,6 @@ func (b *Block) Root() common.Hash { return b.header.Root } func (b *Block) ParentHash() common.Hash { return b.header.ParentHash } 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) Header() *Header { return CopyHeader(b.header) } diff --git a/core/types/block_test.go b/core/types/block_test.go deleted file mode 100644 index a35fbc25b..000000000 --- a/core/types/block_test.go +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2014 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package types - -import ( - "bytes" - "fmt" - "math/big" - "reflect" - "testing" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/rlp" -) - -// from bcValidBlockTest.json, "SimpleTx" -func TestBlockEncoding(t *testing.T) { - blockEnc := common.FromHex("f90260f901f9a083cafc574e1f51ba9dc0568fc617a08ea2429fb384059c972f13b19fa1c8dd55a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a05fe50b260da6308036625b850b5d6ced6d0a9f814c0688bc91ffb7b7a3a54b67a0bc37d79753ad738a6dac4921e57392f145d8887476de3f783dfa7edae9283e52b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845506eb0780a0bd4472abb6659ebe3ee06ee4d7b72a00a9f4d001caca51342001075469aff49888a13a5a8c8f2bb1c4f861f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba09bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094fa08a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b1c0") - 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("0a5843ac1cb04865017cb35a57b50b07084e5fcee39b5acadade33149f4fff9e")) - check("Nonce", block.Nonce(), uint64(0xa13a5a8c8f2bb1c4)) - check("Time", block.Time(), big.NewInt(1426516743)) - check("Size", block.Size(), common.StorageSize(len(blockEnc))) - - tx1 := NewTransaction(0, common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), big.NewInt(10), 50000, big.NewInt(10), nil) - - tx1, _ = tx1.WithSignature(HomesteadSigner{}, common.Hex2Bytes("9bea4c4daac7c7c52e093e6a4c35dbbcf8856f1af7b059ba20253e70848d094f8a8fae537ce25ed8cb5af9adac3f141af69bd515bd2ba031522df09b97dd72b100")) - fmt.Println(block.Transactions()[0].Hash()) - fmt.Println(tx1.data) - fmt.Println(tx1.Hash()) - 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) - } -} diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index 1b92cd9cf..d2c655941 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -16,7 +16,6 @@ var _ = (*headerMarshaling)(nil) func (h Header) MarshalJSON() ([]byte, error) { 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"` @@ -34,7 +33,6 @@ func (h Header) MarshalJSON() ([]byte, error) { } var enc Header enc.ParentHash = h.ParentHash - enc.UncleHash = h.UncleHash enc.Coinbase = h.Coinbase enc.Root = h.Root enc.TxHash = h.TxHash @@ -55,7 +53,6 @@ func (h Header) MarshalJSON() ([]byte, error) { func (h *Header) UnmarshalJSON(input []byte) error { 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"` @@ -78,10 +75,6 @@ func (h *Header) UnmarshalJSON(input []byte) error { return errors.New("missing required field 'parentHash' for Header") } h.ParentHash = *dec.ParentHash - if dec.UncleHash == nil { - return errors.New("missing required field 'sha3Uncles' for Header") - } - h.UncleHash = *dec.UncleHash if dec.Coinbase == nil { return errors.New("missing required field 'miner' for Header") }