an attempt at cleanup
This commit is contained in:
parent
3ad2fc5c4a
commit
a52d584d0c
@ -113,6 +113,22 @@ func ReadManifest(ctx context.Context, store cbor.IpldStore, mfCid cid.Cid) (map
|
||||
return metadata, nil
|
||||
}
|
||||
|
||||
// Given a Manifest CID (NOT the ManifestData CID), load the underlying ManifestData
|
||||
func LoadManifestData(ctx context.Context, mfCid cid.Cid, adtStore adt.Store) (*manifest.ManifestData, error) {
|
||||
var mf manifest.Manifest
|
||||
var mfData manifest.ManifestData
|
||||
|
||||
if err := adtStore.Get(ctx, mfCid, &mf); err != nil {
|
||||
return nil, xerrors.Errorf("error reading manifest: %w", err)
|
||||
}
|
||||
|
||||
if err := adtStore.Get(ctx, mf.Data, &mfData); err != nil {
|
||||
return nil, xerrors.Errorf("error fetching data: %w", err)
|
||||
}
|
||||
|
||||
return &mfData, 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()
|
||||
|
@ -1477,22 +1477,19 @@ 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{}
|
||||
if err := store.Get(ctx, newActorsManifestCid, &newManifest); err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error loading new manifest: %w", err)
|
||||
}
|
||||
newManifestData := manifest.ManifestData{}
|
||||
if err := store.Get(ctx, newManifest.Data, &newManifestData); err != nil {
|
||||
|
||||
newManifestData, err := actors.LoadManifestData(ctx, newActorsManifestCid, store)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error loading new manifest data: %w", err)
|
||||
}
|
||||
|
||||
@ -1506,12 +1503,8 @@ 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)
|
||||
if !ok {
|
||||
return cid.Undef, xerrors.Errorf("code cid for %s actor not found in old manifest", entry.Name)
|
||||
}
|
||||
migrations[oldCodeCid] = entry.Code
|
||||
for i, entry := range newManifestData.Entries {
|
||||
migrations[oldManifestData.Entries[i].Code] = entry.Code
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
|
@ -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)
|
||||
@ -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)
|
||||
var mfData manifest.ManifestData
|
||||
if err := wrapStore.Get(ctx, actorsManifestDataCid, &mfData); err != nil {
|
||||
return nil, xerrors.Errorf("error fetching data: %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)
|
||||
}
|
||||
return manifestData.Entries, nil
|
||||
|
||||
return &mfData, nil
|
||||
}
|
||||
|
@ -10,11 +10,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||
@ -22,7 +20,6 @@ import (
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
"github.com/filecoin-project/go-state-types/exitcode"
|
||||
"github.com/filecoin-project/go-state-types/manifest"
|
||||
|
||||
"github.com/filecoin-project/lotus/blockstore"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
@ -324,6 +321,7 @@ func NewDebugFVM(ctx context.Context, opts *VMOpts) (*FVM, error) {
|
||||
|
||||
baseBstore := opts.Bstore
|
||||
overlayBstore := blockstore.NewMemorySync()
|
||||
cborStore := cbor.NewCborStore(overlayBstore)
|
||||
vmBstore := blockstore.NewTieredBstore(overlayBstore, baseBstore)
|
||||
|
||||
fvmopts := &ffi.FVMOpts{
|
||||
@ -344,14 +342,6 @@ func NewDebugFVM(ctx context.Context, opts *VMOpts) (*FVM, error) {
|
||||
Debug: true,
|
||||
}
|
||||
|
||||
loadBundle := func(path string) (cid.Cid, error) {
|
||||
return bundle.LoadBundleData(ctx, path, overlayBstore)
|
||||
}
|
||||
|
||||
loadManifest := func(mfCid cid.Cid) (manifest.ManifestData, error) {
|
||||
return bundle.LoadManifestData(ctx, mfCid, overlayBstore)
|
||||
}
|
||||
|
||||
putMapping := func(ar map[cid.Cid]cid.Cid) (cid.Cid, error) {
|
||||
var mapping xMapping
|
||||
|
||||
@ -364,7 +354,6 @@ func NewDebugFVM(ctx context.Context, opts *VMOpts) (*FVM, error) {
|
||||
})
|
||||
|
||||
// Passing this as a pointer of structs has proven to be an enormous PiTA; hence this code.
|
||||
cborStore := cbor.NewCborStore(overlayBstore)
|
||||
mappingCid, err := cborStore.Put(context.TODO(), &mapping)
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
@ -379,57 +368,14 @@ func NewDebugFVM(ctx context.Context, opts *VMOpts) (*FVM, error) {
|
||||
}
|
||||
|
||||
switch av {
|
||||
case actors.Version7:
|
||||
if bundle := os.Getenv("LOTUS_FVM_DEBUG_BUNDLE_V7"); bundle != "" {
|
||||
mfCid, err := loadBundle(bundle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mf, err := loadManifest(mfCid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// create actor redirect mapping from the synthetic Cid to the debug code
|
||||
actorRedirect := make(map[cid.Cid]cid.Cid)
|
||||
fromMap := map[string]cid.Cid{
|
||||
"init": builtin7.InitActorCodeID,
|
||||
"cron": builtin7.CronActorCodeID,
|
||||
"account": builtin7.AccountActorCodeID,
|
||||
"storagepower": builtin7.StoragePowerActorCodeID,
|
||||
"storageminer": builtin7.StorageMinerActorCodeID,
|
||||
"paymentchannel": builtin7.PaymentChannelActorCodeID,
|
||||
"multisig": builtin7.MultisigActorCodeID,
|
||||
"reward": builtin7.RewardActorCodeID,
|
||||
"verifiedregistry": builtin7.VerifiedRegistryActorCodeID,
|
||||
}
|
||||
|
||||
for _, e := range mf.Entries {
|
||||
from, ok := fromMap[e.Name]
|
||||
if !ok {
|
||||
return nil, xerrors.Errorf("error mapping %s for debug redirect: %w", e.Name, err)
|
||||
}
|
||||
actorRedirect[from] = e.Code
|
||||
}
|
||||
|
||||
if len(actorRedirect) > 0 {
|
||||
mappingCid, err := putMapping(actorRedirect)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("error writing redirect mapping: %w", err)
|
||||
}
|
||||
fvmopts.ActorRedirect = mappingCid
|
||||
}
|
||||
}
|
||||
|
||||
case actors.Version8:
|
||||
if bundle := os.Getenv("LOTUS_FVM_DEBUG_BUNDLE_V8"); bundle != "" {
|
||||
mfCid, err := loadBundle(bundle)
|
||||
if bundlePath := os.Getenv("LOTUS_FVM_DEBUG_BUNDLE_V8"); bundlePath != "" {
|
||||
mfCid, err := bundle.LoadBundleFromFile(ctx, overlayBstore, bundlePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mf, err := loadManifest(mfCid)
|
||||
mf, err := actors.LoadManifestData(ctx, mfCid, adt.WrapStore(ctx, cborStore))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -4,9 +4,10 @@ import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/network"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
|
@ -47,17 +47,11 @@ func TestLiteMigration(t *testing.T) {
|
||||
oldStateTree, err := state.LoadStateTree(ctxStore, stateRoot)
|
||||
require.NoError(t, err)
|
||||
|
||||
oldManifest, err := stmgr.GetManifest(ctx, oldStateTree)
|
||||
oldManifestData, err := stmgr.GetManifestData(ctx, oldStateTree)
|
||||
require.NoError(t, err)
|
||||
newManifestCid := makeTestManifest(t, ctxStore)
|
||||
// Use the Cid we generated to get the new manifest instead of loading it from the state tree, because that would not test that we have the correct manifest in the state
|
||||
var newManifest manifest.Manifest
|
||||
err = ctxStore.Get(ctx, newManifestCid, &newManifest)
|
||||
require.NoError(t, err)
|
||||
err = newManifest.Load(ctx, ctxStore)
|
||||
require.NoError(t, err)
|
||||
newManifestData := manifest.ManifestData{}
|
||||
err = ctxStore.Get(ctx, newManifest.Data, &newManifestData)
|
||||
newManifestData, err := actors.LoadManifestData(ctx, newManifestCid, ctxStore)
|
||||
require.NoError(t, err)
|
||||
|
||||
newStateRoot, err := filcns.LiteMigration(ctx, bs, newManifestCid, stateRoot, actors.Version8, types.StateTreeVersion4, types.StateTreeVersion4)
|
||||
@ -67,10 +61,8 @@ func TestLiteMigration(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
migrations := make(map[cid.Cid]cid.Cid)
|
||||
for _, entry := range newManifestData.Entries {
|
||||
oldCodeCid, ok := oldManifest.Get(entry.Name)
|
||||
require.True(t, ok)
|
||||
migrations[oldCodeCid] = entry.Code
|
||||
for i, entry := range newManifestData.Entries {
|
||||
migrations[oldManifestData.Entries[i].Code] = entry.Code
|
||||
}
|
||||
|
||||
err = newStateTree.ForEach(func(addr address.Address, newActorState *types.Actor) error {
|
||||
|
@ -1,52 +0,0 @@
|
||||
package bundle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/manifest"
|
||||
"github.com/filecoin-project/lotus/blockstore"
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
car "github.com/ipld/go-car"
|
||||
)
|
||||
|
||||
func LoadBundleData(ctx context.Context, bundle string, bs blockstore.Blockstore) (cid.Cid, error) {
|
||||
f, err := os.Open(bundle)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error opening debug bundle: %w", err)
|
||||
}
|
||||
defer f.Close() //nolint
|
||||
|
||||
hdr, err := car.LoadCar(ctx, bs, f)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("error loading debug bundle: %w", err)
|
||||
}
|
||||
|
||||
return hdr.Roots[0], nil
|
||||
}
|
||||
|
||||
func LoadManifestData(ctx context.Context, mfCid cid.Cid, bs blockstore.Blockstore) (manifest.ManifestData, error) {
|
||||
adtStore := adt.WrapStore(ctx, cbor.NewCborStore(bs))
|
||||
|
||||
var mf manifest.Manifest
|
||||
var mfData manifest.ManifestData
|
||||
|
||||
if err := adtStore.Get(ctx, mfCid, &mf); err != nil {
|
||||
return mfData, xerrors.Errorf("error reading debug manifest: %w", err)
|
||||
}
|
||||
|
||||
if err := mf.Load(ctx, adtStore); err != nil {
|
||||
return mfData, xerrors.Errorf("error loading debug manifest: %w", err)
|
||||
}
|
||||
|
||||
if err := adtStore.Get(ctx, mf.Data, &mfData); err != nil {
|
||||
return mfData, xerrors.Errorf("error fetching manifest data: %w", err)
|
||||
}
|
||||
|
||||
return mfData, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user