forked from filecoin-project/go-state-types
/
miner.go
89 lines (77 loc) · 3.23 KB
/
miner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package migration
import (
"context"
"golang.org/x/xerrors"
miner10 "github.com/CluEleSsUK/go-state-types/builtin/v10/miner"
miner11 "github.com/CluEleSsUK/go-state-types/builtin/v11/miner"
"github.com/CluEleSsUK/go-state-types/migration"
"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
)
// The minerMigrator performs the following migrations:
// - FIP-0061: Updates all miner info PoSt proof types to V1_1 types
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) {
var inState miner10.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)
}
var inInfo miner10.MinerInfo
if err := store.Get(ctx, inState.Info, &inInfo); err != nil {
return nil, xerrors.Errorf("failed to load miner info for %s: %w", in.Address, err)
}
outProof, err := inInfo.WindowPoStProofType.ToV1_1PostProof()
if err != nil {
return nil, xerrors.Errorf("failed to convert to v1_1 proof: %w", err)
}
outInfo := miner11.MinerInfo{
Owner: inInfo.Owner,
Worker: inInfo.Worker,
ControlAddresses: inInfo.ControlAddresses,
PendingWorkerKey: (*miner11.WorkerKeyChange)(inInfo.PendingWorkerKey),
PeerId: inInfo.PeerId,
Multiaddrs: inInfo.Multiaddrs,
WindowPoStProofType: outProof,
SectorSize: inInfo.SectorSize,
WindowPoStPartitionSectors: inInfo.WindowPoStPartitionSectors,
ConsensusFaultElapsed: inInfo.ConsensusFaultElapsed,
PendingOwnerAddress: inInfo.PendingOwnerAddress,
Beneficiary: inInfo.Beneficiary,
BeneficiaryTerm: miner11.BeneficiaryTerm(inInfo.BeneficiaryTerm),
PendingBeneficiaryTerm: (*miner11.PendingBeneficiaryChange)(inInfo.PendingBeneficiaryTerm),
}
outInfoCid, err := store.Put(ctx, &outInfo)
if err != nil {
return nil, xerrors.Errorf("failed to write new miner info: %w", err)
}
outState := miner11.State{
Info: outInfoCid,
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,
}
newHead, err := store.Put(ctx, &outState)
if err != nil {
return nil, xerrors.Errorf("failed to put new state: %w", err)
}
return &migration.ActorMigrationResult{
NewCodeCID: m.MigratedCodeCID(),
NewHead: newHead,
}, nil
}