make the miner load the manifest so that it can correctly map actors

This commit is contained in:
vyzo 2022-04-12 20:38:25 +03:00
parent 07e4024e3b
commit 395c772222
5 changed files with 49 additions and 9 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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) {