diff --git a/blockstore/splitstore/splitstore.go b/blockstore/splitstore/splitstore.go index d1410d556..8fef0ee0a 100644 --- a/blockstore/splitstore/splitstore.go +++ b/blockstore/splitstore/splitstore.go @@ -998,14 +998,23 @@ func (s *SplitStore) doCompact(curTs *types.TipSet) error { } func (s *SplitStore) walk(ts *types.TipSet, boundary abi.ChainEpoch, inclMsgs bool, f func(cid.Cid) error) error { + visited := cid.NewSet() walked := cid.NewSet() toWalk := ts.Cids() walkBlock := func(c cid.Cid) error { - if !walked.Visit(c) { + if !visited.Visit(c) { return nil } + // check if it has been referenced by some later state root via lookback to avoid duplicate + // dispatches to the visitor + if !walked.Has(c) { + if err := f(c); err != nil { + return err + } + } + blk, err := s.get(c) if err != nil { return xerrors.Errorf("error retrieving block (cid: %s): %w", c, err) @@ -1021,10 +1030,6 @@ func (s *SplitStore) walk(ts *types.TipSet, boundary abi.ChainEpoch, inclMsgs bo return nil } - if err := f(c); err != nil { - return err - } - if hdr.Height >= boundary { if inclMsgs { if err := s.walkLinks(hdr.Messages, walked, f); err != nil {