diff options
author | gary rong <garyrong0905@gmail.com> | 2019-08-21 17:29:34 +0800 |
---|---|---|
committer | Felföldi Zsolt <zsfelfoldi@gmail.com> | 2019-08-21 17:29:34 +0800 |
commit | 2ed729d38e90154d1f23ebdf5a9f2808212276d8 (patch) | |
tree | 04aad0e43f8a0b191809a86a2b665535f1f87a93 /core | |
parent | 4aee0d1994ad286c18aa3a586ae950e96979a7f1 (diff) | |
download | go-tangerine-2ed729d38e90154d1f23ebdf5a9f2808212276d8.tar go-tangerine-2ed729d38e90154d1f23ebdf5a9f2808212276d8.tar.gz go-tangerine-2ed729d38e90154d1f23ebdf5a9f2808212276d8.tar.bz2 go-tangerine-2ed729d38e90154d1f23ebdf5a9f2808212276d8.tar.lz go-tangerine-2ed729d38e90154d1f23ebdf5a9f2808212276d8.tar.xz go-tangerine-2ed729d38e90154d1f23ebdf5a9f2808212276d8.tar.zst go-tangerine-2ed729d38e90154d1f23ebdf5a9f2808212276d8.zip |
les: handler separation (#19639)
les: handler separation
Diffstat (limited to 'core')
-rw-r--r-- | core/blockchain.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 361fa8243..2fd373c7c 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -75,6 +75,7 @@ const ( bodyCacheLimit = 256 blockCacheLimit = 256 receiptsCacheLimit = 32 + txLookupCacheLimit = 1024 maxFutureBlocks = 256 maxTimeFutureBlocks = 30 badBlockLimit = 10 @@ -155,6 +156,7 @@ type BlockChain struct { 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 + txLookupCache *lru.Cache // Cache for the most recent transaction lookup data. futureBlocks *lru.Cache // future blocks are blocks added for later processing quit chan struct{} // blockchain quit channel @@ -189,6 +191,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par bodyRLPCache, _ := lru.New(bodyCacheLimit) receiptsCache, _ := lru.New(receiptsCacheLimit) blockCache, _ := lru.New(blockCacheLimit) + txLookupCache, _ := lru.New(txLookupCacheLimit) futureBlocks, _ := lru.New(maxFutureBlocks) badBlocks, _ := lru.New(badBlockLimit) @@ -204,6 +207,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par bodyRLPCache: bodyRLPCache, receiptsCache: receiptsCache, blockCache: blockCache, + txLookupCache: txLookupCache, futureBlocks: futureBlocks, engine: engine, vmConfig: vmConfig, @@ -440,6 +444,7 @@ func (bc *BlockChain) SetHead(head uint64) error { bc.bodyRLPCache.Purge() bc.receiptsCache.Purge() bc.blockCache.Purge() + bc.txLookupCache.Purge() bc.futureBlocks.Purge() return bc.loadLastState() @@ -921,6 +926,7 @@ func (bc *BlockChain) truncateAncient(head uint64) error { bc.bodyRLPCache.Purge() bc.receiptsCache.Purge() bc.blockCache.Purge() + bc.txLookupCache.Purge() bc.futureBlocks.Purge() log.Info("Rewind ancient data", "number", head) @@ -2151,6 +2157,22 @@ func (bc *BlockChain) GetHeaderByNumber(number uint64) *types.Header { return bc.hc.GetHeaderByNumber(number) } +// GetTransactionLookup retrieves the lookup associate with the given transaction +// hash from the cache or database. +func (bc *BlockChain) GetTransactionLookup(hash common.Hash) *rawdb.LegacyTxLookupEntry { + // Short circuit if the txlookup already in the cache, retrieve otherwise + if lookup, exist := bc.txLookupCache.Get(hash); exist { + return lookup.(*rawdb.LegacyTxLookupEntry) + } + tx, blockHash, blockNumber, txIndex := rawdb.ReadTransaction(bc.db, hash) + if tx == nil { + return nil + } + lookup := &rawdb.LegacyTxLookupEntry{BlockHash: blockHash, BlockIndex: blockNumber, Index: txIndex} + bc.txLookupCache.Add(hash, lookup) + return lookup +} + // Config retrieves the chain's fork configuration. func (bc *BlockChain) Config() *params.ChainConfig { return bc.chainConfig } |