Migration cli takes a stateroot cid and a height
This commit is contained in:
parent
10b9d3fa96
commit
5d465056ce
@ -4,8 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
@ -30,7 +33,7 @@ import (
|
|||||||
var invariantsCmd = &cli.Command{
|
var invariantsCmd = &cli.Command{
|
||||||
Name: "check-invariants",
|
Name: "check-invariants",
|
||||||
Description: "Check state invariants",
|
Description: "Check state invariants",
|
||||||
ArgsUsage: "[block to look back from]",
|
ArgsUsage: "[StateRootCid, height]",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "repo",
|
Name: "repo",
|
||||||
@ -40,13 +43,18 @@ var invariantsCmd = &cli.Command{
|
|||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
|
|
||||||
if cctx.NArg() != 1 {
|
if cctx.NArg() != 2 {
|
||||||
return lcli.IncorrectNumArgs(cctx)
|
return lcli.IncorrectNumArgs(cctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
blkCid, err := cid.Decode(cctx.Args().First())
|
stateRootCid, err := cid.Decode(cctx.Args().Get(0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse input: %w", err)
|
return fmt.Errorf("failed to parse state root cid: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
epoch, err := strconv.ParseInt(cctx.Args().Get(1), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to parse epoch: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fsrepo, err := repo.NewFS(cctx.String("repo"))
|
fsrepo, err := repo.NewFS(cctx.String("repo"))
|
||||||
@ -87,17 +95,7 @@ var invariantsCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
blk, err := cs.GetBlock(ctx, blkCid)
|
nv := sm.GetNetworkVersion(ctx, abi.ChainEpoch(epoch))
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ts, err := cs.LoadTipSet(ctx, types.NewTipSetKey(blk.Parents...))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
nv := sm.GetNetworkVersion(ctx, ts.Height())
|
|
||||||
fmt.Println("Network Version ", nv)
|
fmt.Println("Network Version ", nv)
|
||||||
|
|
||||||
av, err := actorstypes.VersionForNetwork(nv)
|
av, err := actorstypes.VersionForNetwork(nv)
|
||||||
@ -112,7 +110,7 @@ var invariantsCmd = &cli.Command{
|
|||||||
|
|
||||||
// Load the state root.
|
// Load the state root.
|
||||||
var stateRoot types.StateRoot
|
var stateRoot types.StateRoot
|
||||||
if err := actorStore.Get(ctx, ts.ParentState(), &stateRoot); err != nil {
|
if err := actorStore.Get(ctx, stateRootCid, &stateRoot); err != nil {
|
||||||
return xerrors.Errorf("failed to decode state root: %w", err)
|
return xerrors.Errorf("failed to decode state root: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,12 +121,12 @@ var invariantsCmd = &cli.Command{
|
|||||||
var messages *builtin.MessageAccumulator
|
var messages *builtin.MessageAccumulator
|
||||||
switch av {
|
switch av {
|
||||||
case actorstypes.Version8:
|
case actorstypes.Version8:
|
||||||
messages, err = v8.CheckStateInvariants(actorTree, ts.Height()-1, actorCodeCids)
|
messages, err = v8.CheckStateInvariants(actorTree, abi.ChainEpoch(epoch), actorCodeCids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("checking state invariants: %w", err)
|
return xerrors.Errorf("checking state invariants: %w", err)
|
||||||
}
|
}
|
||||||
case actorstypes.Version9:
|
case actorstypes.Version9:
|
||||||
messages, err = v9.CheckStateInvariants(actorTree, ts.Height()-1, actorCodeCids)
|
messages, err = v9.CheckStateInvariants(actorTree, abi.ChainEpoch(epoch), actorCodeCids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("checking state invariants: %w", err)
|
return xerrors.Errorf("checking state invariants: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -170,6 +170,7 @@ var migrationsCmd = &cli.Command{
|
|||||||
newCid2)
|
newCid2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("migration height ", blk.Height-1)
|
||||||
fmt.Println("new cid ", newCid2)
|
fmt.Println("new cid ", newCid2)
|
||||||
fmt.Println("completed premigration 1, took ", preMigration1Time)
|
fmt.Println("completed premigration 1, took ", preMigration1Time)
|
||||||
fmt.Println("completed premigration 2, took ", preMigration2Time)
|
fmt.Println("completed premigration 2, took ", preMigration2Time)
|
||||||
@ -177,7 +178,7 @@ var migrationsCmd = &cli.Command{
|
|||||||
fmt.Println("completed round actual (without cache), took ", uncachedMigrationTime)
|
fmt.Println("completed round actual (without cache), took ", uncachedMigrationTime)
|
||||||
|
|
||||||
if cctx.Bool("check-invariants") {
|
if cctx.Bool("check-invariants") {
|
||||||
err = checkMigrationInvariants(ctx, blk.ParentStateRoot, newCid1, bs, blk.Height-1)
|
err = checkMigrationInvariants(ctx, blk.ParentStateRoot, newCid2, bs, blk.Height-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -187,16 +188,16 @@ var migrationsCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkMigrationInvariants(ctx context.Context, v8StateRoot cid.Cid, v9StateRoot cid.Cid, bs blockstore.Blockstore, epoch abi.ChainEpoch) error {
|
func checkMigrationInvariants(ctx context.Context, v8StateRootCid cid.Cid, v9StateRootCid cid.Cid, bs blockstore.Blockstore, epoch abi.ChainEpoch) error {
|
||||||
actorStore := store.ActorStore(ctx, bs)
|
actorStore := store.ActorStore(ctx, bs)
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
stateTreeV8, err := state.LoadStateTree(actorStore, v8StateRoot)
|
stateTreeV8, err := state.LoadStateTree(actorStore, v8StateRootCid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
stateTreeV9, err := state.LoadStateTree(actorStore, v9StateRoot)
|
stateTreeV9, err := state.LoadStateTree(actorStore, v9StateRootCid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -217,8 +218,8 @@ func checkMigrationInvariants(ctx context.Context, v8StateRoot cid.Cid, v9StateR
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load the state root.
|
// Load the state root.
|
||||||
var stateRoot types.StateRoot
|
var v9stateRoot types.StateRoot
|
||||||
if err := actorStore.Get(ctx, v9StateRoot, &stateRoot); err != nil {
|
if err := actorStore.Get(ctx, v9StateRootCid, &v9stateRoot); err != nil {
|
||||||
return xerrors.Errorf("failed to decode state root: %w", err)
|
return xerrors.Errorf("failed to decode state root: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,8 +228,8 @@ func checkMigrationInvariants(ctx context.Context, v8StateRoot cid.Cid, v9StateR
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
actorTree, err := builtin.LoadTree(actorStore, stateRoot.Actors)
|
v9actorTree, err := builtin.LoadTree(actorStore, v9stateRoot.Actors)
|
||||||
messages, err := v9.CheckStateInvariants(actorTree, epoch, actorCodeCids)
|
messages, err := v9.CheckStateInvariants(v9actorTree, epoch, actorCodeCids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("checking state invariants: %w", err)
|
return xerrors.Errorf("checking state invariants: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user