mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
core: reduce lock contention in HasCanonicalTransaction
Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
parent
259705a9e8
commit
8197ceef16
1 changed files with 4 additions and 3 deletions
|
|
@ -328,13 +328,14 @@ func (bc *BlockChain) GetAncestor(hash common.Hash, number, ancestor uint64, max
|
|||
// The cacheOnly flag restricts the check to the in-memory cache, avoiding database
|
||||
// access altogether.
|
||||
func (bc *BlockChain) HasCanonicalTransaction(hash common.Hash, cacheOnly bool) bool {
|
||||
bc.txLookupLock.RLock()
|
||||
defer bc.txLookupLock.RUnlock()
|
||||
|
||||
// Check in memory cache first
|
||||
bc.txLookupLock.RLock()
|
||||
if _, exist := bc.txLookupCache.Get(hash); exist {
|
||||
bc.txLookupLock.RUnlock()
|
||||
return true
|
||||
}
|
||||
bc.txLookupLock.RUnlock()
|
||||
|
||||
// Fallback to database lookup, without reading the transaction itself
|
||||
if !cacheOnly && rawdb.HasCanonicalTransaction(bc.db, hash) {
|
||||
return true
|
||||
|
|
|
|||
Loading…
Reference in a new issue