Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC: FVM Debug Dual Execution #8841

Merged
merged 4 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions chain/actors/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ func ReadManifest(ctx context.Context, store cbor.IpldStore, mfCid cid.Cid) (map
return metadata, nil
}

// Given a Manifest CID, get the manifest from the store and Load data into its entries
func LoadManifest(ctx context.Context, mfCid cid.Cid, adtStore adt.Store) (*manifest.Manifest, error) {
var mf manifest.Manifest

if err := adtStore.Get(ctx, mfCid, &mf); err != nil {
return nil, xerrors.Errorf("error reading manifest: %w", err)
}

if err := mf.Load(ctx, adtStore); err != nil {
return nil, xerrors.Errorf("error loading manifest entries data: %w", err)
}

return &mf, nil
}

// GetActorCodeID looks up a builtin actor's code CID by actor version and canonical actor name.
func GetActorCodeID(av Version, name string) (cid.Cid, bool) {
manifestMx.RLock()
Expand Down
25 changes: 14 additions & 11 deletions chain/consensus/filcns/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -1477,21 +1477,23 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM
return cid.Undef, xerrors.Errorf("failed to load state tree: %w", err)
}

oldManifest, err := stmgr.GetManifest(ctx, st)
oldManifestData, err := stmgr.GetManifestData(ctx, st)
if err != nil {
return cid.Undef, xerrors.Errorf("error loading old actor manifest: %w", err)
}
oldManifestData := manifest.ManifestData{}
if err := store.Get(ctx, oldManifest.Data, &oldManifestData); err != nil {
return cid.Undef, xerrors.Errorf("error loading old manifest data: %w", err)
}

// load new manifest
newManifest := manifest.Manifest{}
var newManifest manifest.Manifest
if err := store.Get(ctx, newActorsManifestCid, &newManifest); err != nil {
return cid.Undef, xerrors.Errorf("error getting new manifest: %w", err)
}

// populate the entries field of the manifest
if err = newManifest.Load(ctx, store); err != nil {
return cid.Undef, xerrors.Errorf("error loading new manifest: %w", err)
}
arajasek marked this conversation as resolved.
Show resolved Hide resolved
newManifestData := manifest.ManifestData{}

var newManifestData manifest.ManifestData
if err := store.Get(ctx, newManifest.Data, &newManifestData); err != nil {
Comment on lines +1491 to 1492
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause us to load the ManifestData twice, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even use this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, solely to check the number of entries, which I can't do from newManifest directly because there's no way (yet) to count the number of entries in a Manifest...

return cid.Undef, xerrors.Errorf("error loading new manifest data: %w", err)
}
Expand All @@ -1506,12 +1508,13 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM
// Maps prior version code CIDs to migration functions.
migrations := make(map[cid.Cid]cid.Cid)

for _, entry := range newManifestData.Entries {
oldCodeCid, ok := oldManifest.Get(entry.Name)
for _, entry := range oldManifestData.Entries {
newCodeCid, ok := newManifest.Get(entry.Name)
if !ok {
return cid.Undef, xerrors.Errorf("code cid for %s actor not found in old manifest", entry.Name)
return cid.Undef, xerrors.Errorf("code cid for %s actor not found in new manifest", entry.Name)
}
migrations[oldCodeCid] = entry.Code

migrations[entry.Code] = newCodeCid
}

startTime := time.Now()
Expand Down
2 changes: 1 addition & 1 deletion chain/gen/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca
}
vm, err := vm.NewVM(ctx, &vmopt)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to create NewLegacyVM: %w", err)
return cid.Undef, xerrors.Errorf("failed to create VM: %w", err)
}

for mi, m := range template.Miners {
Expand Down
31 changes: 7 additions & 24 deletions chain/stmgr/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (sm *StateManager) ListAllActors(ctx context.Context, ts *types.TipSet) ([]
return out, nil
}

func GetManifest(ctx context.Context, st *state.StateTree) (*manifest.Manifest, error) {
func GetManifestData(ctx context.Context, st *state.StateTree) (*manifest.ManifestData, error) {
wrapStore := gstStore.WrapStore(ctx, st.Store)

systemActor, err := st.GetActor(system.Address)
Expand All @@ -226,30 +226,13 @@ func GetManifest(ctx context.Context, st *state.StateTree) (*manifest.Manifest,
if err != nil {
return nil, xerrors.Errorf("failed to load system actor state: %w", err)
}
actorsManifestCid := systemActorState.GetBuiltinActors()

mf := manifest.Manifest{
Version: 1,
Data: actorsManifestCid,
}
if err := mf.Load(ctx, wrapStore); err != nil {
return nil, xerrors.Errorf("failed to load actor manifest: %w", err)
}
manifestData := manifest.ManifestData{}
if err := st.Store.Get(ctx, mf.Data, &manifestData); err != nil {
return nil, xerrors.Errorf("failed to load manifest data: %w", err)
}
return &mf, nil
}
actorsManifestDataCid := systemActorState.GetBuiltinActors()

func GetManifestEntries(ctx context.Context, st *state.StateTree) ([]manifest.ManifestEntry, error) {
mf, err := GetManifest(ctx, st)
if err != nil {
return nil, xerrors.Errorf("failed to get manifest: %w", err)
}
manifestData := manifest.ManifestData{}
if err := st.Store.Get(ctx, mf.Data, &manifestData); err != nil {
return nil, xerrors.Errorf("filed to load manifest data: %w", err)
var mfData manifest.ManifestData
if err := wrapStore.Get(ctx, actorsManifestDataCid, &mfData); err != nil {
return nil, xerrors.Errorf("error fetching data: %w", err)
}
return manifestData.Entries, nil

return &mfData, nil
}
Stebalien marked this conversation as resolved.
Show resolved Hide resolved
Loading