make manifest cid access thread-safe

This commit is contained in:
vyzo 2022-04-06 11:25:46 +03:00
parent ddede202a8
commit a8547ed840
3 changed files with 19 additions and 4 deletions

View File

@ -13,7 +13,7 @@ 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 fill in manifest CIDs for v8 and upwards once these are fixed // TODO fill in manifest CIDs for v8 and upwards once these are fixed
} }
@ -30,6 +30,21 @@ type actorEntry struct {
version Version version Version
} }
func AddManifest(av Version, manifestCid cid.Cid) {
manifestMx.Lock()
defer manifestMx.Unlock()
manifestCids[av] = manifestCid
}
func GetManifest(av Version) (cid.Cid, bool) {
manifestMx.Lock()
defer manifestMx.Unlock()
c, ok := manifestCids[av]
return c, ok
}
func LoadManifests(ctx context.Context, store cbor.IpldStore) error { func LoadManifests(ctx context.Context, store cbor.IpldStore) error {
// tests may invoke this concurrently, so we wrap it in a sync.Once // tests may invoke this concurrently, so we wrap it in a sync.Once
loadOnce.Do(func() { loadError = loadManifests(ctx, store) }) loadOnce.Do(func() { loadError = loadManifests(ctx, store) })
@ -42,7 +57,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

@ -89,7 +89,7 @@ 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] v8ManifestCid, ok := actors.GetManifest(actors.Version8)
if !ok { if !ok {
v8ManifestCid = cid.Undef v8ManifestCid = cid.Undef
} }

View File

@ -265,7 +265,7 @@ func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) {
return nil, xerrors.Errorf("mapping network version to actors version: %w", err) return nil, xerrors.Errorf("mapping network version to actors version: %w", err)
} }
c, ok := actors.ManifestCids[av] c, ok := actors.GetManifest(av)
if !ok { if !ok {
return nil, xerrors.Errorf("no manifest for custom bundle (actors version %d)", av) return nil, xerrors.Errorf("no manifest for custom bundle (actors version %d)", av)
} }