diff --git a/core/blockchain.go b/core/blockchain.go index f103abdb5a..bb1c14f437 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -759,7 +759,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [ log.Crit("Failed to write log blooms", "err", err) return } - if err := WriteLookupEntries(bc.chainDb, block); err != nil { + if err := WriteTxLookupEntries(bc.chainDb, block); err != nil { errs[index] = fmt.Errorf("failed to write lookup metadata: %v", err) atomic.AddInt32(&failed, 1) log.Crit("Failed to write lookup metadata", "err", err) @@ -997,7 +997,7 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) { events = append(events, ChainEvent{block, block.Hash(), logs}) // Write the positional metadata for transaction and receipt lookups - if err := WriteLookupEntries(bc.chainDb, block); err != nil { + if err := WriteTxLookupEntries(bc.chainDb, block); err != nil { return i, err } // Write map map bloom filters @@ -1158,7 +1158,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { // insert the block in the canonical way, re-writing history bc.insert(block) // write lookup entries for hash based transaction/receipt searches - if err := WriteLookupEntries(bc.chainDb, block); err != nil { + if err := WriteTxLookupEntries(bc.chainDb, block); err != nil { return err } // Write map map bloom filters @@ -1174,7 +1174,7 @@ func (bc *BlockChain) reorg(oldBlock, newBlock *types.Block) error { // When transactions get deleted from the database that means the // receipts that were created in the fork must also be deleted for _, tx := range diff { - DeleteLookupEntry(bc.chainDb, tx.Hash()) + DeleteTxLookupEntry(bc.chainDb, tx.Hash()) } // Must be posted in a goroutine because of the transaction pool trying // to acquire the chain manager lock diff --git a/core/database_util.go b/core/database_util.go index 7e9afd40d1..6971113944 100644 --- a/core/database_util.go +++ b/core/database_util.go @@ -65,9 +65,9 @@ var ( preimageHitCounter = metrics.NewCounter("db/preimage/hits") ) -// lookupEntry is a positional metadata to help looking up the data content of +// txLookupEntry is a positional metadata to help looking up the data content of // a transaction or receipt given only its hash. -type lookupEntry struct { +type txLookupEntry struct { BlockHash common.Hash BlockIndex uint64 Index uint64 @@ -234,16 +234,16 @@ func GetBlockReceipts(db ethdb.Database, hash common.Hash, number uint64) types. return receipts } -// GetLookupEntry retrieves the positional metadata associated with a transaction +// GetTxLookupEntry retrieves the positional metadata associated with a transaction // hash to allow retrieving the transaction or receipt by hash. -func GetLookupEntry(db ethdb.Database, hash common.Hash) (common.Hash, uint64, uint64) { +func GetTxLookupEntry(db ethdb.Database, hash common.Hash) (common.Hash, uint64, uint64) { // Load the positional metadata from disk and bail if it fails data, _ := db.Get(append(lookupPrefix, hash.Bytes()...)) if len(data) == 0 { return common.Hash{}, 0, 0 } // Parse and return the contents of the lookup entry - var entry lookupEntry + var entry txLookupEntry if err := rlp.DecodeBytes(data, &entry); err != nil { log.Error("Invalid lookup entry RLP", "hash", hash, "err", err) return common.Hash{}, 0, 0 @@ -255,7 +255,7 @@ func GetLookupEntry(db ethdb.Database, hash common.Hash) (common.Hash, uint64, u // its added positional metadata. func GetTransaction(db ethdb.Database, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) { // Retrieve the lookup metadata and resolve the transaction from the body - blockHash, blockNumber, txIndex := GetLookupEntry(db, hash) + blockHash, blockNumber, txIndex := GetTxLookupEntry(db, hash) if blockHash != (common.Hash{}) { body := GetBody(db, blockHash, blockNumber) @@ -279,7 +279,7 @@ func GetTransaction(db ethdb.Database, hash common.Hash) (*types.Transaction, co if len(data) == 0 { return nil, common.Hash{}, 0, 0 } - var entry lookupEntry + var entry txLookupEntry if err := rlp.DecodeBytes(data, &entry); err != nil { return nil, common.Hash{}, 0, 0 } @@ -290,7 +290,7 @@ func GetTransaction(db ethdb.Database, hash common.Hash) (*types.Transaction, co // its added positional metadata. func GetReceipt(db ethdb.Database, hash common.Hash) (*types.Receipt, common.Hash, uint64, uint64) { // Retrieve the lookup metadata and resolve the receipt from the receipts - blockHash, blockNumber, receiptIndex := GetLookupEntry(db, hash) + blockHash, blockNumber, receiptIndex := GetTxLookupEntry(db, hash) if blockHash != (common.Hash{}) { receipts := GetBlockReceipts(db, blockHash, blockNumber) @@ -431,14 +431,14 @@ func WriteBlockReceipts(db ethdb.Database, hash common.Hash, number uint64, rece return nil } -// WriteLookupEntries stores a positional metadata for every transaction from +// WriteTxLookupEntries stores a positional metadata for every transaction from // a block, enabling hash based transaction and receipt lookups. -func WriteLookupEntries(db ethdb.Database, block *types.Block) error { +func WriteTxLookupEntries(db ethdb.Database, block *types.Block) error { batch := db.NewBatch() // Iterate over each transaction and encode its metadata for i, tx := range block.Transactions() { - entry := lookupEntry{ + entry := txLookupEntry{ BlockHash: block.Hash(), BlockIndex: block.NumberU64(), Index: uint64(i), @@ -492,8 +492,8 @@ func DeleteBlockReceipts(db ethdb.Database, hash common.Hash, number uint64) { db.Delete(append(append(blockReceiptsPrefix, encodeBlockNumber(number)...), hash.Bytes()...)) } -// DeleteLookupEntry removes all transaction data associated with a hash. -func DeleteLookupEntry(db ethdb.Database, hash common.Hash) { +// DeleteTxLookupEntry removes all transaction data associated with a hash. +func DeleteTxLookupEntry(db ethdb.Database, hash common.Hash) { db.Delete(append(lookupPrefix, hash.Bytes()...)) } diff --git a/core/database_util_test.go b/core/database_util_test.go index 905f85ae20..e9a6df97b7 100644 --- a/core/database_util_test.go +++ b/core/database_util_test.go @@ -311,7 +311,7 @@ func TestLookupStorage(t *testing.T) { if err := WriteBlock(db, block); err != nil { t.Fatalf("failed to write block contents: %v", err) } - if err := WriteLookupEntries(db, block); err != nil { + if err := WriteTxLookupEntries(db, block); err != nil { t.Fatalf("failed to write transactions: %v", err) } for i, tx := range txs { @@ -328,7 +328,7 @@ func TestLookupStorage(t *testing.T) { } // Delete the transactions and check purge for i, tx := range txs { - DeleteLookupEntry(db, tx.Hash()) + DeleteTxLookupEntry(db, tx.Hash()) if txn, _, _, _ := GetTransaction(db, tx.Hash()); txn != nil { t.Fatalf("tx #%d [%x]: deleted transaction returned: %v", i, tx.Hash(), txn) } diff --git a/light/txpool.go b/light/txpool.go index b0b82c1d50..416148b7e6 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -181,7 +181,7 @@ func (pool *TxPool) checkMinedTxs(ctx context.Context, hash common.Hash, number if _, err := GetBlockReceipts(ctx, pool.odr, hash, number); err != nil { // ODR caches, ignore results return err } - if err := core.WriteLookupEntries(pool.chainDb, block); err != nil { + if err := core.WriteTxLookupEntries(pool.chainDb, block); err != nil { return err } // Update the transaction pool's state @@ -200,7 +200,7 @@ func (pool *TxPool) rollbackTxs(hash common.Hash, txc txStateChanges) { if list, ok := pool.mined[hash]; ok { for _, tx := range list { txHash := tx.Hash() - core.DeleteLookupEntry(pool.chainDb, txHash) + core.DeleteTxLookupEntry(pool.chainDb, txHash) pool.pending[txHash] = tx txc.setState(txHash, false) } diff --git a/miner/worker.go b/miner/worker.go index 7efde21b97..411bc4e1b8 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -293,7 +293,7 @@ func (self *worker) wait() { // check if canon block and write transactions if stat == core.CanonStatTy { // This puts transactions in a extra db for rpc - core.WriteLookupEntries(self.chainDb, block) + core.WriteTxLookupEntries(self.chainDb, block) // Write map map bloom filters core.WriteMipmapBloom(self.chainDb, block.NumberU64(), work.receipts) // implicit by posting ChainHeadEvent