From 7bced1532b93ee7bd3757aca247249f67b953e33 Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Tue, 6 Apr 2021 13:01:48 +0200 Subject: [PATCH] Convert the chainstore lock to RW High read-API concurrency facilitates multiple calls to GetHeaviestTipSet which in turn could slow down chainsync. --- chain/store/store.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/chain/store/store.go b/chain/store/store.go index e0d71f0304b..7ebe31ec4bf 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -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 {