Skip to content

Commit

Permalink
Merge pull request #10283 from filecoin-project/feat/disable-pre-migr…
Browse files Browse the repository at this point in the history
…ations

feat: stmgr: add env to disable premigrations
  • Loading branch information
travisperson authored Feb 21, 2023
2 parents 392d3d4 + 2dcaddf commit bf2ac13
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
10 changes: 10 additions & 0 deletions chain/stmgr/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"bytes"
"context"
"encoding/binary"
"os"
"sort"
"strings"
"sync"
"time"

Expand All @@ -26,6 +28,9 @@ import (
"github.com/filecoin-project/lotus/chain/vm"
)

// EnvDisablePreMigrations when set to '1' stops pre-migrations from running
const EnvDisablePreMigrations = "LOTUS_DISABLE_PRE_MIGRATIONS"

// MigrationCache can be used to cache information used by a migration. This is primarily useful to
// "pre-compute" some migration state ahead of time, and make it accessible in the migration itself.
type MigrationCache interface {
Expand Down Expand Up @@ -218,6 +223,11 @@ func runPreMigration(ctx context.Context, sm *StateManager, fn PreMigrationFunc,
height := ts.Height()
parent := ts.ParentState()

if disabled := os.Getenv(EnvDisablePreMigrations); strings.TrimSpace(disabled) == "1" {
log.Warnw("SKIPPING pre-migration", "height", height)
return
}

startTime := time.Now()

log.Warn("STARTING pre-migration")
Expand Down
68 changes: 68 additions & 0 deletions chain/stmgr/forks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io"
"os"
"sync"
"testing"

Expand Down Expand Up @@ -535,3 +536,70 @@ func TestForkPreMigration(t *testing.T) {
// to this channel.
require.Equal(t, 6, len(counter))
}

func TestDisablePreMigration(t *testing.T) {
logging.SetAllLoggers(logging.LevelInfo)

cg, err := gen.NewGenerator()
require.NoError(t, err)

err = os.Setenv(EnvDisablePreMigrations, "1")
require.NoError(t, err)

defer func() {
err := os.Unsetenv(EnvDisablePreMigrations)
require.NoError(t, err)
}()

counter := make(chan struct{}, 10)

sm, err := NewStateManager(
cg.ChainStore(),
consensus.NewTipSetExecutor(filcns.RewardFunc),
cg.StateManager().VMSys(),
UpgradeSchedule{{
Network: network.Version1,
Height: testForkHeight,
Migration: func(_ context.Context, _ *StateManager, _ MigrationCache, _ ExecMonitor,
root cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) (cid.Cid, error) {

counter <- struct{}{}

return root, nil
},
PreMigrations: []PreMigration{{
StartWithin: 20,
PreMigration: func(ctx context.Context, _ *StateManager, _ MigrationCache,
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
panic("should be skipped")
},
}}},
},
cg.BeaconSchedule(),
)
require.NoError(t, err)
require.NoError(t, sm.Start(context.Background()))
defer func() {
require.NoError(t, sm.Stop(context.Background()))
}()

inv := consensus.NewActorRegistry()
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
inv.Register(actorstypes.Version0, nil, registry)

sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) {
nvm, err := vm.NewLegacyVM(ctx, vmopt)
require.NoError(t, err)
nvm.SetInvoker(inv)
return nvm, nil
})

cg.SetStateManager(sm)

for i := 0; i < 50; i++ {
_, err := cg.NextTipSet()
require.NoError(t, err)
}

require.Equal(t, 1, len(counter))
}

0 comments on commit bf2ac13

Please sign in to comment.