Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions builtin/v16/migration/miner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package migration

import (
"context"

"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
xerrors "golang.org/x/xerrors"

miner15 "github.com/filecoin-project/go-state-types/builtin/v15/miner"
miner16 "github.com/filecoin-project/go-state-types/builtin/v16/miner"
"github.com/filecoin-project/go-state-types/migration"
)

// minerMigrator performs the migration for the Miner contract state.
type minerMigrator struct {
OutCodeCID cid.Cid
}

func (m minerMigrator) MigratedCodeCID() cid.Cid {
return m.OutCodeCID
}

func (m minerMigrator) MigrateState(ctx context.Context, store cbor.IpldStore, in migration.ActorMigrationInput) (*migration.ActorMigrationResult, error) {
// Load the existing state (v15).
var inState miner15.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)
}

// Create the new state (v16) with VestingFunds set to nil.
outState := miner16.State{
Info: inState.Info,
PreCommitDeposits: inState.PreCommitDeposits,
LockedFunds: inState.LockedFunds,
VestingFunds: inState.VestingFunds,
FeeDebt: inState.FeeDebt,
InitialPledge: inState.InitialPledge,
PreCommittedSectors: inState.PreCommittedSectors,
PreCommittedSectorsCleanUp: inState.PreCommittedSectorsCleanUp,
AllocatedSectors: inState.AllocatedSectors,
Sectors: inState.Sectors,
ProvingPeriodStart: inState.ProvingPeriodStart,
CurrentDeadline: inState.CurrentDeadline,
Deadlines: inState.Deadlines,
EarlyTerminations: inState.EarlyTerminations,
DeadlineCronActive: inState.DeadlineCronActive,
}

// Store the new state.
newHead, err := store.Put(ctx, &outState)
if err != nil {
return nil, xerrors.Errorf("failed to put new evm state: %w", err)
}

return &migration.ActorMigrationResult{
NewCodeCID: m.MigratedCodeCID(),
NewHead: newHead,
}, nil
}

func (m minerMigrator) Deferred() bool {
return false
}
13 changes: 13 additions & 0 deletions builtin/v16/migration/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ func MigrateStateTree(ctx context.Context, store cbor.IpldStore, newManifestCID
deferredCodeIDs := make(map[cid.Cid]struct{})

evm15Cid := cid.Undef
miner15Cid := cid.Undef

for _, oldEntry := range oldManifestData.Entries {
if oldEntry.Name == manifest.EvmKey {
evm15Cid = oldEntry.Code
}
if oldEntry.Name == manifest.MinerKey {
miner15Cid = 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)
Expand Down Expand Up @@ -103,6 +107,15 @@ func MigrateStateTree(ctx context.Context, store cbor.IpldStore, newManifestCID

migrations[evm15Cid] = migration.CachedMigration(cache, evmMigrator{newEvmCodeCID})

// The Miner Actor

newMinerCodeCID, ok := newManifest.Get(manifest.MinerKey)
if !ok {
return cid.Undef, xerrors.Errorf("code cid for miner actor not found in new manifest")
}

migrations[miner15Cid] = migration.CachedMigration(cache, &minerMigrator{newMinerCodeCID})

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))
}
Expand Down
Loading