Skip to content

Commit

Permalink
feat: stmgr: add env to disable premigrations
Browse files Browse the repository at this point in the history
Setting the environment variable `LOTUS_DISABLE_PRE_MIGRATIONS=1` will
discard premigrations for all upgrade.
  • Loading branch information
travisperson committed Feb 15, 2023
1 parent 8b3b70d commit db2eede
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chain/stmgr/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (sm *StateManager) HandleStateForks(ctx context.Context, root cid.Cid, heig
u := sm.stateMigrations[height]
if u != nil && u.upgrade != nil {
if migCid, ok := u.migratedStateroots[root]; ok {
log.Warnw("SKIP migration", "height", height, "from", root, "to", migCid)
log.Warnw("CACHED migration", "height", height, "from", root, "to", migCid)
return migCid, nil
}

Expand Down
14 changes: 14 additions & 0 deletions chain/stmgr/stmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package stmgr

import (
"context"
"os"
"sync"

"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -35,6 +36,8 @@ import (
const LookbackNoLimit = api.LookbackNoLimit
const ReceiptAmtBitwidth = 3

const EnvDisablePreMigrations = "LOTUS_DISABLE_PRE_MIGRATIONS"

var log = logging.Logger("statemgr")

type StateManagerAPI interface {
Expand Down Expand Up @@ -114,6 +117,12 @@ func NewStateManager(cs *store.ChainStore, exec Executor, sys vm.SyscallBuilder,
expensiveUpgrades := make(map[abi.ChainEpoch]struct{}, len(us))
var networkVersions []versionSpec
lastVersion := build.GenesisNetworkVersion

disablePreMigrations := false
if disabled := os.Getenv(EnvDisablePreMigrations); disabled == "1" {
disablePreMigrations = true
}

if len(us) > 0 {
// If we have any upgrades, process them and create a version
// schedule.
Expand All @@ -125,6 +134,11 @@ func NewStateManager(cs *store.ChainStore, exec Executor, sys vm.SyscallBuilder,
cache: nv16.NewMemMigrationCache(),
migratedStateroots: make(map[cid.Cid]cid.Cid),
}

if disablePreMigrations {
migration.preMigrations = []PreMigration{}
}

stateMigrations[upgrade.Height] = migration
}
if upgrade.Expensive {
Expand Down

0 comments on commit db2eede

Please sign in to comment.