Skip to content

Commit

Permalink
Integrate datacap actor
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball committed Sep 21, 2022
1 parent 94add97 commit 9e03c7e
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 23 deletions.
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
35 changes: 27 additions & 8 deletions chain/actors/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,25 @@ const (
RewardKey = "reward"
SystemKey = "system"
VerifregKey = "verifiedregistry"
DatacapKey = "datacap"
)

func GetBuiltinActorsKeys() []string {
func GetBuiltinActorsKeys(av actorstypes.Version) []string {
if av <= 8 {
return []string{
AccountKey,
CronKey,
InitKey,
MarketKey,
MinerKey,
MultisigKey,
PaychKey,
PowerKey,
RewardKey,
SystemKey,
VerifregKey,
}
}
return []string{
AccountKey,
CronKey,
Expand All @@ -46,6 +62,7 @@ func GetBuiltinActorsKeys() []string {
RewardKey,
SystemKey,
VerifregKey,
DatacapKey,
}
}

Expand All @@ -58,7 +75,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 @@ -103,12 +120,14 @@ 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.
metadata := make(map[string]cid.Cid, len(actorKeys))
for _, name := range actorKeys {
if c, ok := mf.Get(name); ok {
metadata[name] = c
}
var manifestData manifest.ManifestData
if err := store.Get(ctx, mf.Data, &manifestData); err != nil {
return nil, xerrors.Errorf("error loading manifest data: %w", err)
}

metadata := make(map[string]cid.Cid)
for _, entry := range manifestData.Entries {
metadata[entry.Name] = entry.Code
}

return metadata, nil
Expand Down
8 changes: 4 additions & 4 deletions chain/consensus/filcns/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ func upgradeActorsV9Common(
// return LiteMigration(ctx, bstore, newActorsManifestCid, root, av, types.StateTreeVersion4, newStateTreeVersion)
//}

func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsManifestCid cid.Cid, root cid.Cid, av actorstypes.Version, oldStateTreeVersion types.StateTreeVersion, newStateTreeVersion types.StateTreeVersion) (cid.Cid, error) {
func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsManifestCid cid.Cid, root cid.Cid, oldAv actorstypes.Version, newAv actorstypes.Version, oldStateTreeVersion types.StateTreeVersion, newStateTreeVersion types.StateTreeVersion) (cid.Cid, error) {
buf := blockstore.NewTieredBstore(bstore, blockstore.NewMemorySync())
store := store.ActorStore(ctx, buf)
adtStore := gstStore.WrapStore(ctx, store)
Expand Down 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(oldAv)) {
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(newAv)) {
return cid.Undef, xerrors.Errorf("incomplete new manifest with %d code CIDs", len(newManifestData.Entries))
}

Expand Down Expand Up @@ -1650,7 +1650,7 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM
}
var head cid.Cid
if addr == system.Address {
newSystemState, err := system.MakeState(store, av, newManifest.Data)
newSystemState, err := system.MakeState(store, newAv, newManifest.Data)
if err != nil {
return xerrors.Errorf("could not make system actor state: %w", err)
}
Expand Down
9 changes: 7 additions & 2 deletions chain/vm/fvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,15 @@ func NewDebugFVM(ctx context.Context, opts *VMOpts) (*FVM, error) {
return xerrors.Errorf("loading debug manifest: %w", err)
}

av, err := actorstypes.VersionForNetwork(opts.NetworkVersion)
if err != nil {
return xerrors.Errorf("getting actors version: %w", err)
}

// create actor redirect mapping
actorRedirect := make(map[cid.Cid]cid.Cid)
for _, key := range actors.GetBuiltinActorsKeys() {
from, ok := actors.GetActorCodeID(actorstypes.Version8, key)
for _, key := range actors.GetBuiltinActorsKeys(av) {
from, ok := actors.GetActorCodeID(av, key)
if !ok {
log.Warnf("actor missing in the from manifest %s", key)
continue
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ require (
github.com/filecoin-project/go-legs v0.4.4
github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.1.12-beta.0.20220920181425-d683559e386b
github.com/filecoin-project/go-state-types v0.1.12-beta.0.20220920221126-fd7ccf3f2a41
github.com/filecoin-project/go-statemachine v1.0.2
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/go-storedcounter v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psS
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.12-beta.0.20220920181425-d683559e386b h1:s4F3e3EBo56j+4xmrzmoAIvtgvDwLn4nsIf5bqcU0Qg=
github.com/filecoin-project/go-state-types v0.1.12-beta.0.20220920181425-d683559e386b/go.mod h1:n/kujdC9JphvYTrmaD1+vJpvDPy/DwzckoMzP0nBKWI=
github.com/filecoin-project/go-state-types v0.1.12-beta.0.20220920221126-fd7ccf3f2a41 h1:berTuM/XTOabRB/6In6Xmkv6/2AIs0HHe79+BhXNUx0=
github.com/filecoin-project/go-state-types v0.1.12-beta.0.20220920221126-fd7ccf3f2a41/go.mod h1:n/kujdC9JphvYTrmaD1+vJpvDPy/DwzckoMzP0nBKWI=
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=
Expand Down
10 changes: 6 additions & 4 deletions itests/lite_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"testing"
"time"

"github.com/filecoin-project/lotus/chain/actors"

"github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -51,15 +53,15 @@ func TestLiteMigration(t *testing.T) {

oldManifestData, err := stmgr.GetManifestData(ctx, oldStateTree)
require.NoError(t, err)
newManifestCid := makeTestManifest(t, ctxStore)
newManifestCid := makeTestManifest(t, ctxStore, actorstypes.Version9)
// Use the Cid we generated to get the new manifest instead of loading it from the store, so as to confirm it's in the store
var newManifest manifest.Manifest
require.NoError(t, ctxStore.Get(ctx, newManifestCid, &newManifest), "error getting new manifest")

// populate the entries field of the manifest
require.NoError(t, newManifest.Load(ctx, ctxStore), "error loading new manifest")

newStateRoot, err := filcns.LiteMigration(ctx, bs, newManifestCid, stateRoot, actorstypes.Version8, types.StateTreeVersion4, types.StateTreeVersion4)
newStateRoot, err := filcns.LiteMigration(ctx, bs, newManifestCid, stateRoot, actorstypes.Version8, actorstypes.Version9, types.StateTreeVersion4, types.StateTreeVersion4)
require.NoError(t, err)

newStateTree, err := state.LoadStateTree(ctxStore, newStateRoot)
Expand Down Expand Up @@ -90,11 +92,11 @@ func TestLiteMigration(t *testing.T) {
require.NoError(t, err)
}

func makeTestManifest(t *testing.T, ctxStore adt.Store) cid.Cid {
func makeTestManifest(t *testing.T, ctxStore adt.Store, av actorstypes.Version) cid.Cid {
builder := cid.V1Builder{Codec: cid.Raw, MhType: mh.IDENTITY}

manifestData := manifest.ManifestData{}
for _, name := range []string{"system", "init", "cron", "account", "storagepower", "storageminer", "storagemarket", "paymentchannel", "multisig", "reward", "verifiedregistry"} {
for _, name := range actors.GetBuiltinActorsKeys(av) {
codeCid, err := builder.Sum([]byte(fmt.Sprintf("fil/8/%s", name)))
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 9e03c7e

Please sign in to comment.