From 08a5950863edab34b2769813d05251d407a19a0a Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 4 Apr 2022 14:14:27 +0300 Subject: [PATCH] actor manifests and metadata --- chain/actors/manifest.go | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 chain/actors/manifest.go diff --git a/chain/actors/manifest.go b/chain/actors/manifest.go new file mode 100644 index 000000000..ac3733737 --- /dev/null +++ b/chain/actors/manifest.go @@ -0,0 +1,72 @@ +package actors + +import ( + "context" + + "golang.org/x/xerrors" + + cid "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "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 manifests map[Version]*manifest.Manifest +var actorMeta map[cid.Cid]actorEntry + +type actorEntry struct { + name string + version Version +} + +func LoadManifests(ctx context.Context, store cbor.IpldStore) error { + adtStore := adt.WrapStore(ctx, store) + + manifests = make(map[Version]*manifest.Manifest) + actorMeta = make(map[cid.Cid]actorEntry) + + 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) + } + + if err := mf.Load(ctx, adtStore); err != nil { + return xerrors.Errorf("error loading manifest for network version %d: %w", av, err) + } + + manifests[av] = mf + + for _, name := range []string{"system", "init", "cron", "account", "storagepower", "storageminer", "storagemarket", "paymentchannel", "multisig", "reward", "verifiedregistry"} { + c, ok := mf.Get(name) + if ok { + actorMeta[c] = actorEntry{name: name, version: av} + } + } + } + + return nil +} + +func GetActorCodeID(av Version, name string) (cid.Cid, bool) { + mf, ok := manifests[av] + if ok { + return mf.Get(name) + } + + return cid.Undef, false +} + +func GetActorMetaByCode(c cid.Cid) (string, Version, bool) { + entry, ok := actorMeta[c] + if !ok { + return "", -1, false + } + + return entry.name, entry.version, true +}