dynamic loading of builtin actor bundles
This commit is contained in:
@@ -2,8 +2,8 @@ package modules
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"go.uber.org/fx"
|
||||
"golang.org/x/xerrors"
|
||||
@@ -12,28 +12,60 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||
"github.com/filecoin-project/lotus/node/repo"
|
||||
|
||||
cid "github.com/ipfs/go-cid"
|
||||
dstore "github.com/ipfs/go-datastore"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
)
|
||||
|
||||
func LoadBultinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtypes.UniversalBlockstore) (result dtypes.BuiltinActorsLoaded, err error) {
|
||||
func LoadBultinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.LockedRepo, bs dtypes.UniversalBlockstore, ds dtypes.MetadataDS) (result dtypes.BuiltinActorsLoaded, err error) {
|
||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||
|
||||
// TODO eventually we want this to start with bundle/manifest CIDs and fetch them from IPFS if
|
||||
// not already loaded.
|
||||
// For now, we just embed the v8 bundle and adjust the manifest CIDs for the migration/actor
|
||||
// metadata.
|
||||
if len(build.BuiltinActorsV8Bundle()) > 0 {
|
||||
if err := actors.LoadBundle(ctx, bs, actors.Version8, build.BuiltinActorsV8Bundle()); err != nil {
|
||||
return result, err
|
||||
}
|
||||
// TODO how to properly get the network name?
|
||||
// putting it as a dep in inputs causes a stack overflow in DI from circular dependency
|
||||
// sigh...
|
||||
netw := "mainnet"
|
||||
if v := os.Getenv("LOTUS_FIL_NETWORK"); v != "" {
|
||||
netw = v
|
||||
}
|
||||
|
||||
// for testing -- need to also set LOTUS_USE_FVM_CUSTOM_BUNDLE=1 to force the fvm to use it.
|
||||
if len(build.BuiltinActorsV7Bundle()) > 0 {
|
||||
if err := actors.LoadBundle(ctx, bs, actors.Version7, build.BuiltinActorsV7Bundle()); err != nil {
|
||||
for av, rel := range build.BuiltinActorReleases {
|
||||
key := dstore.NewKey(fmt.Sprintf("/builtin-actors/v%d/%s", av, rel))
|
||||
|
||||
data, err := ds.Get(ctx, key)
|
||||
switch err {
|
||||
case nil:
|
||||
mfCid, err := cid.Cast(data)
|
||||
if err != nil {
|
||||
return result, xerrors.Errorf("error parsing cid for %s: %w", key, err)
|
||||
}
|
||||
|
||||
has, err := bs.Has(ctx, mfCid)
|
||||
if err != nil {
|
||||
return result, xerrors.Errorf("error checking blockstore for manifest cid %s: %w", mfCid, err)
|
||||
}
|
||||
|
||||
if has {
|
||||
actors.AddManifest(av, mfCid)
|
||||
continue
|
||||
}
|
||||
|
||||
case dstore.ErrNotFound:
|
||||
|
||||
default:
|
||||
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 := actors.FetchAndLoadBundle(ctx, r.Path(), bs, av, rel, string(netw))
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
if err := ds.Put(ctx, key, mfCid.Bytes()); err != nil {
|
||||
return result, xerrors.Errorf("error storing manifest CID for builtin-actors vrsion %d to the datastore: %w", av, err)
|
||||
}
|
||||
}
|
||||
|
||||
cborStore := cbor.NewCborStore(bs)
|
||||
@@ -45,38 +77,26 @@ func LoadBultinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtypes.Univer
|
||||
}
|
||||
|
||||
// for itests
|
||||
var testingBundleMx sync.Mutex
|
||||
|
||||
func LoadBuiltinActorsTesting(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtypes.UniversalBlockstore) (result dtypes.BuiltinActorsLoaded, err error) {
|
||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||
|
||||
base := os.Getenv("LOTUS_SRC_DIR")
|
||||
if base == "" {
|
||||
base = "."
|
||||
}
|
||||
|
||||
var template string
|
||||
var netw string
|
||||
if build.InsecurePoStValidation {
|
||||
template = "%s/build/builtin-actors/v%d/builtin-actors-testing-fake-proofs.car"
|
||||
netw = "testing-fake-proofs"
|
||||
} else {
|
||||
template = "%s/build/builtin-actors/v%d/builtin-actors-testing.car"
|
||||
netw = "testing"
|
||||
}
|
||||
|
||||
for _, ver := range []actors.Version{actors.Version8} {
|
||||
path := fmt.Sprintf(template, base, ver)
|
||||
testingBundleMx.Lock()
|
||||
defer testingBundleMx.Unlock()
|
||||
|
||||
log.Infof("loading testing bundle: %s", path)
|
||||
for av, rel := range build.BuiltinActorReleases {
|
||||
const basePath = "/tmp/lotus-testing"
|
||||
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return result, xerrors.Errorf("error opening v%d bundle: %w", ver, err)
|
||||
}
|
||||
|
||||
bundle, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return result, xerrors.Errorf("error reading v%d bundle: %w", ver, err)
|
||||
}
|
||||
|
||||
if err := actors.LoadBundle(ctx, bs, actors.Version8, bundle); err != nil {
|
||||
return result, xerrors.Errorf("error loading v%d bundle: %w", ver, err)
|
||||
if _, err := actors.FetchAndLoadBundle(ctx, basePath, bs, av, rel, netw); err != nil {
|
||||
return result, xerrors.Errorf("error loading bundle for builtin-actors vresion %d: %w", av, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user