Skip to content

Commit

Permalink
chore: lotus-shed: Add support for nv23 in migrate-state cmd (#12172)
Browse files Browse the repository at this point in the history
* Add support for nv23 in `lotus-shed migrate-state` cmd

Add support for nv23 in `lotus-shed migrate-state` cmd

* Add actors v14 to `check-invariants` cmd

Add actors v14 to `check-invariants` cmd
  • Loading branch information
rjan90 committed Jul 22, 2024
1 parent 33d0861 commit 21f8f95
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/lotus-shed/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
v11 "github.com/filecoin-project/go-state-types/builtin/v11"
v12 "github.com/filecoin-project/go-state-types/builtin/v12"
v13 "github.com/filecoin-project/go-state-types/builtin/v13"
v14 "github.com/filecoin-project/go-state-types/builtin/v14"
v8 "github.com/filecoin-project/go-state-types/builtin/v8"
v9 "github.com/filecoin-project/go-state-types/builtin/v9"

Expand Down Expand Up @@ -192,6 +193,11 @@ var invariantsCmd = &cli.Command{
if err != nil {
return xerrors.Errorf("checking state invariants: %w", err)
}
case actorstypes.Version14:
messages, err = v14.CheckStateInvariants(actorTree, abi.ChainEpoch(epoch), actorCodeCids)
if err != nil {
return xerrors.Errorf("checking state invariants: %w", err)
}
default:
return xerrors.Errorf("unsupported actor version: %v", av)
}
Expand Down
35 changes: 35 additions & 0 deletions cmd/lotus-shed/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
v13 "github.com/filecoin-project/go-state-types/builtin/v13"
market13 "github.com/filecoin-project/go-state-types/builtin/v13/market"
adt13 "github.com/filecoin-project/go-state-types/builtin/v13/util/adt"
v14 "github.com/filecoin-project/go-state-types/builtin/v14"
market8 "github.com/filecoin-project/go-state-types/builtin/v8/market"
adt8 "github.com/filecoin-project/go-state-types/builtin/v8/util/adt"
v9 "github.com/filecoin-project/go-state-types/builtin/v9"
Expand Down Expand Up @@ -291,6 +292,8 @@ func getMigrationFuncsForNetwork(nv network.Version) (UpgradeActorsFunc, PreUpgr
return filcns.UpgradeActorsV12, filcns.PreUpgradeActorsV12, checkNv21Invariants, nil
case network.Version22:
return filcns.UpgradeActorsV13, filcns.PreUpgradeActorsV13, checkNv22Invariants, nil
case network.Version23:
return filcns.UpgradeActorsV14, filcns.PreUpgradeActorsV14, checkNv23Invariants, nil
default:
return nil, nil, nil, xerrors.Errorf("migration not implemented for nv%d", nv)
}
Expand Down Expand Up @@ -619,6 +622,38 @@ func printMarketActorDiff(ctx context.Context, cst *cbornode.BasicIpldStore, nv
return nil
}

func checkNv23Invariants(ctx context.Context, oldStateRootCid cid.Cid, newStateRootCid cid.Cid, bs blockstore.Blockstore, epoch abi.ChainEpoch) error {

actorStore := store.ActorStore(ctx, bs)
startTime := time.Now()

// Load the new state root.
var newStateRoot types.StateRoot
if err := actorStore.Get(ctx, newStateRootCid, &newStateRoot); err != nil {
return xerrors.Errorf("failed to decode state root: %w", err)
}

actorCodeCids, err := actors.GetActorCodeIDs(actorstypes.Version14)
if err != nil {
return err
}
newActorTree, err := builtin.LoadTree(actorStore, newStateRoot.Actors)
if err != nil {
return err
}
messages, err := v14.CheckStateInvariants(newActorTree, epoch, actorCodeCids)
if err != nil {
return xerrors.Errorf("checking state invariants: %w", err)
}

for _, message := range messages.Messages() {
fmt.Println("got the following error: ", message)
}

fmt.Println("completed invariant checks, took ", time.Since(startTime))

return nil
}
func checkNv22Invariants(ctx context.Context, oldStateRootCid cid.Cid, newStateRootCid cid.Cid, bs blockstore.Blockstore, epoch abi.ChainEpoch) error {

actorStore := store.ActorStore(ctx, bs)
Expand Down

0 comments on commit 21f8f95

Please sign in to comment.