refactor: fetch tipset blocks in parallel

This commit is contained in:
Dirk McCormick 2020-09-28 15:56:44 +02:00
parent b14afba859
commit 6b16d48bad

View File

@ -10,6 +10,8 @@ import (
"strconv" "strconv"
"sync" "sync"
"golang.org/x/sync/errgroup"
"github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/crypto"
"github.com/minio/blake2b-simd" "github.com/minio/blake2b-simd"
@ -467,14 +469,25 @@ func (cs *ChainStore) LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error) {
return v.(*types.TipSet), nil return v.(*types.TipSet), nil
} }
var blks []*types.BlockHeader // Fetch tipset block headers from blockstore in parallel
for _, c := range tsk.Cids() { var eg errgroup.Group
cids := tsk.Cids()
blks := make([]*types.BlockHeader, 0, len(cids))
for _, c := range cids {
c := c
eg.Go(func() error {
b, err := cs.GetBlock(c) b, err := cs.GetBlock(c)
if err != nil { if err != nil {
return nil, xerrors.Errorf("get block %s: %w", c, err) return xerrors.Errorf("get block %s: %w", c, err)
} }
blks = append(blks, b) blks = append(blks, b)
return nil
})
}
err := eg.Wait()
if err != nil {
return nil, err
} }
ts, err := types.NewTipSet(blks) ts, err := types.NewTipSet(blks)