Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball committed Sep 21, 2022
1 parent 624961e commit a8951fb
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 27 deletions.
12 changes: 6 additions & 6 deletions build/builtin_actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func loadManifests(netw string) error {
var newMetadata []*BuiltinActorsMetadata
// First, prefer overrides.
for av, path := range BundleOverrides {
root, actorCids, err := readBundleManifestFromFile(path)
root, actorCids, err := readBundleManifestFromFile(path, av)
if err != nil {
return err
}
Expand Down Expand Up @@ -178,7 +178,7 @@ func readEmbeddedBuiltinActorsMetadata(bundle string) ([]*BuiltinActorsMetadata,
name = name[len(bundlePrefix) : len(name)-len(bundleExt)]

// Load the bundle.
root, actorCids, err := readBundleManifest(tarReader)
root, actorCids, err := readBundleManifest(tarReader, actorstypes.Version(version))
if err != nil {
return nil, xerrors.Errorf("error loading builtin actors bundle: %w", err)
}
Expand All @@ -191,17 +191,17 @@ func readEmbeddedBuiltinActorsMetadata(bundle string) ([]*BuiltinActorsMetadata,
}
}

func readBundleManifestFromFile(path string) (cid.Cid, map[string]cid.Cid, error) {
func readBundleManifestFromFile(path string, av actorstypes.Version) (cid.Cid, map[string]cid.Cid, error) {
fi, err := os.Open(path)
if err != nil {
return cid.Undef, nil, err
}
defer fi.Close() //nolint

return readBundleManifest(fi)
return readBundleManifest(fi, av)
}

func readBundleManifest(r io.Reader) (cid.Cid, map[string]cid.Cid, error) {
func readBundleManifest(r io.Reader, av actorstypes.Version) (cid.Cid, map[string]cid.Cid, error) {
// Load the bundle.
bs := blockstore.NewMemory()
hdr, err := car.LoadCar(context.Background(), bs, r)
Expand All @@ -213,7 +213,7 @@ func readBundleManifest(r io.Reader) (cid.Cid, map[string]cid.Cid, error) {
return cid.Undef, nil, xerrors.Errorf("expected one root when loading actors bundle, got %d", len(hdr.Roots))
}
root := hdr.Roots[0]
actorCids, err := actors.ReadManifest(context.Background(), adt.WrapStore(context.Background(), cbor.NewCborStore(bs)), root)
actorCids, err := actors.ReadManifest(context.Background(), adt.WrapStore(context.Background(), cbor.NewCborStore(bs)), root, av)
if err != nil {
return cid.Undef, nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions build/builtin_actors_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet
"storagepower": MustParseCid("bafk2bzacebxl4ssugntkckifkq6sydczcas463bmonwi2m5hddurzzcukdzyg"),
"system": MustParseCid("bafk2bzacedtw2ebtl3uccbqfcm6jd7teinlpktcglopuaxa6ev334jhs46hso"),
"verifiedregistry": MustParseCid("bafk2bzaceds62ys6rpbtjjsemohalxnkr3jtqhflifabn3xlhpi45mvi757po"),
"datacap": MustParseCid("todo"),
},
}, {
Network: "calibrationnet",
Expand Down Expand Up @@ -73,6 +74,7 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet
"storagepower": MustParseCid("bafk2bzaceassqqdljvblivbcrkv62a36gxjwf7dmkgez6ezq2oydx3dv2b3z2"),
"system": MustParseCid("bafk2bzacebxsecqifqvqxavnmsuwigmnc5rcuxoezspmykeqinkbgrkfukmgs"),
"verifiedregistry": MustParseCid("bafk2bzacedrmxfk5qifi7ujcb7mm73mwoy5e7nbndxhbqauuyol6cunf6popm"),
"datacap": MustParseCid("todo"),
},
}, {
Network: "caterpillarnet",
Expand Down Expand Up @@ -107,6 +109,7 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet
"storagepower": MustParseCid("bafk2bzacedbfoblr65vbqwx37cym6v3zhbgrau46vma4c2lbh6toz6q5dyrtc"),
"system": MustParseCid("bafk2bzaced7z2lu5hp4qpsesbmubq3chrad3sl6kgveldafksh4w252ijjaw2"),
"verifiedregistry": MustParseCid("bafk2bzacec6fdlcvlnaiktdptogae3bgofhzo24lhn4hs6rsa2zbnknfpsct6"),
"datacap": MustParseCid("todo"),
},
}, {
Network: "devnet",
Expand Down Expand Up @@ -141,6 +144,7 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet
"storagepower": MustParseCid("bafk2bzaced377v52henedhmudi2isuxe73mp2lrv2zyyxfp4r4uppz3sy2ipw"),
"system": MustParseCid("bafk2bzacebb3gdmg2fqexijivo7dkxj6g6gu7ou2jsw6opszr5gfmwt4fvorw"),
"verifiedregistry": MustParseCid("bafk2bzacec5xfb3a56mlclymhvs2br3qzx7sagqda4dvl4xz3fgiymkkbz5tk"),
"datacap": MustParseCid("todo"),
},
}, {
Network: "mainnet",
Expand Down Expand Up @@ -175,6 +179,7 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet
"storagepower": MustParseCid("bafk2bzacec3dmcwtizgy6qhxg6fgb4ykc2pamxxh2n5oyeqvebjf3ikzd2sui"),
"system": MustParseCid("bafk2bzacecrm36gf2gusruvhfc6ukf36qflsr5pdbquvfyysprdyudsatoufm"),
"verifiedregistry": MustParseCid("bafk2bzaceah3mwu6tb4jmffohpoz6nyoxpgno2hmxz455rycw4o2hrat3yg3u"),
"datacap": MustParseCid("todo"),
},
}, {
Network: "testing",
Expand Down Expand Up @@ -209,6 +214,7 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet
"storagepower": MustParseCid("bafk2bzaceasmr5xc3c7jgihqcb5pdv557kfor72wlmzmh4syvedknelebhsve"),
"system": MustParseCid("bafk2bzaceabj3whuno364pjqn7sphwquiqpl2w5le6aa6quwytgyxshvelcwq"),
"verifiedregistry": MustParseCid("bafk2bzaceamn6gzihkytyqym4dqs7wqmo2fz6kpge4tphumvutsp2ys4bwaha"),
"datacap": MustParseCid("todo"),
},
}, {
Network: "testing-fake-proofs",
Expand Down Expand Up @@ -243,5 +249,6 @@ var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMet
"storagepower": MustParseCid("bafk2bzaceaoteuuvld3bzy3t3kzjp5iabgkvxjc5cxq2ziwankpxqqixkqqjw"),
"system": MustParseCid("bafk2bzaceabj3whuno364pjqn7sphwquiqpl2w5le6aa6quwytgyxshvelcwq"),
"verifiedregistry": MustParseCid("bafk2bzaceamn6gzihkytyqym4dqs7wqmo2fz6kpge4tphumvutsp2ys4bwaha"),
"datacap": MustParseCid("todo"),
},
}}
2 changes: 1 addition & 1 deletion build/builtin_actors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestRegistration(t *testing.T) {
require.True(t, found)
require.True(t, manifestCid.Defined())

for _, key := range actors.GetBuiltinActorsKeys() {
for _, key := range actors.GetBuiltinActorsKeys(actorstypes.Version8) {
actorCid, found := actors.GetActorCodeID(actorstypes.Version8, key)
require.True(t, found)
name, version, found := actors.GetActorMetaByCode(actorCid)
Expand Down
2 changes: 1 addition & 1 deletion chain/actors/actor_cids.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func GetActorCodeIDs(av actorstypes.Version) (map[string]cid.Cid, error) {
return cids, nil
}

actorsKeys := GetBuiltinActorsKeys()
actorsKeys := GetBuiltinActorsKeys(av)
synthCids := make(map[string]cid.Cid)

for _, key := range actorsKeys {
Expand Down
51 changes: 35 additions & 16 deletions chain/actors/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,40 @@ const (
RewardKey = "reward"
SystemKey = "system"
VerifregKey = "verifiedregistry"
DatacapKey = "datacap"
)

func GetBuiltinActorsKeys() []string {
return []string{
AccountKey,
CronKey,
InitKey,
MarketKey,
MinerKey,
MultisigKey,
PaychKey,
PowerKey,
RewardKey,
SystemKey,
VerifregKey,
func GetBuiltinActorsKeys(av actorstypes.Version) []string {
if av <= 8 {
return []string{
AccountKey,
CronKey,
InitKey,
MarketKey,
MinerKey,
MultisigKey,
PaychKey,
PowerKey,
RewardKey,
SystemKey,
VerifregKey,
DatacapKey,
}
} else {
return []string{
AccountKey,
CronKey,
InitKey,
MarketKey,
MinerKey,
MultisigKey,
PaychKey,
PowerKey,
RewardKey,
SystemKey,
VerifregKey,
DatacapKey,
}
}
}

Expand All @@ -58,7 +77,7 @@ type actorEntry struct {
version actorstypes.Version
}

// ClearManifest clears all known manifests. This is usually used in tests that need to switch networks.
// ClearManifests clears all known manifests. This is usually used in tests that need to switch networks.
func ClearManifests() {
manifestMx.Lock()
defer manifestMx.Unlock()
Expand Down Expand Up @@ -91,7 +110,7 @@ func GetManifest(av actorstypes.Version) (cid.Cid, bool) {
}

// ReadManifest reads a manifest from a blockstore. It does not "add" it.
func ReadManifest(ctx context.Context, store cbor.IpldStore, mfCid cid.Cid) (map[string]cid.Cid, error) {
func ReadManifest(ctx context.Context, store cbor.IpldStore, mfCid cid.Cid, av actorstypes.Version) (map[string]cid.Cid, error) {
adtStore := adt.WrapStore(ctx, store)

var mf manifest.Manifest
Expand All @@ -103,7 +122,7 @@ func ReadManifest(ctx context.Context, store cbor.IpldStore, mfCid cid.Cid) (map
return nil, xerrors.Errorf("error loading manifest (cid: %s): %w", mfCid, err)
}

actorKeys := GetBuiltinActorsKeys() // TODO: we should be able to enumerate manifests directly.
actorKeys := GetBuiltinActorsKeys(av) // TODO: we should be able to enumerate manifests directly.
metadata := make(map[string]cid.Cid, len(actorKeys))
for _, name := range actorKeys {
if c, ok := mf.Get(name); ok {
Expand Down
4 changes: 2 additions & 2 deletions chain/consensus/filcns/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -1615,10 +1615,10 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM
return cid.Undef, xerrors.Errorf("error loading new manifest data: %w", err)
}

if len(oldManifestData.Entries) != len(actors.GetBuiltinActorsKeys()) {
if len(oldManifestData.Entries) != len(actors.GetBuiltinActorsKeys(av-1)) {
return cid.Undef, xerrors.Errorf("incomplete old manifest with %d code CIDs", len(oldManifestData.Entries))
}
if len(newManifestData.Entries) != len(actors.GetBuiltinActorsKeys()) {
if len(newManifestData.Entries) != len(actors.GetBuiltinActorsKeys(av)) {
return cid.Undef, xerrors.Errorf("incomplete new manifest with %d code CIDs", len(newManifestData.Entries))
}

Expand Down
2 changes: 1 addition & 1 deletion chain/vm/fvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func NewDebugFVM(ctx context.Context, opts *VMOpts) (*FVM, error) {

// create actor redirect mapping
actorRedirect := make(map[cid.Cid]cid.Cid)
for _, key := range actors.GetBuiltinActorsKeys() {
for _, key := range actors.GetBuiltinActorsKeys(actorstypes.Version8) {
from, ok := actors.GetActorCodeID(actorstypes.Version8, key)
if !ok {
log.Warnf("actor missing in the from manifest %s", key)
Expand Down

0 comments on commit a8951fb

Please sign in to comment.