From 46a85fc11e9d5e4ad0f64c06eb7123aaa972b334 Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 16 May 2022 21:09:09 +0300 Subject: [PATCH] niceties for development bundle loading --- build/builtin_actors.go | 6 ++--- build/bundle.go | 7 ++++++ node/bundle/manifest.go | 18 ++++++++++---- node/modules/builtin_actors.go | 44 ++++++++++++++++++++++++---------- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/build/builtin_actors.go b/build/builtin_actors.go index e65ebabf9..c6ed38c5b 100644 --- a/build/builtin_actors.go +++ b/build/builtin_actors.go @@ -8,10 +8,10 @@ import ( "github.com/BurntSushi/toml" ) -var BuiltinActorReleases map[actors.Version]string +var BuiltinActorReleases map[actors.Version]Bundle func init() { - BuiltinActorReleases = make(map[actors.Version]string) + BuiltinActorReleases = make(map[actors.Version]Bundle) spec := BundleSpec{} @@ -22,6 +22,6 @@ func init() { } for _, b := range spec.Bundles { - BuiltinActorReleases[b.Version] = b.Release + BuiltinActorReleases[b.Version] = b } } diff --git a/build/bundle.go b/build/bundle.go index 1a6fbcd93..3afe41daa 100644 --- a/build/bundle.go +++ b/build/bundle.go @@ -16,6 +16,13 @@ type BundleSpec struct { } type Bundle struct { + // actors version in this bundle Version actors.Version + // release id 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 } diff --git a/node/bundle/manifest.go b/node/bundle/manifest.go index 45c632bdb..4bd55075e 100644 --- a/node/bundle/manifest.go +++ b/node/bundle/manifest.go @@ -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 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) if err != nil { 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 -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 if netw == "" { netw = "mainnet" @@ -67,9 +71,15 @@ func FetchAndLoadBundles(ctx context.Context, bs blockstore.Blockstore, bar map[ } } - for av, rel := range bar { - if _, err := FetchAndLoadBundle(ctx, path, bs, av, rel, netw); err != nil { - return err + for av, bd := range bar { + if bd.Path != "" { + if _, err := LoadBundle(ctx, bs, bd.Path, av); err != nil { + return err + } + } else { + if _, err := FetchAndLoadBundle(ctx, path, bs, av, bd.Release, netw); err != nil { + return err + } } } diff --git a/node/modules/builtin_actors.go b/node/modules/builtin_actors.go index 991372526..5f496b00f 100644 --- a/node/modules/builtin_actors.go +++ b/node/modules/builtin_actors.go @@ -2,7 +2,7 @@ package modules import ( "fmt" - "strings" + "path/filepath" "sync" "go.uber.org/fx" @@ -30,9 +30,9 @@ func LoadBuiltinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRe netw = "mainnet" } - for av, rel := range build.BuiltinActorReleases { + for av, bd := range build.BuiltinActorReleases { // 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) 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) } - // ok, we don't have it -- fetch it and add it to the blockstore - mfCid, err := bundle.FetchAndLoadBundle(ctx, r.Path(), bs, av, rel, netw) - if err != nil { - return result, err + // we haven't recorded it in the daatastore, so we need to load it + 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 { + 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 continue } @@ -108,11 +118,19 @@ func LoadBuiltinActorsTesting(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtype testingBundleMx.Lock() defer testingBundleMx.Unlock() - for av, rel := range build.BuiltinActorReleases { - const basePath = "/tmp/lotus-testing" - - if _, err := bundle.FetchAndLoadBundle(ctx, basePath, bs, av, rel, netw); err != nil { - return result, xerrors.Errorf("error loading bundle for builtin-actors vresion %d: %w", av, err) + 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" + if _, err := bundle.FetchAndLoadBundle(ctx, basePath, bs, av, bd.Release, netw); err != nil { + return result, xerrors.Errorf("error loading testing bundle for builtin-actors version %d/%s: %w", av, netw, err) + } } }