niceties for development bundle loading
This commit is contained in:
parent
b4be759b2c
commit
46a85fc11e
@ -8,10 +8,10 @@ import (
|
|||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
)
|
)
|
||||||
|
|
||||||
var BuiltinActorReleases map[actors.Version]string
|
var BuiltinActorReleases map[actors.Version]Bundle
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
BuiltinActorReleases = make(map[actors.Version]string)
|
BuiltinActorReleases = make(map[actors.Version]Bundle)
|
||||||
|
|
||||||
spec := BundleSpec{}
|
spec := BundleSpec{}
|
||||||
|
|
||||||
@ -22,6 +22,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, b := range spec.Bundles {
|
for _, b := range spec.Bundles {
|
||||||
BuiltinActorReleases[b.Version] = b.Release
|
BuiltinActorReleases[b.Version] = b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,13 @@ type BundleSpec struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Bundle struct {
|
type Bundle struct {
|
||||||
|
// actors version in this bundle
|
||||||
Version actors.Version
|
Version actors.Version
|
||||||
|
// release id
|
||||||
Release string
|
Release string
|
||||||
|
// bundle path: optional, uses the appropriate release bundle if unset
|
||||||
|
Path string
|
||||||
|
// development version; when set, in conjunction with path, it will always
|
||||||
|
// load the bundle to the blockstore
|
||||||
|
Development bool
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,10 @@ func FetchAndLoadBundle(ctx context.Context, basePath string, bs blockstore.Bloc
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return LoadBundle(ctx, bs, path, av)
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadBundle(ctx context.Context, bs blockstore.Blockstore, path string, av actors.Version) (cid.Cid, error) {
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, xerrors.Errorf("error opening bundle for builtin-actors vresion %d: %w", av, err)
|
return cid.Undef, xerrors.Errorf("error opening bundle for builtin-actors vresion %d: %w", av, err)
|
||||||
@ -52,7 +56,7 @@ func FetchAndLoadBundle(ctx context.Context, basePath string, bs blockstore.Bloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// utility for blanket loading outside DI
|
// utility for blanket loading outside DI
|
||||||
func FetchAndLoadBundles(ctx context.Context, bs blockstore.Blockstore, bar map[actors.Version]string) error {
|
func FetchAndLoadBundles(ctx context.Context, bs blockstore.Blockstore, bar map[actors.Version]build.Bundle) error {
|
||||||
netw := build.NetworkBundle
|
netw := build.NetworkBundle
|
||||||
if netw == "" {
|
if netw == "" {
|
||||||
netw = "mainnet"
|
netw = "mainnet"
|
||||||
@ -67,10 +71,16 @@ func FetchAndLoadBundles(ctx context.Context, bs blockstore.Blockstore, bar map[
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for av, rel := range bar {
|
for av, bd := range bar {
|
||||||
if _, err := FetchAndLoadBundle(ctx, path, bs, av, rel, netw); err != nil {
|
if bd.Path != "" {
|
||||||
|
if _, err := LoadBundle(ctx, bs, bd.Path, av); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if _, err := FetchAndLoadBundle(ctx, path, bs, av, bd.Release, netw); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cborStore := cbor.NewCborStore(bs)
|
cborStore := cbor.NewCborStore(bs)
|
||||||
|
@ -2,7 +2,7 @@ package modules
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
@ -30,9 +30,9 @@ func LoadBuiltinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRe
|
|||||||
netw = "mainnet"
|
netw = "mainnet"
|
||||||
}
|
}
|
||||||
|
|
||||||
for av, rel := range build.BuiltinActorReleases {
|
for av, bd := range build.BuiltinActorReleases {
|
||||||
// first check to see if we know this release
|
// first check to see if we know this release
|
||||||
key := dstore.NewKey(fmt.Sprintf("/builtin-actors/v%d/%s", av, rel))
|
key := dstore.NewKey(fmt.Sprintf("/builtin-actors/v%d/%s", av, bd.Release))
|
||||||
|
|
||||||
data, err := ds.Get(ctx, key)
|
data, err := ds.Get(ctx, key)
|
||||||
switch err {
|
switch err {
|
||||||
@ -66,13 +66,23 @@ func LoadBuiltinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRe
|
|||||||
return result, xerrors.Errorf("error loading %s from datastore: %w", key, err)
|
return result, xerrors.Errorf("error loading %s from datastore: %w", key, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ok, we don't have it -- fetch it and add it to the blockstore
|
// we haven't recorded it in the daatastore, so we need to load it
|
||||||
mfCid, err := bundle.FetchAndLoadBundle(ctx, r.Path(), bs, av, rel, netw)
|
var mfCid cid.Cid
|
||||||
|
if bd.Path != "" {
|
||||||
|
// this is a local bundle, load it directly from the filessystem
|
||||||
|
mfCid, err = bundle.LoadBundle(ctx, bs, bd.Path, av)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// fetch it and add it to the blockstore
|
||||||
|
mfCid, err = bundle.FetchAndLoadBundle(ctx, r.Path(), bs, av, bd.Release, netw)
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if rel == "dev" || strings.HasPrefix(rel, "dev.") {
|
if bd.Development {
|
||||||
// don't store the release key so that we always load development bundles
|
// don't store the release key so that we always load development bundles
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -108,11 +118,19 @@ func LoadBuiltinActorsTesting(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtype
|
|||||||
testingBundleMx.Lock()
|
testingBundleMx.Lock()
|
||||||
defer testingBundleMx.Unlock()
|
defer testingBundleMx.Unlock()
|
||||||
|
|
||||||
for av, rel := range build.BuiltinActorReleases {
|
for av, bd := range build.BuiltinActorReleases {
|
||||||
|
if bd.Path != "" {
|
||||||
|
// we need the appopriate bundle for tests; it should live next to the main bundle, with the
|
||||||
|
// appropriate network name
|
||||||
|
path := filepath.Join(filepath.Dir(bd.Path), fmt.Sprintf("builtin-actors-%s.car", netw))
|
||||||
|
if _, err := bundle.LoadBundle(ctx, bs, path, av); err != nil {
|
||||||
|
return result, xerrors.Errorf("error loading testing bundle for builtin-actors version %d/%s: %w", av, netw, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
const basePath = "/tmp/lotus-testing"
|
const basePath = "/tmp/lotus-testing"
|
||||||
|
if _, err := bundle.FetchAndLoadBundle(ctx, basePath, bs, av, bd.Release, netw); err != nil {
|
||||||
if _, err := bundle.FetchAndLoadBundle(ctx, basePath, bs, av, rel, netw); err != nil {
|
return result, xerrors.Errorf("error loading testing bundle for builtin-actors version %d/%s: %w", av, netw, err)
|
||||||
return result, xerrors.Errorf("error loading bundle for builtin-actors vresion %d: %w", av, err)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user