2022-04-04 14:48:13 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
2022-04-19 14:33:08 +00:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
2022-04-04 14:48:13 +00:00
|
|
|
"go.uber.org/fx"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/helpers"
|
|
|
|
|
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
|
|
)
|
|
|
|
|
2022-04-04 17:06:49 +00:00
|
|
|
func LoadBultinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtypes.UniversalBlockstore) (result dtypes.BuiltinActorsLoaded, err error) {
|
2022-04-04 14:48:13 +00:00
|
|
|
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.
|
2022-04-12 17:38:25 +00:00
|
|
|
if len(build.BuiltinActorsV8Bundle()) > 0 {
|
|
|
|
if err := actors.LoadBundle(ctx, bs, actors.Version8, build.BuiltinActorsV8Bundle()); err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
2022-04-04 14:48:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 17:38:25 +00:00
|
|
|
// 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 {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
}
|
2022-04-04 14:48:13 +00:00
|
|
|
|
|
|
|
cborStore := cbor.NewCborStore(bs)
|
|
|
|
if err := actors.LoadManifests(ctx, cborStore); err != nil {
|
2022-04-04 17:06:49 +00:00
|
|
|
return result, xerrors.Errorf("error loading actor manifests: %w", err)
|
2022-04-04 14:48:13 +00:00
|
|
|
}
|
|
|
|
|
2022-04-04 17:06:49 +00:00
|
|
|
return result, nil
|
2022-04-04 14:48:13 +00:00
|
|
|
}
|
2022-04-19 14:33:08 +00:00
|
|
|
|
|
|
|
// for itests
|
|
|
|
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 = "."
|
|
|
|
}
|
|
|
|
|
2022-04-22 08:34:18 +00:00
|
|
|
var template string
|
|
|
|
if build.InsecurePoStValidation {
|
|
|
|
template = "%s/build/builtin-actors/v%d/builtin-actors-testing-fake-proofs.car"
|
|
|
|
} else {
|
|
|
|
template = "%s/build/builtin-actors/v%d/builtin-actors-testing.car"
|
|
|
|
}
|
|
|
|
|
2022-04-19 14:33:08 +00:00
|
|
|
for _, ver := range []actors.Version{actors.Version8} {
|
2022-04-22 08:34:18 +00:00
|
|
|
path := fmt.Sprintf(template, base, ver)
|
|
|
|
|
|
|
|
log.Infof("loading testing bundle: %s", path)
|
2022-04-19 14:33:08 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cborStore := cbor.NewCborStore(bs)
|
|
|
|
if err := actors.LoadManifests(ctx, cborStore); err != nil {
|
|
|
|
return result, xerrors.Errorf("error loading actor manifests: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|