make manifest cid access thread-safe
This commit is contained in:
parent
ddede202a8
commit
a8547ed840
@ -13,7 +13,7 @@ import (
|
||||
"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
|
||||
}
|
||||
|
||||
@ -30,6 +30,21 @@ type actorEntry struct {
|
||||
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 {
|
||||
// tests may invoke this concurrently, so we wrap it in a sync.Once
|
||||
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)
|
||||
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)
|
||||
|
@ -89,7 +89,7 @@ func legacyPreMigration(f LegacyPreMigrationFunc) stmgr.PreMigrationFunc {
|
||||
func DefaultUpgradeSchedule() stmgr.UpgradeSchedule {
|
||||
var us stmgr.UpgradeSchedule
|
||||
|
||||
v8ManifestCid, ok := actors.ManifestCids[actors.Version8]
|
||||
v8ManifestCid, ok := actors.GetManifest(actors.Version8)
|
||||
if !ok {
|
||||
v8ManifestCid = cid.Undef
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
c, ok := actors.ManifestCids[av]
|
||||
c, ok := actors.GetManifest(av)
|
||||
if !ok {
|
||||
return nil, xerrors.Errorf("no manifest for custom bundle (actors version %d)", av)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user