From 395c7722225626d975e1ad64ca6a971164452c06 Mon Sep 17 00:00:00 2001 From: vyzo Date: Tue, 12 Apr 2022 20:38:25 +0300 Subject: [PATCH] make the miner load the manifest so that it can correctly map actors --- chain/actors/manifest.go | 17 +++++++++++++++++ cmd/lotus-miner/init.go | 17 +++++++++++++++++ node/builder_miner.go | 3 +++ node/modules/builtin_actors.go | 19 ++++++++++--------- node/modules/storageminer.go | 2 ++ 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/chain/actors/manifest.go b/chain/actors/manifest.go index 322052494..4fc37c0f5 100644 --- a/chain/actors/manifest.go +++ b/chain/actors/manifest.go @@ -1,6 +1,7 @@ package actors import ( + "bytes" "context" "strings" "sync" @@ -9,7 +10,9 @@ import ( cid "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" + car "github.com/ipld/go-car" + "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/specs-actors/v8/actors/builtin/manifest" ) @@ -107,3 +110,17 @@ func CanonicalName(name string) string { return name } + +func LoadBundle(ctx context.Context, bs blockstore.Blockstore, av Version, data []byte) error { + blobr := bytes.NewReader(data) + + hdr, err := car.LoadCar(ctx, bs, blobr) + if err != nil { + return xerrors.Errorf("error loading builtin actors v%d bundle: %w", av, err) + } + + manifestCid := hdr.Roots[0] + AddManifest(av, manifestCid) + + return nil +} diff --git a/cmd/lotus-miner/init.go b/cmd/lotus-miner/init.go index 8512f4a22..a23795d28 100644 --- a/cmd/lotus-miner/init.go +++ b/cmd/lotus-miner/init.go @@ -21,6 +21,7 @@ import ( "github.com/google/uuid" "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/namespace" + cbor "github.com/ipfs/go-ipld-cbor" "github.com/libp2p/go-libp2p-core/crypto" "github.com/libp2p/go-libp2p-core/peer" "github.com/mitchellh/go-homedir" @@ -215,6 +216,22 @@ var initCmd = &cli.Command{ return err } + if len(build.BuiltinActorsV8Bundle()) > 0 { + bs, err := lr.Blockstore(context.TODO(), repo.UniversalBlockstore) + if err != nil { + return xerrors.Errorf("error opening blockstore: %w", err) + } + + if err := actors.LoadBundle(context.TODO(), bs, actors.Version8, build.BuiltinActorsV8Bundle()); err != nil { + return xerrors.Errorf("error loading actor bundle: %w", err) + } + + cborStore := cbor.NewCborStore(bs) + if err := actors.LoadManifests(ctx, cborStore); err != nil { + return xerrors.Errorf("error loading actor manifests: %w", err) + } + } + var localPaths []stores.LocalPath if pssb := cctx.StringSlice("pre-sealed-sectors"); len(pssb) != 0 { diff --git a/node/builder_miner.go b/node/builder_miner.go index 2223d14ce..0509fcd05 100644 --- a/node/builder_miner.go +++ b/node/builder_miner.go @@ -51,6 +51,9 @@ var MinerNode = Options( // Mining / proving Override(new(*storage.AddressSelector), modules.AddressSelector(nil)), + + // builtin actors manifest + Override(new(dtypes.BuiltinActorsLoaded), modules.LoadBultinActors), ) func ConfigStorageMiner(c interface{}) Option { diff --git a/node/modules/builtin_actors.go b/node/modules/builtin_actors.go index c65ae1a0a..a669123f2 100644 --- a/node/modules/builtin_actors.go +++ b/node/modules/builtin_actors.go @@ -1,8 +1,6 @@ package modules import ( - "bytes" - "go.uber.org/fx" "golang.org/x/xerrors" @@ -12,7 +10,6 @@ import ( "github.com/filecoin-project/lotus/node/modules/helpers" cbor "github.com/ipfs/go-ipld-cbor" - car "github.com/ipld/go-car" ) func LoadBultinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtypes.UniversalBlockstore) (result dtypes.BuiltinActorsLoaded, err error) { @@ -22,14 +19,18 @@ func LoadBultinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtypes.Univer // 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 { - return result, xerrors.Errorf("error loading builtin actors v8 bundle: %w", err) + if len(build.BuiltinActorsV8Bundle()) > 0 { + if err := actors.LoadBundle(ctx, bs, actors.Version8, build.BuiltinActorsV8Bundle()); err != nil { + return result, err + } } - manifestCid := hdr.Roots[0] - actors.ManifestCids[actors.Version8] = manifestCid + // 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 + } + } cborStore := cbor.NewCborStore(bs) if err := actors.LoadManifests(ctx, cborStore); err != nil { diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 09b8b6f31..ae3628764 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -219,6 +219,8 @@ type StorageMinerParams struct { Journal journal.Journal AddrSel *storage.AddressSelector Maddr dtypes.MinerAddress + + ManifestLoaded dtypes.BuiltinActorsLoaded } func StorageMiner(fc config.MinerFeeConfig) func(params StorageMinerParams) (*storage.Miner, error) {