diff --git a/chain/consensus/filcns/upgrades.go b/chain/consensus/filcns/upgrades.go index 6ac159a78..d95af28b2 100644 --- a/chain/consensus/filcns/upgrades.go +++ b/chain/consensus/filcns/upgrades.go @@ -1449,7 +1449,8 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM if stateRoot.Version != oldStateTreeVersion { return cid.Undef, xerrors.Errorf( - "expected state root version 4 for actors code upgrade, got %d", + "expected state tree version %d for actors code upgrade, got %d", + oldStateTreeVersion, stateRoot.Version, ) } @@ -1459,23 +1460,8 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM return cid.Undef, xerrors.Errorf("failed to load state tree: %w", err) } - // Get old actors - systemActor, err := st.GetActor(system.Address) + oldManifest, err := stmgr.GetManifest(ctx, st) if err != nil { - return cid.Undef, xerrors.Errorf("failed to get system actor: %w", err) - } - systemActorState, err := system.Load(store, systemActor) - if err != nil { - return cid.Undef, xerrors.Errorf("failed to load system actor state: %w", err) - } - oldActorsManifestCid := systemActorState.GetBuiltinActors() - - // load old manifest - oldManifest := manifest.Manifest{ - Version: 1, - Data: oldActorsManifestCid, - } - if err := oldManifest.Load(ctx, adtStore); err != nil { return cid.Undef, xerrors.Errorf("error loading old actor manifest: %w", err) } oldManifestData := manifest.ManifestData{} @@ -1506,7 +1492,7 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM 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 manifest", entry.Name) + return cid.Undef, xerrors.Errorf("code cid for %s actor not found in old manifest", entry.Name) } migrations[oldCodeCid] = entry.Code } @@ -1525,29 +1511,24 @@ func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsM if !ok { return xerrors.Errorf("new code cid not found in migrations for actor %s", addr) } - var newActor types.Actor + var head cid.Cid if addr == system.Address { newSystemState, err := system.MakeState(store, av, newManifest.Data) if err != nil { return xerrors.Errorf("could not make system actor state: %w", err) } - systemStateHead, err := store.Put(ctx, newSystemState) + head, err = store.Put(ctx, newSystemState) if err != nil { return xerrors.Errorf("could not set system actor state head: %w", err) } - newActor = types.Actor{ - Code: newCid, - Head: systemStateHead, - Nonce: actorIn.Nonce, - Balance: actorIn.Balance, - } } else { - newActor = types.Actor{ - Code: newCid, - Head: actorIn.Head, - Nonce: actorIn.Nonce, - Balance: actorIn.Balance, - } + head = actorIn.Head + } + newActor := types.Actor{ + Code: newCid, + Head: head, + Nonce: actorIn.Nonce, + Balance: actorIn.Balance, } err = actorsOut.SetActor(addr, &newActor) if err != nil { diff --git a/chain/stmgr/actors.go b/chain/stmgr/actors.go index 6e5b40d50..bfa04827e 100644 --- a/chain/stmgr/actors.go +++ b/chain/stmgr/actors.go @@ -3,7 +3,6 @@ package stmgr import ( "bytes" "context" - "fmt" "os" "golang.org/x/xerrors" @@ -13,9 +12,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/go-state-types/manifest" "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/go-state-types/store" cid "github.com/ipfs/go-cid" miner_types "github.com/filecoin-project/go-state-types/builtin/v8/miner" @@ -25,10 +22,8 @@ import ( "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/actors/builtin/power" - "github.com/filecoin-project/lotus/chain/actors/builtin/system" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/rand" - "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" @@ -556,60 +551,4 @@ func (sm *StateManager) MarketBalance(ctx context.Context, addr address.Address, return out, nil } -func (sm *StateManager) GetManifest(ctx context.Context, root cid.Cid) (*manifest.Manifest, error) { - st, err := sm.StateTree(root) - if err != nil { - return nil, fmt.Errorf("failed to get state tree: %w", err) - } - return GetManifestFromStateTree(ctx, st) -} - -func GetManifestFromStateTree(ctx context.Context, st *state.StateTree) (*manifest.Manifest, error) { - wrapStore := store.WrapStore(ctx, st.Store) - - systemActor, err := st.GetActor(system.Address) - if err != nil { - return nil, fmt.Errorf("failed to get system actor: %w", err) - } - systemActorState, err := system.Load(wrapStore, systemActor) - 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 -} - -func (sm *StateManager) GetManifestData(ctx context.Context, root cid.Cid) ([]manifest.ManifestEntry, error) { - st, err := sm.StateTree(root) - if err != nil { - return nil, fmt.Errorf("failed to get state tree: %w", err) - } - - return GetManifestDataFromStateTree(ctx, st) -} - -func GetManifestDataFromStateTree(ctx context.Context, st *state.StateTree) ([]manifest.ManifestEntry, error) { - mf, err := GetManifestFromStateTree(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) - } - return manifestData.Entries, nil -} - var _ StateManagerAPI = (*StateManager)(nil) diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 2a84c777b..61eb5fcb0 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -5,18 +5,21 @@ import ( "fmt" "reflect" - "github.com/filecoin-project/lotus/chain/rand" - "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" + "github.com/filecoin-project/go-state-types/manifest" + gstStore "github.com/filecoin-project/go-state-types/store" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/api" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + "github.com/filecoin-project/lotus/chain/actors/builtin/system" "github.com/filecoin-project/lotus/chain/actors/policy" + "github.com/filecoin-project/lotus/chain/rand" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" @@ -211,3 +214,42 @@ func (sm *StateManager) ListAllActors(ctx context.Context, ts *types.TipSet) ([] return out, nil } + +func GetManifest(ctx context.Context, st *state.StateTree) (*manifest.Manifest, error) { + wrapStore := gstStore.WrapStore(ctx, st.Store) + + systemActor, err := st.GetActor(system.Address) + if err != nil { + return nil, fmt.Errorf("failed to get system actor: %w", err) + } + systemActorState, err := system.Load(wrapStore, systemActor) + 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 +} + +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) + } + return manifestData.Entries, nil +} diff --git a/gateway/node.go b/gateway/node.go index 7885ddff5..471c6200a 100644 --- a/gateway/node.go +++ b/gateway/node.go @@ -254,12 +254,12 @@ func (gw *Node) ChainReadObj(ctx context.Context, c cid.Cid) ([]byte, error) { return gw.target.ChainReadObj(ctx, c) } -func (gw *Node) ChainPutObj(ctx context.Context, block blocks.Block) error { - return gw.target.ChainPutObj(ctx, block) +func (gw *Node) ChainPutObj(context.Context, blocks.Block) error { + return xerrors.New("not supported") } -func (gw *Node) ChainPutMany(ctx context.Context, blocks []blocks.Block) error { - return gw.target.ChainPutMany(ctx, blocks) +func (gw *Node) ChainPutMany(context.Context, []blocks.Block) error { + return xerrors.New("not supported") } func (gw *Node) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error) { diff --git a/itests/lite_migration_test.go b/itests/lite_migration_test.go index 65a5a3eca..8701dac4e 100644 --- a/itests/lite_migration_test.go +++ b/itests/lite_migration_test.go @@ -47,7 +47,7 @@ func TestLiteMigration(t *testing.T) { oldStateTree, err := state.LoadStateTree(ctxStore, stateRoot) require.NoError(t, err) - oldManifest, err := stmgr.GetManifestFromStateTree(ctx, oldStateTree) + oldManifest, err := stmgr.GetManifest(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