2022-04-04 14:48:13 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"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"
|
|
|
|
car "github.com/ipld/go-car"
|
|
|
|
)
|
|
|
|
|
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.
|
|
|
|
blobr := bytes.NewReader(build.BuiltinActorsV8Bundle())
|
|
|
|
hdr, err := car.LoadCar(ctx, bs, blobr)
|
|
|
|
if err != nil {
|
2022-04-04 17:06:49 +00:00
|
|
|
return result, xerrors.Errorf("error loading builtin actors v8 bundle: %w", err)
|
2022-04-04 14:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
manifestCid := hdr.Roots[0]
|
|
|
|
actors.ManifestCids[actors.Version8] = manifestCid
|
|
|
|
|
|
|
|
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
|
|
|
}
|