core: improve locking in storeBlock
Getting batch, updating Prometheus metrics and pushing events doesn't require any locking: batch is a local cache batch that no one outside cares about, Prometheus metrics are not critical to be in perfect sync and events are asynchronous anyway.
This commit is contained in:
parent
5464f9c3ae
commit
9454ef5c28
1 changed files with 5 additions and 3 deletions
|
@ -818,21 +818,23 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bc.lock.Lock()
|
|
||||||
defer bc.lock.Unlock()
|
|
||||||
|
|
||||||
if bc.config.SaveStorageBatch {
|
if bc.config.SaveStorageBatch {
|
||||||
bc.lastBatch = cache.DAO.GetBatch()
|
bc.lastBatch = cache.DAO.GetBatch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bc.lock.Lock()
|
||||||
_, err := cache.Persist()
|
_, err := cache.Persist()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
bc.lock.Unlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
bc.topBlock.Store(block)
|
bc.topBlock.Store(block)
|
||||||
atomic.StoreUint32(&bc.blockHeight, block.Index)
|
atomic.StoreUint32(&bc.blockHeight, block.Index)
|
||||||
updateBlockHeightMetric(block.Index)
|
|
||||||
bc.memPool.RemoveStale(bc.isTxStillRelevant)
|
bc.memPool.RemoveStale(bc.isTxStillRelevant)
|
||||||
|
bc.lock.Unlock()
|
||||||
|
|
||||||
|
updateBlockHeightMetric(block.Index)
|
||||||
// Genesis block is stored when Blockchain is not yet running, so there
|
// Genesis block is stored when Blockchain is not yet running, so there
|
||||||
// is no one to read this event. And it doesn't make much sense as event
|
// is no one to read this event. And it doesn't make much sense as event
|
||||||
// anyway.
|
// anyway.
|
||||||
|
|
Loading…
Add table
Reference in a new issue