Skip to content

Commit a1102e4

Browse files
authored
feat(shed): migrate-state tock-fix (#13014)
some special strings will be able to run non-numbered migrations, starting with "tock-fix"
1 parent 98c4d30 commit a1102e4

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

cmd/lotus-shed/migrations.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import (
7777
var migrationsCmd = &cli.Command{
7878
Name: "migrate-state",
7979
Description: "Run a network upgrade migration",
80-
ArgsUsage: "[new network version, block to look back from]",
80+
ArgsUsage: `<network version or fix specifier (e.g. "tock-fix")> <CID of block to look back from>`,
8181
Flags: []cli.Flag{
8282
&cli.StringFlag{
8383
Name: "repo",
@@ -101,14 +101,25 @@ var migrationsCmd = &cli.Command{
101101
return lcli.IncorrectNumArgs(cctx)
102102
}
103103

104-
nv, err := strconv.ParseUint(cctx.Args().Get(0), 10, 32)
105-
if err != nil {
106-
return fmt.Errorf("failed to parse network version: %w", err)
107-
}
104+
var (
105+
nv network.Version
106+
upgradeActorsFunc UpgradeActorsFunc
107+
preUpgradeActorsFunc PreUpgradeActorsFunc
108+
checkInvariantsFunc CheckInvariantsFunc
109+
)
108110

109-
upgradeActorsFunc, preUpgradeActorsFunc, checkInvariantsFunc, err := getMigrationFuncsForNetwork(network.Version(nv))
110-
if err != nil {
111-
return err
111+
if nvi, err := strconv.ParseUint(cctx.Args().Get(0), 10, 32); err != nil {
112+
// not a specific network version number, treat it as a string and check predefined strings
113+
nv, upgradeActorsFunc, preUpgradeActorsFunc, checkInvariantsFunc, err = getMigrationFuncsForString(cctx.Args().Get(0))
114+
if err != nil {
115+
return fmt.Errorf("failed to parse network version or string: %w", err)
116+
}
117+
} else {
118+
nv = network.Version(nvi)
119+
upgradeActorsFunc, preUpgradeActorsFunc, checkInvariantsFunc, err = getMigrationFuncsForNetwork(nv)
120+
if err != nil {
121+
return err
122+
}
112123
}
113124

114125
blkCid, err := cid.Decode(cctx.Args().Get(1))
@@ -123,7 +134,7 @@ var migrationsCmd = &cli.Command{
123134

124135
lkrepo, err := fsrepo.Lock(repo.FullNode)
125136
if err != nil {
126-
return err
137+
return xerrors.Errorf("failed to lock repo: %w", err)
127138
}
128139

129140
defer lkrepo.Close() //nolint:errcheck
@@ -208,7 +219,7 @@ var migrationsCmd = &cli.Command{
208219
fmt.Println("new cid ", newCid2)
209220
fmt.Println("completed round actual (without cache), took ", uncachedMigrationTime)
210221

211-
if !cctx.IsSet("skip-pre-migration") {
222+
if !cctx.IsSet("skip-pre-migration") && preUpgradeActorsFunc != nil {
212223
cache := mutil.NewMemMigrationCache()
213224

214225
ts1, err := cs.GetTipsetByHeight(ctx, blk.Height-60, migrationTs, false)
@@ -237,7 +248,7 @@ var migrationsCmd = &cli.Command{
237248

238249
if newCid1 != newCid2 {
239250
{
240-
if err := printStateDiff(ctx, network.Version(nv), newCid2, newCid1, bs); err != nil {
251+
if err := printStateDiff(ctx, nv, newCid2, newCid1, bs); err != nil {
241252
fmt.Println("failed to print state diff: ", err)
242253
}
243254
}
@@ -266,6 +277,8 @@ var migrationsCmd = &cli.Command{
266277
}
267278

268279
fmt.Println("completed round actual (with cache), took ", cachedMigrationTime)
280+
} else if !cctx.IsSet("skip-pre-migration") {
281+
fmt.Println("skipping pre-migration, no pre-migration function")
269282
}
270283

271284
if cctx.Bool("check-invariants") {
@@ -305,6 +318,15 @@ func getMigrationFuncsForNetwork(nv network.Version) (UpgradeActorsFunc, PreUpgr
305318
}
306319
}
307320

321+
func getMigrationFuncsForString(input string) (network.Version, UpgradeActorsFunc, PreUpgradeActorsFunc, CheckInvariantsFunc, error) {
322+
switch input {
323+
case "tock-fix":
324+
return network.Version27, filcns.UpgradeActorsV16Fix, nil, checkNv25Invariants, nil
325+
default:
326+
return 0, nil, nil, nil, xerrors.Errorf("migration not implemented for string: %s", input)
327+
}
328+
}
329+
308330
type UpgradeActorsFunc = func(context.Context, *stmgr.StateManager, stmgr.MigrationCache, stmgr.ExecMonitor, cid.Cid, abi.ChainEpoch, *types.TipSet) (cid.Cid, error)
309331
type PreUpgradeActorsFunc = func(context.Context, *stmgr.StateManager, stmgr.MigrationCache, cid.Cid, abi.ChainEpoch, *types.TipSet) error
310332
type CheckInvariantsFunc = func(context.Context, cid.Cid, cid.Cid, blockstore.Blockstore, abi.ChainEpoch) error

0 commit comments

Comments
 (0)