|
|
|
@ -55,6 +55,7 @@ var ( |
|
|
|
|
const ( |
|
|
|
|
bodyCacheLimit = 256 |
|
|
|
|
blockCacheLimit = 256 |
|
|
|
|
receiptsCacheLimit = 32 |
|
|
|
|
maxFutureBlocks = 256 |
|
|
|
|
maxTimeFutureBlocks = 30 |
|
|
|
|
badBlockLimit = 10 |
|
|
|
@ -114,6 +115,7 @@ type BlockChain struct { |
|
|
|
|
stateCache state.Database // State database to reuse between imports (contains state cache)
|
|
|
|
|
bodyCache *lru.Cache // Cache for the most recent block bodies
|
|
|
|
|
bodyRLPCache *lru.Cache // Cache for the most recent block bodies in RLP encoded format
|
|
|
|
|
receiptsCache *lru.Cache // Cache for the most recent receipts per block
|
|
|
|
|
blockCache *lru.Cache // Cache for the most recent entire blocks
|
|
|
|
|
futureBlocks *lru.Cache // future blocks are blocks added for later processing
|
|
|
|
|
|
|
|
|
@ -144,6 +146,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par |
|
|
|
|
} |
|
|
|
|
bodyCache, _ := lru.New(bodyCacheLimit) |
|
|
|
|
bodyRLPCache, _ := lru.New(bodyCacheLimit) |
|
|
|
|
receiptsCache, _ := lru.New(receiptsCacheLimit) |
|
|
|
|
blockCache, _ := lru.New(blockCacheLimit) |
|
|
|
|
futureBlocks, _ := lru.New(maxFutureBlocks) |
|
|
|
|
badBlocks, _ := lru.New(badBlockLimit) |
|
|
|
@ -158,6 +161,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par |
|
|
|
|
shouldPreserve: shouldPreserve, |
|
|
|
|
bodyCache: bodyCache, |
|
|
|
|
bodyRLPCache: bodyRLPCache, |
|
|
|
|
receiptsCache: receiptsCache, |
|
|
|
|
blockCache: blockCache, |
|
|
|
|
futureBlocks: futureBlocks, |
|
|
|
|
engine: engine, |
|
|
|
@ -280,6 +284,7 @@ func (bc *BlockChain) SetHead(head uint64) error { |
|
|
|
|
// Clear out any stale content from the caches
|
|
|
|
|
bc.bodyCache.Purge() |
|
|
|
|
bc.bodyRLPCache.Purge() |
|
|
|
|
bc.receiptsCache.Purge() |
|
|
|
|
bc.blockCache.Purge() |
|
|
|
|
bc.futureBlocks.Purge() |
|
|
|
|
|
|
|
|
@ -603,11 +608,18 @@ func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block { |
|
|
|
|
|
|
|
|
|
// GetReceiptsByHash retrieves the receipts for all transactions in a given block.
|
|
|
|
|
func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts { |
|
|
|
|
if receipts, ok := bc.receiptsCache.Get(hash); ok { |
|
|
|
|
return receipts.(types.Receipts) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
number := rawdb.ReadHeaderNumber(bc.db, hash) |
|
|
|
|
if number == nil { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
return rawdb.ReadReceipts(bc.db, hash, *number) |
|
|
|
|
|
|
|
|
|
receipts := rawdb.ReadReceipts(bc.db, hash, *number) |
|
|
|
|
bc.receiptsCache.Add(hash, receipts) |
|
|
|
|
return receipts |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// GetBlocksFromHash returns the block corresponding to hash and up to n-1 ancestors.
|
|
|
|
|