Skip to content

Commit

Permalink
add nil check for curTs -- some tests don't have chain state
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Dec 1, 2020
1 parent b489595 commit f2f01d9
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions chain/store/splitstore/splitstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func (s *SplitStore) GetSize(cid cid.Cid) (int, error) {

func (s *SplitStore) Put(blk blocks.Block) error {
s.mx.Lock()
if s.curTs == nil {
s.mx.Unlock()
return s.cold.Put(blk)
}

epoch := s.curTs.Height()
s.mx.Unlock()

Expand All @@ -147,16 +152,21 @@ func (s *SplitStore) Put(blk blocks.Block) error {
}

func (s *SplitStore) PutMany(blks []blocks.Block) error {
err := s.hot.PutMany(blks)
if err != nil {
log.Errorf("error tracking CIDs in hotstore: %s; falling back to coldstore", err)
s.mx.Lock()
if s.curTs == nil {
s.mx.Unlock()
return s.cold.PutMany(blks)
}

s.mx.Lock()
epoch := s.curTs.Height()
s.mx.Unlock()

err := s.hot.PutMany(blks)
if err != nil {
log.Errorf("error tracking CIDs in hotstore: %s; falling back to coldstore", err)
return s.cold.PutMany(blks)
}

batch := make([]cid.Cid, 0, len(blks))
for _, blk := range blks {
batch = append(batch, blk.Cid())
Expand Down Expand Up @@ -228,6 +238,11 @@ func (s *SplitStore) Start(cs *store.ChainStore) error {
s.baseEpoch = bytesToEpoch(bs)

case dstore.ErrNotFound:
if s.curTs == nil {
// this can happen in some tests
break
}

err = s.setBaseEpoch(s.curTs.Height())
if err != nil {
return err
Expand Down

0 comments on commit f2f01d9

Please sign in to comment.