fix: unsafe append in LoadTipSet

This commit is contained in:
Dirk McCormick 2020-09-28 16:35:37 +02:00
parent 6b16d48bad
commit cfe6f595b0

View File

@ -472,16 +472,16 @@ func (cs *ChainStore) LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error) {
// Fetch tipset block headers from blockstore in parallel // Fetch tipset block headers from blockstore in parallel
var eg errgroup.Group var eg errgroup.Group
cids := tsk.Cids() cids := tsk.Cids()
blks := make([]*types.BlockHeader, 0, len(cids)) blks := make([]*types.BlockHeader, len(cids))
for _, c := range cids { for i, c := range cids {
c := c i, c := i, c
eg.Go(func() error { eg.Go(func() error {
b, err := cs.GetBlock(c) b, err := cs.GetBlock(c)
if err != nil { if err != nil {
return xerrors.Errorf("get block %s: %w", c, err) return xerrors.Errorf("get block %s: %w", c, err)
} }
blks = append(blks, b) blks[i] = b
return nil return nil
}) })
} }