remove the curTs state variable; we don't need it

This commit is contained in:
vyzo 2021-07-07 09:55:25 +03:00
parent 05dbbe9681
commit 6cc2112749

View File

@ -117,14 +117,12 @@ type SplitStore struct {
cfg *Config cfg *Config
mx sync.Mutex
baseEpoch abi.ChainEpoch baseEpoch abi.ChainEpoch
warmupEpoch abi.ChainEpoch warmupEpoch abi.ChainEpoch
coldPurgeSize int coldPurgeSize int
mx sync.Mutex
curTs *types.TipSet
chain ChainAccessor chain ChainAccessor
ds dstore.Datastore ds dstore.Datastore
hot bstore.Blockstore hot bstore.Blockstore
@ -388,7 +386,7 @@ func (s *SplitStore) View(cid cid.Cid, cb func([]byte) error) error {
// State tracking // State tracking
func (s *SplitStore) Start(chain ChainAccessor) error { func (s *SplitStore) Start(chain ChainAccessor) error {
s.chain = chain s.chain = chain
s.curTs = chain.GetHeaviestTipSet() curTs := chain.GetHeaviestTipSet()
// load base epoch from metadata ds // load base epoch from metadata ds
// if none, then use current epoch because it's a fresh start // if none, then use current epoch because it's a fresh start
@ -398,12 +396,12 @@ func (s *SplitStore) Start(chain ChainAccessor) error {
s.baseEpoch = bytesToEpoch(bs) s.baseEpoch = bytesToEpoch(bs)
case dstore.ErrNotFound: case dstore.ErrNotFound:
if s.curTs == nil { if curTs == nil {
// this can happen in some tests // this can happen in some tests
break break
} }
err = s.setBaseEpoch(s.curTs.Height()) err = s.setBaseEpoch(curTs.Height())
if err != nil { if err != nil {
return xerrors.Errorf("error saving base epoch: %w", err) return xerrors.Errorf("error saving base epoch: %w", err)
} }
@ -420,7 +418,7 @@ func (s *SplitStore) Start(chain ChainAccessor) error {
case dstore.ErrNotFound: case dstore.ErrNotFound:
// the hotstore hasn't warmed up, start a concurrent warm up // the hotstore hasn't warmed up, start a concurrent warm up
err = s.warmup(s.curTs) err = s.warmup(curTs)
if err != nil { if err != nil {
return xerrors.Errorf("error warming up: %w", err) return xerrors.Errorf("error warming up: %w", err)
} }
@ -468,11 +466,8 @@ func (s *SplitStore) HeadChange(_, apply []*types.TipSet) error {
return nil return nil
} }
s.mx.Lock()
curTs := apply[len(apply)-1] curTs := apply[len(apply)-1]
epoch := curTs.Height() epoch := curTs.Height()
s.curTs = curTs
s.mx.Unlock()
if !atomic.CompareAndSwapInt32(&s.compacting, 0, 1) { if !atomic.CompareAndSwapInt32(&s.compacting, 0, 1) {
// we are currently compacting -- protect the new tipset(s) // we are currently compacting -- protect the new tipset(s)