mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/rawdb: drop txlookup entry struct wrapper
This commit is contained in:
parent
3d5019b62b
commit
e8b4262c40
3 changed files with 9 additions and 22 deletions
|
|
@ -30,15 +30,14 @@ func ReadTxLookupEntry(db DatabaseReader, hash common.Hash) common.Hash {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return common.Hash{}
|
return common.Hash{}
|
||||||
}
|
}
|
||||||
var entry TxLookupEntry
|
if len(data) == common.HashLength {
|
||||||
if err := rlp.DecodeBytes(data, &entry); err != nil {
|
return common.BytesToHash(data)
|
||||||
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
|
// 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
|
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.
|
// a block, enabling hash based transaction and receipt lookups.
|
||||||
func WriteTxLookupEntries(db DatabaseWriter, block *types.Block) {
|
func WriteTxLookupEntries(db DatabaseWriter, block *types.Block) {
|
||||||
for _, tx := range block.Transactions() {
|
for _, tx := range block.Transactions() {
|
||||||
entry := TxLookupEntry{
|
if err := db.Put(txLookupKey(tx.Hash()), block.Hash().Bytes()); err != nil {
|
||||||
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 {
|
|
||||||
log.Crit("Failed to store transaction lookup entry", "err", err)
|
log.Crit("Failed to store transaction lookup entry", "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,12 +71,6 @@ type LegacyTxLookupEntry struct {
|
||||||
Index uint64
|
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
|
// encodeBlockNumber encodes a block number as big endian uint64
|
||||||
func encodeBlockNumber(number uint64) []byte {
|
func encodeBlockNumber(number uint64) []byte {
|
||||||
enc := make([]byte, 8)
|
enc := make([]byte, 8)
|
||||||
|
|
|
||||||
|
|
@ -206,6 +206,7 @@ func (r *ReceiptForStorage) DecodeRLP(s *rlp.Stream) error {
|
||||||
for i, log := range dec.Logs {
|
for i, log := range dec.Logs {
|
||||||
r.Logs[i] = (*Log)(log)
|
r.Logs[i] = (*Log)(log)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Bloom = CreateBloom(Receipts{(*Receipt)(r)})
|
r.Bloom = CreateBloom(Receipts{(*Receipt)(r)})
|
||||||
// Assign the implementation fields
|
// Assign the implementation fields
|
||||||
r.TxHash, r.ContractAddress, r.GasUsed = dec.TxHash, dec.ContractAddress, dec.GasUsed
|
r.TxHash, r.ContractAddress, r.GasUsed = dec.TxHash, dec.ContractAddress, dec.GasUsed
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue