From 71e7909f7dcfd2622616fa318a71210c94cb51f8 Mon Sep 17 00:00:00 2001 From: Phi Date: Mon, 11 Nov 2024 16:12:26 +0700 Subject: [PATCH] chore: delete migration specific for nv24 chore: delete migration specific for nv24 --- builtin/v16/migration/power.go | 71 ------------- builtin/v16/migration/power_test.go | 88 ---------------- builtin/v16/migration/system.go | 40 -------- builtin/v16/migration/top.go | 151 ---------------------------- 4 files changed, 350 deletions(-) delete mode 100644 builtin/v16/migration/power.go delete mode 100644 builtin/v16/migration/power_test.go delete mode 100644 builtin/v16/migration/system.go delete mode 100644 builtin/v16/migration/top.go diff --git a/builtin/v16/migration/power.go b/builtin/v16/migration/power.go deleted file mode 100644 index e1168f33..00000000 --- a/builtin/v16/migration/power.go +++ /dev/null @@ -1,71 +0,0 @@ -package migration - -import ( - "context" - - power14 "github.com/filecoin-project/go-state-types/builtin/v14/power" - power15 "github.com/filecoin-project/go-state-types/builtin/v16/power" - smoothing15 "github.com/filecoin-project/go-state-types/builtin/v16/util/smoothing" - "github.com/filecoin-project/go-state-types/migration" - "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - "golang.org/x/xerrors" -) - -type powerMigrator struct { - rampStartEpoch int64 - rampDurationEpochs uint64 - outCodeCID cid.Cid -} - -func newPowerMigrator(rampStartEpoch int64, rampDurationEpochs uint64, outCode cid.Cid) (*powerMigrator, error) { - return &powerMigrator{ - rampStartEpoch: rampStartEpoch, - rampDurationEpochs: rampDurationEpochs, - outCodeCID: outCode, - }, nil -} - -func (p powerMigrator) MigratedCodeCID() cid.Cid { return p.outCodeCID } - -func (p powerMigrator) Deferred() bool { return false } - -func (p powerMigrator) MigrateState(ctx context.Context, store cbor.IpldStore, in migration.ActorMigrationInput) (*migration.ActorMigrationResult, error) { - var inState power14.State - if err := store.Get(ctx, in.Head, &inState); err != nil { - return nil, xerrors.Errorf("failed to load miner state for %s: %w", in.Address, err) - } - - outState := power15.State{ - TotalRawBytePower: inState.TotalRawBytePower, - TotalBytesCommitted: inState.TotalBytesCommitted, - TotalQualityAdjPower: inState.TotalQualityAdjPower, - TotalQABytesCommitted: inState.TotalQABytesCommitted, - TotalPledgeCollateral: inState.TotalPledgeCollateral, - ThisEpochRawBytePower: inState.ThisEpochRawBytePower, - ThisEpochQualityAdjPower: inState.ThisEpochQualityAdjPower, - ThisEpochPledgeCollateral: inState.ThisEpochPledgeCollateral, - ThisEpochQAPowerSmoothed: smoothing15.FilterEstimate{ - PositionEstimate: inState.ThisEpochQAPowerSmoothed.PositionEstimate, - VelocityEstimate: inState.ThisEpochQAPowerSmoothed.VelocityEstimate, - }, - MinerCount: inState.MinerCount, - MinerAboveMinPowerCount: inState.MinerAboveMinPowerCount, - RampStartEpoch: p.rampStartEpoch, - RampDurationEpochs: p.rampDurationEpochs, - CronEventQueue: inState.CronEventQueue, - FirstCronEpoch: inState.FirstCronEpoch, - Claims: inState.Claims, - ProofValidationBatch: inState.ProofValidationBatch, - } - - newHead, err := store.Put(ctx, &outState) - if err != nil { - return nil, xerrors.Errorf("failed to put new state: %w", err) - } - - return &migration.ActorMigrationResult{ - NewCodeCID: p.MigratedCodeCID(), - NewHead: newHead, - }, nil -} diff --git a/builtin/v16/migration/power_test.go b/builtin/v16/migration/power_test.go deleted file mode 100644 index 7cfc2003..00000000 --- a/builtin/v16/migration/power_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package migration - -import ( - "context" - "testing" - "time" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - power14 "github.com/filecoin-project/go-state-types/builtin/v14/power" - smoothing14 "github.com/filecoin-project/go-state-types/builtin/v14/util/smoothing" - power15 "github.com/filecoin-project/go-state-types/builtin/v16/power" - "github.com/filecoin-project/go-state-types/migration" - "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - "github.com/stretchr/testify/require" -) - -func TestPowerMigration(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) - defer cancel() - - req := require.New(t) - - cst := cbor.NewMemCborStore() - - pvb := cid.MustParse("bafy2bzacaf2a") - state14 := power14.State{ - TotalRawBytePower: abi.NewStoragePower(101), - TotalBytesCommitted: abi.NewStoragePower(102), - TotalQualityAdjPower: abi.NewStoragePower(103), - TotalQABytesCommitted: abi.NewStoragePower(104), - TotalPledgeCollateral: abi.NewTokenAmount(105), - ThisEpochRawBytePower: abi.NewStoragePower(106), - ThisEpochQualityAdjPower: abi.NewStoragePower(107), - ThisEpochPledgeCollateral: abi.NewTokenAmount(108), - ThisEpochQAPowerSmoothed: smoothing14.NewEstimate(big.NewInt(109), big.NewInt(110)), - MinerCount: 111, - MinerAboveMinPowerCount: 112, - CronEventQueue: cid.MustParse("bafy2bzacafza"), - FirstCronEpoch: 113, - Claims: cid.MustParse("bafy2bzacafzq"), - ProofValidationBatch: &pvb, - } - - state14Cid, err := cst.Put(ctx, &state14) - req.NoError(err) - - var rampStartEpoch int64 = 101 - var rampDurationEpochs uint64 = 202 - - migrator, err := newPowerMigrator(rampStartEpoch, rampDurationEpochs, cid.MustParse("bafy2bzaca4aaaaaaaaaqk")) - req.NoError(err) - - result, err := migrator.MigrateState(ctx, cst, migration.ActorMigrationInput{ - Address: address.TestAddress, - Head: state14Cid, - Cache: nil, - }) - req.NoError(err) - req.Equal(cid.MustParse("bafy2bzaca4aaaaaaaaaqk"), result.NewCodeCID) - req.NotEqual(cid.Undef, result.NewHead) - - newState := power15.State{} - req.NoError(cst.Get(ctx, result.NewHead, &newState)) - - req.Equal(state14.TotalRawBytePower, newState.TotalRawBytePower) - req.Equal(state14.TotalBytesCommitted, newState.TotalBytesCommitted) - req.Equal(state14.TotalQualityAdjPower, newState.TotalQualityAdjPower) - req.Equal(state14.TotalQABytesCommitted, newState.TotalQABytesCommitted) - req.Equal(state14.TotalPledgeCollateral, newState.TotalPledgeCollateral) - req.Equal(state14.ThisEpochRawBytePower, newState.ThisEpochRawBytePower) - req.Equal(state14.ThisEpochQualityAdjPower, newState.ThisEpochQualityAdjPower) - req.Equal(state14.ThisEpochPledgeCollateral, newState.ThisEpochPledgeCollateral) - req.Equal(state14.ThisEpochQAPowerSmoothed.PositionEstimate, newState.ThisEpochQAPowerSmoothed.PositionEstimate) - req.Equal(state14.ThisEpochQAPowerSmoothed.VelocityEstimate, newState.ThisEpochQAPowerSmoothed.VelocityEstimate) - req.Equal(state14.MinerCount, newState.MinerCount) - req.Equal(state14.MinerAboveMinPowerCount, newState.MinerAboveMinPowerCount) - req.Equal(state14.CronEventQueue, newState.CronEventQueue) - req.Equal(state14.FirstCronEpoch, newState.FirstCronEpoch) - req.Equal(state14.Claims, newState.Claims) - req.Equal(state14.ProofValidationBatch, newState.ProofValidationBatch) - - // Ramp parameters - req.Equal(rampStartEpoch, newState.RampStartEpoch) - req.Equal(rampDurationEpochs, newState.RampDurationEpochs) -} diff --git a/builtin/v16/migration/system.go b/builtin/v16/migration/system.go deleted file mode 100644 index 9eb57fdf..00000000 --- a/builtin/v16/migration/system.go +++ /dev/null @@ -1,40 +0,0 @@ -package migration - -import ( - "context" - - system15 "github.com/filecoin-project/go-state-types/builtin/v16/system" - - "github.com/filecoin-project/go-state-types/migration" - - "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" -) - -// System Actor migrator -type systemActorMigrator struct { - OutCodeCID cid.Cid - ManifestData cid.Cid -} - -func (m systemActorMigrator) MigratedCodeCID() cid.Cid { - return m.OutCodeCID -} - -func (m systemActorMigrator) MigrateState(ctx context.Context, store cbor.IpldStore, in migration.ActorMigrationInput) (*migration.ActorMigrationResult, error) { - // The ManifestData itself is already in the blockstore - state := system15.State{BuiltinActors: m.ManifestData} - stateHead, err := store.Put(ctx, &state) - if err != nil { - return nil, err - } - - return &migration.ActorMigrationResult{ - NewCodeCID: m.OutCodeCID, - NewHead: stateHead, - }, nil -} - -func (m systemActorMigrator) Deferred() bool { - return false -} diff --git a/builtin/v16/migration/top.go b/builtin/v16/migration/top.go deleted file mode 100644 index a1db55f9..00000000 --- a/builtin/v16/migration/top.go +++ /dev/null @@ -1,151 +0,0 @@ -package migration - -import ( - "context" - - adt15 "github.com/filecoin-project/go-state-types/builtin/v16/util/adt" - - system14 "github.com/filecoin-project/go-state-types/builtin/v14/system" - - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/builtin" - "github.com/filecoin-project/go-state-types/manifest" - "github.com/filecoin-project/go-state-types/migration" - - "github.com/ipfs/go-cid" - cbor "github.com/ipfs/go-ipld-cbor" - "golang.org/x/xerrors" -) - -// MigrateStateTree migrates the Filecoin state tree starting from the global state tree and upgrading all actor states. -// The store must support concurrent writes (even if the configured worker count is 1). -// -// FIP-0081 constants for the power actor state for pledge calculations that apply only to this migration: -// -// - powerRampStartEpoch: Epoch at which the new pledge calculation starts. -// - powerRampDurationEpochs: Number of epochs over which the new pledge calculation is ramped up. -func MigrateStateTree( - ctx context.Context, - store cbor.IpldStore, - newManifestCID cid.Cid, - actorsRootIn cid.Cid, - priorEpoch abi.ChainEpoch, - powerRampStartEpoch int64, - powerRampDurationEpochs uint64, - cfg migration.Config, - log migration.Logger, - cache migration.MigrationCache, -) (cid.Cid, error) { - if cfg.MaxWorkers <= 0 { - return cid.Undef, xerrors.Errorf("invalid migration config with %d workers", cfg.MaxWorkers) - } - - if powerRampStartEpoch == 0 { - return cid.Undef, xerrors.Errorf("powerRampStartEpoch must be non-zero") - } - if powerRampStartEpoch < 0 { - return cid.Undef, xerrors.Errorf("powerRampStartEpoch must be non-negative") - } - if powerRampDurationEpochs == 0 { - return cid.Undef, xerrors.Errorf("powerRampDurationEpochs must be non-zero") - } - - adtStore := adt15.WrapStore(ctx, store) - - // Load input and output state trees - actorsIn, err := builtin.LoadTree(adtStore, actorsRootIn) - if err != nil { - return cid.Undef, xerrors.Errorf("loading state tree: %w", err) - } - - // load old manifest data - systemActor, ok, err := actorsIn.GetActorV5(builtin.SystemActorAddr) - if err != nil { - return cid.Undef, xerrors.Errorf("failed to get system actor: %w", err) - } - - if !ok { - return cid.Undef, xerrors.New("didn't find system actor") - } - - var systemState system14.State - if err := store.Get(ctx, systemActor.Head, &systemState); err != nil { - return cid.Undef, xerrors.Errorf("failed to get system actor state: %w", err) - } - - var oldManifestData manifest.ManifestData - if err := store.Get(ctx, systemState.BuiltinActors, &oldManifestData); err != nil { - return cid.Undef, xerrors.Errorf("failed to get old manifest data: %w", err) - } - - // load new manifest - var newManifest manifest.Manifest - if err := adtStore.Get(ctx, newManifestCID, &newManifest); err != nil { - return cid.Undef, xerrors.Errorf("error reading actor manifest: %w", err) - } - - if err := newManifest.Load(ctx, adtStore); err != nil { - return cid.Undef, xerrors.Errorf("error loading actor manifest: %w", err) - } - - // Maps prior version code CIDs to migration functions. - migrations := make(map[cid.Cid]migration.ActorMigration) - // Set of prior version code CIDs for actors to defer during iteration, for explicit migration afterwards. - deferredCodeIDs := make(map[cid.Cid]struct{}) - - power14Cid := cid.Undef - - for _, oldEntry := range oldManifestData.Entries { - if oldEntry.Name == manifest.PowerKey { - power14Cid = oldEntry.Code - } - - newCodeCID, ok := newManifest.Get(oldEntry.Name) - if !ok { - return cid.Undef, xerrors.Errorf("code cid for %s actor not found in new manifest", oldEntry.Name) - } - migrations[oldEntry.Code] = migration.CodeMigrator{OutCodeCID: newCodeCID} - } - - // migrations that migrate both code and state, override entries in `migrations` - - // The System Actor - - newSystemCodeCID, ok := newManifest.Get(manifest.SystemKey) - if !ok { - return cid.Undef, xerrors.Errorf("code cid for system actor not found in new manifest") - } - - migrations[systemActor.Code] = systemActorMigrator{OutCodeCID: newSystemCodeCID, ManifestData: newManifest.Data} - - // The Power Actor - if power14Cid == cid.Undef { - return cid.Undef, xerrors.Errorf("code cid for power actor not found in old manifest") - } - power15Cid, ok := newManifest.Get(manifest.PowerKey) - if !ok { - return cid.Undef, xerrors.Errorf("code cid for power actor not found in new manifest") - } - - pm, err := newPowerMigrator(powerRampStartEpoch, powerRampDurationEpochs, power15Cid) - if err != nil { - return cid.Undef, xerrors.Errorf("failed to create miner migrator: %w", err) - } - migrations[power14Cid] = *pm - - if len(migrations)+len(deferredCodeIDs) != len(oldManifestData.Entries) { - return cid.Undef, xerrors.Errorf("incomplete migration specification with %d code CIDs, need %d", len(migrations)+len(deferredCodeIDs), len(oldManifestData.Entries)) - } - - actorsOut, err := migration.RunMigration(ctx, cfg, cache, store, log, actorsIn, migrations) - if err != nil { - return cid.Undef, xerrors.Errorf("failed to run migration: %w", err) - } - - outCid, err := actorsOut.Flush() - if err != nil { - return cid.Undef, xerrors.Errorf("failed to flush actorsOut: %w", err) - } - - return outCid, nil -}