Skip to content

Commit

Permalink
v13: Cleanup miner migration
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Feb 9, 2024
1 parent 90e0f57 commit 884c4fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 46 deletions.
46 changes: 2 additions & 44 deletions builtin/v13/migration/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package migration
import (
"bytes"
"context"
"encoding/json"
"fmt"
"sync"

"github.com/filecoin-project/go-address"
Expand All @@ -25,9 +23,6 @@ type providerSectors struct {
lk sync.Mutex

dealToSector map[abi.DealID]abi.SectorID

// diff mode removes
removedDealToSector map[abi.DealID]abi.SectorID
}

// minerMigration is technically a no-op, but it collects a cache for market migration
Expand Down Expand Up @@ -98,11 +93,6 @@ func (m *minerMigrator) MigrateState(ctx context.Context, store cbor.IpldStore,
return nil, xerrors.Errorf("failed to diff old and new Sector AMTs: %w", err)
}

prevInSectors, err := adt.AsArray(ctxStore, prevSectors, miner12.SectorsAmtBitwidth)
if err != nil {
return nil, xerrors.Errorf("failed to load prev sectors array: %w", err)
}

for i, change := range diffs {
sectorNo := abi.SectorNumber(change.Key)

Expand Down Expand Up @@ -149,17 +139,6 @@ func (m *minerMigrator) MigrateState(ctx context.Context, store cbor.IpldStore,

if len(sectorBefore.DealIDs) != len(sectorAfter.DealIDs) {
if len(sectorBefore.DealIDs) != 0 {
pjsonb, err := json.MarshalIndent(sectorBefore, "", " ")
if err != nil {
return nil, err
}
pjson, err := json.MarshalIndent(sectorAfter, "", " ")
if err != nil {
return nil, err
}

fmt.Println("sector before: ", string(pjsonb))
fmt.Println("sector after: ", string(pjson))
return nil, xerrors.Errorf("WHAT?! sector %d modified, this not supported and not supposed to happen", i) // todo: is it? Can't happen w/o a deep, deep reorg, and even then we wouldn't use the cache??
}
// snap
Expand All @@ -178,31 +157,10 @@ func (m *minerMigrator) MigrateState(ctx context.Context, store cbor.IpldStore,

// extensions, etc. here; we don't care about those
case amt.Remove:
// related deals will also get removed in the market, so we don't have anything to do here

found, err := prevInSectors.Get(change.Key, &sector)
if err != nil {
return nil, xerrors.Errorf("failed to get sector %d in prevInSectors: %w", sectorNo, err)
}
if !found {
return nil, xerrors.Errorf("didn't find sector %d in prevInSectors", sectorNo)
}

if len(sector.DealIDs) == 0 {
// if no deals don't even bother taking the lock
continue
}
// nothing to do here, market removes deals based on activation/slash status, and can tell what
// mappings to remove because non-slashed deals already had them

//fmt.Printf("prov dealsector REM %d: %v\n", sectorNo, sector.DealIDs)

m.providerSectors.lk.Lock()
for _, dealID := range sector.DealIDs {
m.providerSectors.removedDealToSector[dealID] = abi.SectorID{
Miner: abi.ActorID(mid),
Number: sectorNo,
}
}
m.providerSectors.lk.Unlock()
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions builtin/v13/migration/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func MigrateStateTree(ctx context.Context, store cbor.IpldStore, newManifestCID
migrations[oldEntry.Code] = migration.CachedMigration(cache, migration.CodeMigrator{OutCodeCID: newCodeCID})
}

if market12Cid == cid.Undef || miner12Cid == cid.Undef {
return cid.Undef, xerrors.Errorf("could not find market or miner actor in old manifest")
}

// migrations that migrate both code and state, override entries in `migrations`

// The System Actor
Expand Down Expand Up @@ -118,7 +122,7 @@ func MigrateStateTree(ctx context.Context, store cbor.IpldStore, newManifestCID
// The Market Actor
market13Cid, ok := newManifest.Get(manifest.MarketKey)
if !ok {
return cid.Undef, xerrors.Errorf("code cid for miner actor not found in new manifest")
return cid.Undef, xerrors.Errorf("code cid for market actor not found in new manifest")
}

marketMig, err := newMarketMigrator(ctx, store, market13Cid, ps)
Expand All @@ -128,7 +132,7 @@ func MigrateStateTree(ctx context.Context, store cbor.IpldStore, newManifestCID
migrations[market12Cid] = migration.CachedMigration(cache, marketMig)

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(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)
Expand Down

0 comments on commit 884c4fc

Please sign in to comment.