From f2f01d96d82349a3bcc5393ed64285d123de1898 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 1 Dec 2020 17:56:22 +0200 Subject: [PATCH] add nil check for curTs -- some tests don't have chain state --- chain/store/splitstore/splitstore.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/chain/store/splitstore/splitstore.go b/chain/store/splitstore/splitstore.go index 5ae97a1ef82..751ab2a5641 100644 --- a/chain/store/splitstore/splitstore.go +++ b/chain/store/splitstore/splitstore.go @@ -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() @@ -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()) @@ -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