Skip to content

Commit

Permalink
Merge pull request #5971 from filecoin-project/chore/switch_lock_to_rw
Browse files Browse the repository at this point in the history
Convert the chainstore lock to RW
  • Loading branch information
magik6k authored Apr 6, 2021
2 parents 79194cc + 7bced15 commit 2eda5e8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions chain/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ type ChainStore struct {

chainLocalBlockstore bstore.Blockstore

heaviestLk sync.Mutex
heaviestLk sync.RWMutex
heaviest *types.TipSet

bestTips *pubsub.PubSub
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2eda5e8

Please sign in to comment.