remove manifest from upgrade schedule, get it inside the migration instead

This commit is contained in:
vyzo 2022-04-12 10:33:38 +03:00
parent 0ac8708396
commit 3b1964c507
4 changed files with 41 additions and 108 deletions

View File

@ -46,194 +46,132 @@ import (
"github.com/filecoin-project/lotus/chain/vm"
)
type LegacyMigrationFunc = func(
ctx context.Context,
sm *stmgr.StateManager, cache stmgr.MigrationCache,
cb stmgr.ExecMonitor,
oldState cid.Cid,
height abi.ChainEpoch, ts *types.TipSet,
) (newState cid.Cid, err error)
type LegacyPreMigrationFunc = func(
ctx context.Context,
sm *stmgr.StateManager, cache stmgr.MigrationCache,
oldState cid.Cid,
height abi.ChainEpoch, ts *types.TipSet,
) error
func LegacyMigration(f LegacyMigrationFunc) stmgr.MigrationFunc {
return func(
ctx context.Context,
sm *stmgr.StateManager, cache stmgr.MigrationCache,
cb stmgr.ExecMonitor,
manifest cid.Cid,
oldState cid.Cid,
height abi.ChainEpoch, ts *types.TipSet,
) (newState cid.Cid, err error) {
return f(ctx, sm, cache, cb, oldState, height, ts)
}
}
func LegacyPreMigration(f LegacyPreMigrationFunc) stmgr.PreMigrationFunc {
return func(
ctx context.Context,
sm *stmgr.StateManager, cache stmgr.MigrationCache,
manifest cid.Cid,
oldState cid.Cid,
height abi.ChainEpoch, ts *types.TipSet,
) error {
return f(ctx, sm, cache, oldState, height, ts)
}
}
func DefaultUpgradeSchedule() stmgr.UpgradeSchedule {
var us stmgr.UpgradeSchedule
v8ManifestCid, ok := actors.GetManifest(actors.Version8)
if !ok {
v8ManifestCid = cid.Undef
}
updates := []stmgr.Upgrade{{
Height: build.UpgradeBreezeHeight,
Network: network.Version1,
Migration: LegacyMigration(UpgradeFaucetBurnRecovery),
Manifest: cid.Undef,
Migration: UpgradeFaucetBurnRecovery,
}, {
Height: build.UpgradeSmokeHeight,
Network: network.Version2,
Migration: nil,
Manifest: cid.Undef,
}, {
Height: build.UpgradeIgnitionHeight,
Network: network.Version3,
Migration: LegacyMigration(UpgradeIgnition),
Manifest: cid.Undef,
Migration: UpgradeIgnition,
}, {
Height: build.UpgradeRefuelHeight,
Network: network.Version3,
Migration: LegacyMigration(UpgradeRefuel),
Manifest: cid.Undef,
Migration: UpgradeRefuel,
}, {
Height: build.UpgradeAssemblyHeight,
Network: network.Version4,
Expensive: true,
Migration: LegacyMigration(UpgradeActorsV2),
Manifest: cid.Undef,
Migration: UpgradeActorsV2,
}, {
Height: build.UpgradeTapeHeight,
Network: network.Version5,
Migration: nil,
Manifest: cid.Undef,
}, {
Height: build.UpgradeLiftoffHeight,
Network: network.Version5,
Migration: LegacyMigration(UpgradeLiftoff),
Manifest: cid.Undef,
Migration: UpgradeLiftoff,
}, {
Height: build.UpgradeKumquatHeight,
Network: network.Version6,
Migration: nil,
Manifest: cid.Undef,
}, {
Height: build.UpgradeCalicoHeight,
Network: network.Version7,
Migration: LegacyMigration(UpgradeCalico),
Manifest: cid.Undef,
Migration: UpgradeCalico,
}, {
Height: build.UpgradePersianHeight,
Network: network.Version8,
Migration: nil,
Manifest: cid.Undef,
}, {
Height: build.UpgradeOrangeHeight,
Network: network.Version9,
Migration: nil,
Manifest: cid.Undef,
}, {
Height: build.UpgradeTrustHeight,
Network: network.Version10,
Migration: LegacyMigration(UpgradeActorsV3),
Migration: UpgradeActorsV3,
PreMigrations: []stmgr.PreMigration{{
PreMigration: LegacyPreMigration(PreUpgradeActorsV3),
PreMigration: PreUpgradeActorsV3,
StartWithin: 120,
DontStartWithin: 60,
StopWithin: 35,
}, {
PreMigration: LegacyPreMigration(PreUpgradeActorsV3),
PreMigration: PreUpgradeActorsV3,
StartWithin: 30,
DontStartWithin: 15,
StopWithin: 5,
}},
Manifest: cid.Undef,
Expensive: true,
}, {
Height: build.UpgradeNorwegianHeight,
Network: network.Version11,
Migration: nil,
Manifest: cid.Undef,
}, {
Height: build.UpgradeTurboHeight,
Network: network.Version12,
Migration: LegacyMigration(UpgradeActorsV4),
Migration: UpgradeActorsV4,
PreMigrations: []stmgr.PreMigration{{
PreMigration: LegacyPreMigration(PreUpgradeActorsV4),
PreMigration: PreUpgradeActorsV4,
StartWithin: 120,
DontStartWithin: 60,
StopWithin: 35,
}, {
PreMigration: LegacyPreMigration(PreUpgradeActorsV4),
PreMigration: PreUpgradeActorsV4,
StartWithin: 30,
DontStartWithin: 15,
StopWithin: 5,
}},
Manifest: cid.Undef,
Expensive: true,
}, {
Height: build.UpgradeHyperdriveHeight,
Network: network.Version13,
Migration: LegacyMigration(UpgradeActorsV5),
Migration: UpgradeActorsV5,
PreMigrations: []stmgr.PreMigration{{
PreMigration: LegacyPreMigration(PreUpgradeActorsV5),
PreMigration: PreUpgradeActorsV5,
StartWithin: 120,
DontStartWithin: 60,
StopWithin: 35,
}, {
PreMigration: LegacyPreMigration(PreUpgradeActorsV5),
PreMigration: PreUpgradeActorsV5,
StartWithin: 30,
DontStartWithin: 15,
StopWithin: 5,
}},
Manifest: cid.Undef,
Expensive: true,
}, {
Height: build.UpgradeChocolateHeight,
Network: network.Version14,
Migration: LegacyMigration(UpgradeActorsV6),
Migration: UpgradeActorsV6,
PreMigrations: []stmgr.PreMigration{{
PreMigration: LegacyPreMigration(PreUpgradeActorsV6),
PreMigration: PreUpgradeActorsV6,
StartWithin: 120,
DontStartWithin: 60,
StopWithin: 35,
}, {
PreMigration: LegacyPreMigration(PreUpgradeActorsV6),
PreMigration: PreUpgradeActorsV6,
StartWithin: 30,
DontStartWithin: 15,
StopWithin: 5,
}},
Manifest: cid.Undef,
Expensive: true,
}, {
Height: build.UpgradeOhSnapHeight,
Network: network.Version15,
Migration: LegacyMigration(UpgradeActorsV7),
Migration: UpgradeActorsV7,
PreMigrations: []stmgr.PreMigration{{
PreMigration: LegacyPreMigration(PreUpgradeActorsV7),
PreMigration: PreUpgradeActorsV7,
StartWithin: 180,
DontStartWithin: 60,
StopWithin: 5,
}},
Manifest: cid.Undef,
Expensive: true,
}, {
Height: build.UpgradeFVM1Height,
@ -245,7 +183,6 @@ func DefaultUpgradeSchedule() stmgr.UpgradeSchedule {
DontStartWithin: 60,
StopWithin: 5,
}},
Manifest: v8ManifestCid,
Expensive: true,
},
}
@ -1381,7 +1318,7 @@ func upgradeActorsV7Common(
return newRoot, nil
}
func UpgradeActorsV8(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, cb stmgr.ExecMonitor, manifest cid.Cid, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
func UpgradeActorsV8(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, cb stmgr.ExecMonitor, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
// Use all the CPUs except 3.
workerCount := runtime.NumCPU() - 3
if workerCount <= 0 {
@ -1395,7 +1332,7 @@ func UpgradeActorsV8(ctx context.Context, sm *stmgr.StateManager, cache stmgr.Mi
ProgressLogPeriod: 10 * time.Second,
}
newRoot, err := upgradeActorsV8Common(ctx, sm, cache, manifest, root, epoch, ts, config)
newRoot, err := upgradeActorsV8Common(ctx, sm, cache, root, epoch, ts, config)
if err != nil {
return cid.Undef, xerrors.Errorf("migrating actors v6 state: %w", err)
}
@ -1403,7 +1340,7 @@ func UpgradeActorsV8(ctx context.Context, sm *stmgr.StateManager, cache stmgr.Mi
return newRoot, nil
}
func PreUpgradeActorsV8(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, manifest cid.Cid, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) error {
func PreUpgradeActorsV8(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) error {
// Use half the CPUs for pre-migration, but leave at least 3.
workerCount := runtime.NumCPU()
if workerCount <= 4 {
@ -1420,13 +1357,12 @@ func PreUpgradeActorsV8(ctx context.Context, sm *stmgr.StateManager, cache stmgr
config := nv16.Config{MaxWorkers: uint(workerCount),
ProgressLogPeriod: time.Minute * 5}
_, err = upgradeActorsV8Common(ctx, sm, cache, manifest, lbRoot, epoch, lbts, config)
_, err = upgradeActorsV8Common(ctx, sm, cache, lbRoot, epoch, lbts, config)
return err
}
func upgradeActorsV8Common(
ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache,
manifest cid.Cid,
root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet,
config nv16.Config,
) (cid.Cid, error) {
@ -1446,6 +1382,11 @@ func upgradeActorsV8Common(
)
}
manifest, ok := actors.GetManifest(actors.Version8)
if !ok {
return cid.Undef, xerrors.Errorf("no manifest CID for v8 upgrade")
}
// Perform the migration
newHamtRoot, err := nv16.MigrateStateTree(ctx, store, manifest, stateRoot.Actors, epoch, config, migrationLogger{}, cache)
if err != nil {

View File

@ -48,7 +48,6 @@ type MigrationFunc func(
ctx context.Context,
sm *StateManager, cache MigrationCache,
cb ExecMonitor,
manifest cid.Cid,
oldState cid.Cid,
height abi.ChainEpoch, ts *types.TipSet,
) (newState cid.Cid, err error)
@ -58,7 +57,6 @@ type MigrationFunc func(
type PreMigrationFunc func(
ctx context.Context,
sm *StateManager, cache MigrationCache,
manifest cid.Cid,
oldState cid.Cid,
height abi.ChainEpoch, ts *types.TipSet,
) error
@ -95,10 +93,6 @@ type Upgrade struct {
// These functions should fill the given cache with information that can speed up the
// eventual full migration at the upgrade epoch.
PreMigrations []PreMigration
// Manifest is the migration manifest CID, starting with nv16; for older migrations it is
// undefined
Manifest cid.Cid
}
type UpgradeSchedule []Upgrade
@ -182,7 +176,7 @@ func (sm *StateManager) HandleStateForks(ctx context.Context, root cid.Cid, heig
// Yes, we clone the cache, even for the final upgrade epoch. Why? Reverts. We may
// have to migrate multiple times.
tmpCache := u.cache.Clone()
retCid, err = u.upgrade(ctx, sm, tmpCache, cb, u.manifest, root, height, ts)
retCid, err = u.upgrade(ctx, sm, tmpCache, cb, root, height, ts)
if err != nil {
log.Errorw("FAILED migration", "height", height, "from", root, "error", err)
return cid.Undef, err
@ -219,7 +213,7 @@ func (sm *StateManager) hasExpensiveFork(height abi.ChainEpoch) bool {
return ok
}
func runPreMigration(ctx context.Context, sm *StateManager, manifest cid.Cid, fn PreMigrationFunc, cache *nv16.MemMigrationCache, ts *types.TipSet) {
func runPreMigration(ctx context.Context, sm *StateManager, fn PreMigrationFunc, cache *nv16.MemMigrationCache, ts *types.TipSet) {
height := ts.Height()
parent := ts.ParentState()
@ -231,7 +225,7 @@ func runPreMigration(ctx context.Context, sm *StateManager, manifest cid.Cid, fn
// migration to use the cache may assume that
// certain blocks exist, even if they don't.
tmpCache := cache.Clone()
err := fn(ctx, sm, tmpCache, manifest, parent, height, ts)
err := fn(ctx, sm, tmpCache, parent, height, ts)
if err != nil {
log.Errorw("FAILED pre-migration", "error", err)
return
@ -272,7 +266,6 @@ func (sm *StateManager) preMigrationWorker(ctx context.Context) {
notAfterEpoch = stopEpoch - 1
}
manifest := migration.manifest
// Add an op to start a pre-migration.
schedule = append(schedule, op{
after: afterEpoch,
@ -283,7 +276,7 @@ func (sm *StateManager) preMigrationWorker(ctx context.Context) {
wg.Add(1)
go func() {
defer wg.Done()
runPreMigration(preCtx, sm, manifest, migrationFunc, cache, ts)
runPreMigration(preCtx, sm, migrationFunc, cache, ts)
}()
},
})

View File

@ -130,7 +130,7 @@ func TestForkHeightTriggers(t *testing.T) {
Network: network.Version1,
Height: testForkHeight,
Migration: func(ctx context.Context, sm *StateManager, cache MigrationCache, cb ExecMonitor,
_ cid.Cid, root cid.Cid, height abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
root cid.Cid, height abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
cst := ipldcbor.NewCborStore(sm.ChainStore().StateBlockstore())
st, err := sm.StateTree(root)
@ -276,7 +276,7 @@ func testForkRefuseCall(t *testing.T, nullsBefore, nullsAfter int) {
Expensive: true,
Height: testForkHeight,
Migration: func(ctx context.Context, sm *StateManager, cache MigrationCache, cb ExecMonitor,
_ cid.Cid, root cid.Cid, height abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
root cid.Cid, height abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
migrationCount++
return root, nil
}}}, cg.BeaconSchedule())
@ -412,7 +412,7 @@ func TestForkPreMigration(t *testing.T) {
Network: network.Version1,
Height: testForkHeight,
Migration: func(ctx context.Context, sm *StateManager, cache MigrationCache, cb ExecMonitor,
_ cid.Cid, root cid.Cid, height abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
root cid.Cid, height abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) {
// Make sure the test that should be canceled, is canceled.
select {
@ -431,7 +431,7 @@ func TestForkPreMigration(t *testing.T) {
PreMigrations: []PreMigration{{
StartWithin: 20,
PreMigration: func(ctx context.Context, _ *StateManager, cache MigrationCache,
_ cid.Cid, _ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
wait20.Done()
wait20.Wait()
@ -445,7 +445,7 @@ func TestForkPreMigration(t *testing.T) {
}, {
StartWithin: 20,
PreMigration: func(ctx context.Context, _ *StateManager, cache MigrationCache,
_ cid.Cid, _ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
wait20.Done()
wait20.Wait()
@ -459,7 +459,7 @@ func TestForkPreMigration(t *testing.T) {
}, {
StartWithin: 20,
PreMigration: func(ctx context.Context, _ *StateManager, cache MigrationCache,
_ cid.Cid, _ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
wait20.Done()
wait20.Wait()
@ -475,7 +475,7 @@ func TestForkPreMigration(t *testing.T) {
StartWithin: 15,
StopWithin: 5,
PreMigration: func(ctx context.Context, _ *StateManager, cache MigrationCache,
_ cid.Cid, _ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
<-ctx.Done()
close(wasCanceled)
@ -487,7 +487,7 @@ func TestForkPreMigration(t *testing.T) {
}, {
StartWithin: 10,
PreMigration: func(ctx context.Context, _ *StateManager, cache MigrationCache,
_ cid.Cid, _ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
_ cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) error {
checkCache(t, cache)

View File

@ -124,7 +124,6 @@ func NewStateManager(cs *store.ChainStore, exec Executor, sys vm.SyscallBuilder,
upgrade: upgrade.Migration,
preMigrations: upgrade.PreMigrations,
cache: nv16.NewMemMigrationCache(),
manifest: upgrade.Manifest,
}
stateMigrations[upgrade.Height] = migration
}