move bundle fetcher to node/bundle instead of chain/actors

This commit is contained in:
vyzo 2022-05-12 09:51:08 +03:00
parent da8bda3248
commit 26d07fd987
2 changed files with 11 additions and 10 deletions

View File

@ -16,6 +16,7 @@ import (
"github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/blockstore"
"github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/node/bundle"
"github.com/filecoin-project/specs-actors/v8/actors/builtin/manifest" "github.com/filecoin-project/specs-actors/v8/actors/builtin/manifest"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
@ -122,12 +123,12 @@ func CanonicalName(name string) string {
} }
func FetchAndLoadBundle(ctx context.Context, basePath string, bs blockstore.Blockstore, av Version, rel, netw string) (cid.Cid, error) { func FetchAndLoadBundle(ctx context.Context, basePath string, bs blockstore.Blockstore, av Version, rel, netw string) (cid.Cid, error) {
fetcher, err := NewBundleFetcher(basePath) fetcher, err := bundle.NewBundleFetcher(basePath)
if err != nil { if err != nil {
return cid.Undef, xerrors.Errorf("error creating fetcher for builtin-actors version %d: %w", av, err) return cid.Undef, xerrors.Errorf("error creating fetcher for builtin-actors version %d: %w", av, err)
} }
path, err := fetcher.Fetch(av, rel, netw) path, err := fetcher.Fetch(int(av), rel, netw)
if err != nil { if err != nil {
return cid.Undef, xerrors.Errorf("error fetching bundle for builtin-actors version %d: %w", av, err) return cid.Undef, xerrors.Errorf("error fetching bundle for builtin-actors version %d: %w", av, err)
} }

View File

@ -1,4 +1,4 @@
package actors package bundle
import ( import (
"bytes" "bytes"
@ -16,7 +16,7 @@ import (
logging "github.com/ipfs/go-log/v2" logging "github.com/ipfs/go-log/v2"
) )
var logb = logging.Logger("bundle-fetcher") var log = logging.Logger("bundle-fetcher")
type BundleFetcher struct { type BundleFetcher struct {
path string path string
@ -31,7 +31,7 @@ func NewBundleFetcher(basepath string) (*BundleFetcher, error) {
return &BundleFetcher{path: path}, nil return &BundleFetcher{path: path}, nil
} }
func (b *BundleFetcher) Fetch(version Version, release, netw string) (path string, err error) { func (b *BundleFetcher) Fetch(version int, release, netw string) (path string, err error) {
bundleName := fmt.Sprintf("builtin-actors-%s", netw) bundleName := fmt.Sprintf("builtin-actors-%s", netw)
bundleFile := fmt.Sprintf("%s.car", bundleName) bundleFile := fmt.Sprintf("%s.car", bundleName)
bundleHash := fmt.Sprintf("%s.sha256", bundleName) bundleHash := fmt.Sprintf("%s.sha256", bundleName)
@ -49,17 +49,17 @@ func (b *BundleFetcher) Fetch(version Version, release, netw string) (path strin
return bundleFilePath, nil return bundleFilePath, nil
} }
logb.Warnf("invalid bundle %s: %s; refetching", bundleName, err) log.Warnf("invalid bundle %s: %s; refetching", bundleName, err)
} }
logb.Infof("fetching bundle %s", bundleFile) log.Infof("fetching bundle %s", bundleFile)
if err := b.fetch(release, bundleBasePath, bundleFile, bundleHash); err != nil { if err := b.fetch(release, bundleBasePath, bundleFile, bundleHash); err != nil {
logb.Errorf("error fetching bundle %s: %s", bundleName, err) log.Errorf("error fetching bundle %s: %s", bundleName, err)
return "", xerrors.Errorf("error fetching bundle: %w", err) return "", xerrors.Errorf("error fetching bundle: %w", err)
} }
if err := b.check(bundleBasePath, bundleFile, bundleHash); err != nil { if err := b.check(bundleBasePath, bundleFile, bundleHash); err != nil {
logb.Errorf("error checking bundle %s: %s", bundleName, err) log.Errorf("error checking bundle %s: %s", bundleName, err)
return "", xerrors.Errorf("error checking bundle: %s", err) return "", xerrors.Errorf("error checking bundle: %s", err)
} }
@ -67,7 +67,7 @@ func (b *BundleFetcher) Fetch(version Version, release, netw string) (path strin
} }
func (b *BundleFetcher) fetchURL(url, path string) error { func (b *BundleFetcher) fetchURL(url, path string) error {
logb.Infof("fetching URL: %s", url) log.Infof("fetching URL: %s", url)
resp, err := http.Get(url) //nolint resp, err := http.Get(url) //nolint
if err != nil { if err != nil {