diff --git a/chain/actors/manifest.go b/chain/actors/manifest.go index ac3733737..3c600ecf2 100644 --- a/chain/actors/manifest.go +++ b/chain/actors/manifest.go @@ -12,8 +12,8 @@ import ( "github.com/filecoin-project/specs-actors/v8/actors/builtin/manifest" ) -var manifestCids map[Version]cid.Cid = map[Version]cid.Cid{ - // TODO manifest CIDs for v8 and upwards +var ManifestCids map[Version]cid.Cid = map[Version]cid.Cid{ + // TODO fill in manifest CIDs for v8 and upwards once these are fixed } var manifests map[Version]*manifest.Manifest @@ -30,7 +30,7 @@ func LoadManifests(ctx context.Context, store cbor.IpldStore) error { manifests = make(map[Version]*manifest.Manifest) actorMeta = make(map[cid.Cid]actorEntry) - for av, mfCid := range manifestCids { + for av, mfCid := range ManifestCids { mf := &manifest.Manifest{} if err := adtStore.Get(ctx, mfCid, mf); err != nil { return xerrors.Errorf("error reading manifest for network version %d (cid: %s): %w", av, mfCid, err) diff --git a/chain/consensus/filcns/upgrades.go b/chain/consensus/filcns/upgrades.go index ba1d7736b..cced0c0f9 100644 --- a/chain/consensus/filcns/upgrades.go +++ b/chain/consensus/filcns/upgrades.go @@ -36,6 +36,7 @@ import ( "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/state" @@ -88,6 +89,11 @@ func legacyPreMigration(f LegacyPreMigrationFunc) stmgr.PreMigrationFunc { func DefaultUpgradeSchedule() stmgr.UpgradeSchedule { var us stmgr.UpgradeSchedule + v8ManifestCid, ok := actors.ManifestCids[actors.Version8] + if !ok { + v8ManifestCid = cid.Undef + } + updates := []stmgr.Upgrade{{ Height: build.UpgradeBreezeHeight, Network: network.Version1, @@ -239,7 +245,7 @@ func DefaultUpgradeSchedule() stmgr.UpgradeSchedule { DontStartWithin: 60, StopWithin: 5, }}, - Manifest: cid.Undef, // TODO this should be the real manifest CID + Manifest: v8ManifestCid, Expensive: true, }, } diff --git a/node/builder.go b/node/builder.go index f0106ad97..759d04bbb 100644 --- a/node/builder.go +++ b/node/builder.go @@ -71,6 +71,7 @@ var ( ConnGaterKey = special{12} // libp2p option DAGStoreKey = special{13} // constructor returns multiple values ResourceManagerKey = special{14} // Libp2p option + BuiltinActorsKey = special{15} // builtin actors bundle loading ) type invoke int diff --git a/node/builder_chain.go b/node/builder_chain.go index 226ecac68..5581e5096 100644 --- a/node/builder_chain.go +++ b/node/builder_chain.go @@ -48,6 +48,13 @@ var ChainNode = Options( // Full node or lite node // TODO: Fix offline mode + // FVM: builtin actor bundle loading + // Note: this has to load before the upgrade schedule, so that we can patch in the + // right manifest cid. + // This restriction will be lifted once we have the final actors v8 bundle and we know + // the manifest cid. + Override(BuiltinActorsKey, modules.LoadBultinActors), + // Consensus settings Override(new(dtypes.DrandSchedule), modules.BuiltinDrandConfig), Override(new(stmgr.UpgradeSchedule), filcns.DefaultUpgradeSchedule()), diff --git a/node/modules/builtin_actors.go b/node/modules/builtin_actors.go new file mode 100644 index 000000000..88cb567d5 --- /dev/null +++ b/node/modules/builtin_actors.go @@ -0,0 +1,40 @@ +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" +) + +func LoadBultinActors(lc fx.Lifecycle, mctx helpers.MetricsCtx, bs dtypes.UniversalBlockstore) 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. + blobr := bytes.NewReader(build.BuiltinActorsV8Bundle()) + hdr, err := car.LoadCar(ctx, bs, blobr) + if err != nil { + return xerrors.Errorf("error loading builtin actors v8 bundle: %w", err) + } + + manifestCid := hdr.Roots[0] + actors.ManifestCids[actors.Version8] = manifestCid + + cborStore := cbor.NewCborStore(bs) + if err := actors.LoadManifests(ctx, cborStore); err != nil { + return xerrors.Errorf("error loading actor manifests: %w", err) + } + + return nil +}