core/rawdb: drop txlookup entry struct wrapper

This commit is contained in:
rjl493456442 2019-02-21 19:20:33 +08:00
parent 3d5019b62b
commit e8b4262c40
3 changed files with 9 additions and 22 deletions

View file

@ -30,15 +30,14 @@ func ReadTxLookupEntry(db DatabaseReader, hash common.Hash) common.Hash {
if len(data) == 0 {
return common.Hash{}
}
var entry TxLookupEntry
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{}
if len(data) == common.HashLength {
return common.BytesToHash(data)
}
entry.BlockHash = dec.BlockHash
// Probably it's legacy txlookup entry data, try to decode it.
var entry LegacyTxLookupEntry
if err := rlp.DecodeBytes(data, &entry); err != nil {
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)
}
}

View file

@ -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)

View file

@ -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