load actor bundle at startup and initialize the manifest CID from the loaded file

This commit is contained in:
vyzo 2022-04-04 17:48:13 +03:00
parent c3fb3301ab
commit f26d19ed7d
5 changed files with 58 additions and 4 deletions

View File

@ -12,8 +12,8 @@ import (
"github.com/filecoin-project/specs-actors/v8/actors/builtin/manifest" "github.com/filecoin-project/specs-actors/v8/actors/builtin/manifest"
) )
var manifestCids map[Version]cid.Cid = map[Version]cid.Cid{ var ManifestCids map[Version]cid.Cid = map[Version]cid.Cid{
// TODO manifest CIDs for v8 and upwards // TODO fill in manifest CIDs for v8 and upwards once these are fixed
} }
var manifests map[Version]*manifest.Manifest 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) manifests = make(map[Version]*manifest.Manifest)
actorMeta = make(map[cid.Cid]actorEntry) actorMeta = make(map[cid.Cid]actorEntry)
for av, mfCid := range manifestCids { for av, mfCid := range ManifestCids {
mf := &manifest.Manifest{} mf := &manifest.Manifest{}
if err := adtStore.Get(ctx, mfCid, mf); err != nil { 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) return xerrors.Errorf("error reading manifest for network version %d (cid: %s): %w", av, mfCid, err)

View File

@ -36,6 +36,7 @@ import (
"github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/blockstore"
"github.com/filecoin-project/lotus/build" "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"
"github.com/filecoin-project/lotus/chain/actors/builtin/multisig" "github.com/filecoin-project/lotus/chain/actors/builtin/multisig"
"github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/state"
@ -88,6 +89,11 @@ func legacyPreMigration(f LegacyPreMigrationFunc) stmgr.PreMigrationFunc {
func DefaultUpgradeSchedule() stmgr.UpgradeSchedule { func DefaultUpgradeSchedule() stmgr.UpgradeSchedule {
var us stmgr.UpgradeSchedule var us stmgr.UpgradeSchedule
v8ManifestCid, ok := actors.ManifestCids[actors.Version8]
if !ok {
v8ManifestCid = cid.Undef
}
updates := []stmgr.Upgrade{{ updates := []stmgr.Upgrade{{
Height: build.UpgradeBreezeHeight, Height: build.UpgradeBreezeHeight,
Network: network.Version1, Network: network.Version1,
@ -239,7 +245,7 @@ func DefaultUpgradeSchedule() stmgr.UpgradeSchedule {
DontStartWithin: 60, DontStartWithin: 60,
StopWithin: 5, StopWithin: 5,
}}, }},
Manifest: cid.Undef, // TODO this should be the real manifest CID Manifest: v8ManifestCid,
Expensive: true, Expensive: true,
}, },
} }

View File

@ -71,6 +71,7 @@ var (
ConnGaterKey = special{12} // libp2p option ConnGaterKey = special{12} // libp2p option
DAGStoreKey = special{13} // constructor returns multiple values DAGStoreKey = special{13} // constructor returns multiple values
ResourceManagerKey = special{14} // Libp2p option ResourceManagerKey = special{14} // Libp2p option
BuiltinActorsKey = special{15} // builtin actors bundle loading
) )
type invoke int type invoke int

View File

@ -48,6 +48,13 @@ var ChainNode = Options(
// Full node or lite node // Full node or lite node
// TODO: Fix offline mode // 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 // Consensus settings
Override(new(dtypes.DrandSchedule), modules.BuiltinDrandConfig), Override(new(dtypes.DrandSchedule), modules.BuiltinDrandConfig),
Override(new(stmgr.UpgradeSchedule), filcns.DefaultUpgradeSchedule()), Override(new(stmgr.UpgradeSchedule), filcns.DefaultUpgradeSchedule()),

View File

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