diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index 80ec073c82..c54948122d 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -234,9 +234,17 @@ func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts { return receipts } -// GetRawReceiptsByHash retrieves the receipts for all transactions in a given block +// GetRawReceipts retrieves the receipts for all transactions in a given block // without deriving the internal fields and the Bloom. -func (bc *BlockChain) GetRawReceiptsByHash(hash common.Hash) rlp.RawValue { +func (bc *BlockChain) GetRawReceipts(hash common.Hash, number uint64) types.Receipts { + if receipts, ok := bc.receiptsCache.Get(hash); ok { + return receipts + } + return rawdb.ReadRawReceipts(bc.db, hash, number) +} + +// GetReceiptsRLP retrieves the receipts of a block. +func (bc *BlockChain) GetReceiptsRLP(hash common.Hash) rlp.RawValue { number := rawdb.ReadHeaderNumber(bc.db, hash) if number == nil { return nil diff --git a/core/filtermaps/chain_view.go b/core/filtermaps/chain_view.go index 874ff19e31..433ca07cd0 100644 --- a/core/filtermaps/chain_view.go +++ b/core/filtermaps/chain_view.go @@ -29,7 +29,7 @@ type blockchain interface { GetHeader(hash common.Hash, number uint64) *types.Header GetCanonicalHash(number uint64) common.Hash GetReceiptsByHash(hash common.Hash) types.Receipts - GetRawReceiptsByHash(hash common.Hash) types.Receipts + GetRawReceipts(hash common.Hash, number uint64) types.Receipts } // ChainView represents an immutable view of a chain with a block id and a set @@ -117,7 +117,7 @@ func (cv *ChainView) RawReceipts(number uint64) types.Receipts { log.Error("Chain view: block hash unavailable", "number", number, "head", cv.headNumber) return nil } - return cv.chain.GetRawReceiptsByHash(blockHash) + return cv.chain.GetRawReceipts(blockHash, number) } // SharedRange returns the block range shared by two chain views. diff --git a/core/filtermaps/indexer_test.go b/core/filtermaps/indexer_test.go index 2782b2cbe6..5ed397a90e 100644 --- a/core/filtermaps/indexer_test.go +++ b/core/filtermaps/indexer_test.go @@ -515,7 +515,7 @@ func (tc *testChain) GetReceiptsByHash(hash common.Hash) types.Receipts { return tc.receipts[hash] } -func (tc *testChain) GetRawReceiptsByHash(hash common.Hash) types.Receipts { +func (tc *testChain) GetRawReceipts(hash common.Hash, number uint64) types.Receipts { tc.lock.RLock() defer tc.lock.RUnlock() diff --git a/eth/filters/filter_system_test.go b/eth/filters/filter_system_test.go index 122bdaeda4..85d4a33913 100644 --- a/eth/filters/filter_system_test.go +++ b/eth/filters/filter_system_test.go @@ -80,11 +80,8 @@ func (b *testBackend) GetReceiptsByHash(hash common.Hash) types.Receipts { return r } -func (b *testBackend) GetRawReceiptsByHash(hash common.Hash) types.Receipts { - if number := rawdb.ReadHeaderNumber(b.db, hash); number != nil { - return rawdb.ReadRawReceipts(b.db, hash, *number) - } - return nil +func (b *testBackend) GetRawReceipts(hash common.Hash, number uint64) types.Receipts { + return rawdb.ReadRawReceipts(b.db, hash, number) } func (b *testBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*types.Header, error) { diff --git a/eth/protocols/eth/handlers.go b/eth/protocols/eth/handlers.go index 3e2dd4537e..15ad048bcf 100644 --- a/eth/protocols/eth/handlers.go +++ b/eth/protocols/eth/handlers.go @@ -282,7 +282,7 @@ func ServiceGetReceiptsQuery68(chain *core.BlockChain, query GetReceiptsRequest) break } // Retrieve the requested block's receipts - results := chain.GetRawReceiptsByHash(hash) + results := chain.GetReceiptsRLP(hash) if results == nil { if header := chain.GetHeaderByHash(hash); header == nil || header.ReceiptHash != types.EmptyRootHash { continue @@ -319,7 +319,7 @@ func serviceGetReceiptsQuery69(chain *core.BlockChain, query GetReceiptsRequest) break } // Retrieve the requested block's receipts - results := chain.GetRawReceiptsByHash(hash) + results := chain.GetReceiptsRLP(hash) if results == nil { if header := chain.GetHeaderByHash(hash); header == nil || header.ReceiptHash != types.EmptyRootHash { continue