From db2eedebb08254335ebabcbe1c9833cd077acc13 Mon Sep 17 00:00:00 2001 From: Travis Person Date: Wed, 15 Feb 2023 21:07:57 +0000 Subject: [PATCH] feat: stmgr: add env to disable premigrations Setting the environment variable `LOTUS_DISABLE_PRE_MIGRATIONS=1` will discard premigrations for all upgrade. --- chain/stmgr/forks.go | 2 +- chain/stmgr/stmgr.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index d5fe2dd5bb5..b2a5208170f 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -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 } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 325260aa736..92a5285801d 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -2,6 +2,7 @@ package stmgr import ( "context" + "os" "sync" "github.com/ipfs/go-cid" @@ -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 { @@ -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. @@ -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 {