Merge pull request #5971 from filecoin-project/chore/switch_lock_to_rw

Convert the chainstore lock to RW
This commit is contained in:
Łukasz Magiera 2021-04-06 15:27:20 +02:00 committed by GitHub
commit 2eda5e8284
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,7 +113,7 @@ type ChainStore struct {
chainLocalBlockstore bstore.Blockstore
heaviestLk sync.Mutex
heaviestLk sync.RWMutex
heaviest *types.TipSet
bestTips *pubsub.PubSub
@ -775,10 +775,11 @@ func ReorgOps(lts func(types.TipSetKey) (*types.TipSet, error), a, b *types.TipS
}
// GetHeaviestTipSet returns the current heaviest tipset known (i.e. our head).
func (cs *ChainStore) GetHeaviestTipSet() *types.TipSet {
cs.heaviestLk.Lock()
defer cs.heaviestLk.Unlock()
return cs.heaviest
func (cs *ChainStore) GetHeaviestTipSet() (ts *types.TipSet) {
cs.heaviestLk.RLock()
ts = cs.heaviest
cs.heaviestLk.RUnlock()
return
}
func (cs *ChainStore) AddToTipSetTracker(b *types.BlockHeader) error {