diff --git a/chain/consensus/filcns/upgrades.go b/chain/consensus/filcns/upgrades.go index 5a268c8a6..617d44fb5 100644 --- a/chain/consensus/filcns/upgrades.go +++ b/chain/consensus/filcns/upgrades.go @@ -240,8 +240,8 @@ func DefaultUpgradeSchedule() stmgr.UpgradeSchedule { Migration: UpgradeActorsV10, PreMigrations: []stmgr.PreMigration{{ PreMigration: PreUpgradeActorsV10, - StartWithin: 180, - DontStartWithin: 60, + StartWithin: 60, + DontStartWithin: 10, StopWithin: 5, }}, Expensive: true, diff --git a/cmd/lotus-shed/migrations.go b/cmd/lotus-shed/migrations.go index a7e0ee34f..8a1007882 100644 --- a/cmd/lotus-shed/migrations.go +++ b/cmd/lotus-shed/migrations.go @@ -17,6 +17,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" actorstypes "github.com/filecoin-project/go-state-types/actors" "github.com/filecoin-project/go-state-types/builtin" + v10 "github.com/filecoin-project/go-state-types/builtin/v10" 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" @@ -151,7 +152,7 @@ var migrationsCmd = &cli.Command{ if !cctx.IsSet("skip-pre-migration") { cache := mutil.NewMemMigrationCache() - ts1, err := cs.GetTipsetByHeight(ctx, blk.Height-240, migrationTs, false) + ts1, err := cs.GetTipsetByHeight(ctx, blk.Height-60, migrationTs, false) if err != nil { return err } @@ -163,21 +164,7 @@ var migrationsCmd = &cli.Command{ return err } - preMigration1Time := time.Since(startTime) - - ts2, err := cs.GetTipsetByHeight(ctx, blk.Height-15, migrationTs, false) - if err != nil { - return err - } - - startTime = time.Now() - - err = preUpgradeActorsFunc(ctx, sm, cache, ts2.ParentState(), ts2.Height()-1, ts2) - if err != nil { - return err - } - - preMigration2Time := time.Since(startTime) + preMigrationTime := time.Since(startTime) startTime = time.Now() @@ -192,8 +179,7 @@ var migrationsCmd = &cli.Command{ return xerrors.Errorf("got different results with and without the cache: %s, %s", newCid1, newCid2) } - fmt.Println("completed premigration 1, took ", preMigration1Time) - fmt.Println("completed premigration 2, took ", preMigration2Time) + fmt.Println("completed premigration, took ", preMigrationTime) fmt.Println("completed round actual (with cache), took ", cachedMigrationTime) } @@ -216,7 +202,7 @@ func getMigrationFuncsForNetwork(nv network.Version) (UpgradeActorsFunc, PreUpgr case network.Version17: return filcns.UpgradeActorsV9, filcns.PreUpgradeActorsV9, checkNv17Invariants, nil case network.Version18: - return filcns.UpgradeActorsV10, filcns.PreUpgradeActorsV10, nil, nil + return filcns.UpgradeActorsV10, filcns.PreUpgradeActorsV10, checkNv18Invariants, nil default: return nil, nil, nil, xerrors.Errorf("migration not implemented for nv%d", nv) } @@ -226,6 +212,40 @@ type UpgradeActorsFunc = func(context.Context, *stmgr.StateManager, stmgr.Migrat type PreUpgradeActorsFunc = func(context.Context, *stmgr.StateManager, stmgr.MigrationCache, cid.Cid, abi.ChainEpoch, *types.TipSet) error type CheckInvariantsFunc = func(context.Context, cid.Cid, cid.Cid, blockstore.Blockstore, abi.ChainEpoch) error +func checkNv18Invariants(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.Version10) + if err != nil { + return err + } + newActorTree, err := builtin.LoadTree(actorStore, newStateRoot.Actors) + if err != nil { + return err + } + messages, err := v10.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 +} + +/// NV17 and earlier stuff + func checkNv17Invariants(ctx context.Context, v8StateRootCid cid.Cid, v9StateRootCid cid.Cid, bs blockstore.Blockstore, epoch abi.ChainEpoch) error { actorStore := store.ActorStore(ctx, bs) startTime := time.Now()