|
|
@ -53,25 +53,29 @@ func ReadTxLookupEntry(db ethdb.Reader, hash common.Hash) *uint64 { |
|
|
|
return &entry.BlockIndex |
|
|
|
return &entry.BlockIndex |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// WriteTxLookupEntries stores a positional metadata for every transaction from
|
|
|
|
// writeTxLookupEntry stores a positional metadata for a transaction,
|
|
|
|
// a block, enabling hash based transaction and receipt lookups.
|
|
|
|
// enabling hash based transaction and receipt lookups.
|
|
|
|
func WriteTxLookupEntries(db ethdb.KeyValueWriter, block *types.Block) { |
|
|
|
func writeTxLookupEntry(db ethdb.KeyValueWriter, hash common.Hash, numberBytes []byte) { |
|
|
|
number := block.Number().Bytes() |
|
|
|
if err := db.Put(txLookupKey(hash), numberBytes); err != nil { |
|
|
|
for _, tx := range block.Transactions() { |
|
|
|
|
|
|
|
if err := db.Put(txLookupKey(tx.Hash()), number); err != nil { |
|
|
|
|
|
|
|
log.Crit("Failed to store transaction lookup entry", "err", err) |
|
|
|
log.Crit("Failed to store transaction lookup entry", "err", err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// WriteTxLookupEntriesByHash is identical to WriteTxLookupEntries, but does not
|
|
|
|
// WriteTxLookupEntries is identical to WriteTxLookupEntry, but it works on
|
|
|
|
// require a full types.Block as input.
|
|
|
|
// a list of hashes
|
|
|
|
func WriteTxLookupEntriesByHash(db ethdb.KeyValueWriter, number uint64, hashes []common.Hash) { |
|
|
|
func WriteTxLookupEntries(db ethdb.KeyValueWriter, number uint64, hashes []common.Hash) { |
|
|
|
numberBytes := new(big.Int).SetUint64(number).Bytes() |
|
|
|
numberBytes := new(big.Int).SetUint64(number).Bytes() |
|
|
|
for _, hash := range hashes { |
|
|
|
for _, hash := range hashes { |
|
|
|
if err := db.Put(txLookupKey(hash), numberBytes); err != nil { |
|
|
|
writeTxLookupEntry(db, hash, numberBytes) |
|
|
|
log.Crit("Failed to store transaction lookup entry", "err", err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// WriteTxLookupEntriesByBlock stores a positional metadata for every transaction from
|
|
|
|
|
|
|
|
// a block, enabling hash based transaction and receipt lookups.
|
|
|
|
|
|
|
|
func WriteTxLookupEntriesByBlock(db ethdb.KeyValueWriter, block *types.Block) { |
|
|
|
|
|
|
|
numberBytes := block.Number().Bytes() |
|
|
|
|
|
|
|
for _, tx := range block.Transactions() { |
|
|
|
|
|
|
|
writeTxLookupEntry(db, tx.Hash(), numberBytes) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -83,11 +87,9 @@ func DeleteTxLookupEntry(db ethdb.KeyValueWriter, hash common.Hash) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DeleteTxLookupEntries removes all transaction lookups for a given block.
|
|
|
|
// DeleteTxLookupEntries removes all transaction lookups for a given block.
|
|
|
|
func DeleteTxLookupEntriesByHash(db ethdb.KeyValueWriter, hashes []common.Hash) { |
|
|
|
func DeleteTxLookupEntries(db ethdb.KeyValueWriter, hashes []common.Hash) { |
|
|
|
for _, hash := range hashes { |
|
|
|
for _, hash := range hashes { |
|
|
|
if err := db.Delete(txLookupKey(hash)); err != nil { |
|
|
|
DeleteTxLookupEntry(db, hash) |
|
|
|
log.Crit("Failed to delete transaction lookup entry", "err", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|