From e8b4262c401885c4f6df93e0fb0f571d0d463905 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Thu, 21 Feb 2019 19:20:33 +0800 Subject: [PATCH] core/rawdb: drop txlookup entry struct wrapper --- core/rawdb/accessors_indexes.go | 24 ++++++++---------------- core/rawdb/schema.go | 6 ------ core/types/receipt.go | 1 + 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/core/rawdb/accessors_indexes.go b/core/rawdb/accessors_indexes.go index bd80b4f6aa..e6f7782a12 100644 --- a/core/rawdb/accessors_indexes.go +++ b/core/rawdb/accessors_indexes.go @@ -30,15 +30,14 @@ func ReadTxLookupEntry(db DatabaseReader, hash common.Hash) common.Hash { if len(data) == 0 { return common.Hash{} } - var entry TxLookupEntry + if len(data) == common.HashLength { + return common.BytesToHash(data) + } + // Probably it's legacy txlookup entry data, try to decode it. + var entry LegacyTxLookupEntry if err := rlp.DecodeBytes(data, &entry); err != nil { - var dec LegacyTxLookupEntry - if err = rlp.DecodeBytes(data, &dec); err != nil { - log.Error("Invalid transaction lookup entry RLP", "hash", hash, "err", err) - return common.Hash{} - } - entry.BlockHash = dec.BlockHash - + log.Error("Invalid transaction lookup entry RLP", "hash", hash, "blob", data, "err", err) + return common.Hash{} } return entry.BlockHash } @@ -47,14 +46,7 @@ func ReadTxLookupEntry(db DatabaseReader, hash common.Hash) common.Hash { // a block, enabling hash based transaction and receipt lookups. func WriteTxLookupEntries(db DatabaseWriter, block *types.Block) { for _, tx := range block.Transactions() { - entry := TxLookupEntry{ - BlockHash: block.Hash(), - } - data, err := rlp.EncodeToBytes(entry) - if err != nil { - log.Crit("Failed to encode transaction lookup entry", "err", err) - } - if err := db.Put(txLookupKey(tx.Hash()), data); err != nil { + if err := db.Put(txLookupKey(tx.Hash()), block.Hash().Bytes()); err != nil { log.Crit("Failed to store transaction lookup entry", "err", err) } } diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index b62efdd539..3bb86e7ffb 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -71,12 +71,6 @@ type LegacyTxLookupEntry struct { Index uint64 } -// TxLookupEntry is a positional metadata to help looking up the data content of -// a transaction or receipt given only its hash. -type TxLookupEntry struct { - BlockHash common.Hash -} - // encodeBlockNumber encodes a block number as big endian uint64 func encodeBlockNumber(number uint64) []byte { enc := make([]byte, 8) diff --git a/core/types/receipt.go b/core/types/receipt.go index 0dfe35e0d8..ac1ebe349b 100644 --- a/core/types/receipt.go +++ b/core/types/receipt.go @@ -206,6 +206,7 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error { for i, log := range dec.Logs { r.Logs[i] = (*Log)(log) } + r.Bloom = CreateBloom(Receipts{(*Receipt)(r)}) // Assign the implementation fields r.TxHash, r.ContractAddress, r.GasUsed = dec.TxHash, dec.ContractAddress, dec.GasUsed