Skip to content

Commit

Permalink
fixup! feat: stmgr: add env to disable premigrations
Browse files Browse the repository at this point in the history
  • Loading branch information
travisperson committed Feb 16, 2023
1 parent 0930ff2 commit b379b47
Show file tree
Hide file tree
Showing 2 changed files with 67 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 @@ -224,7 +224,7 @@ func runPreMigration(ctx context.Context, sm *StateManager, fn PreMigrationFunc,
parent := ts.ParentState()

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

Expand Down
66 changes: 66 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,68 @@ 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)

os.Setenv(EnvDisablePreMigrations, "1")
defer func() {
os.Unsetenv(EnvDisablePreMigrations)
}()

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")
return nil
},
}}},
},
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 b379b47

Please sign in to comment.