77 cbor "github.com/ipfs/go-ipld-cbor"
88 xerrors "golang.org/x/xerrors"
99
10+ "github.com/filecoin-project/go-state-types/abi"
1011 miner15 "github.com/filecoin-project/go-state-types/builtin/v15/miner"
1112 miner16 "github.com/filecoin-project/go-state-types/builtin/v16/miner"
1213 adt16 "github.com/filecoin-project/go-state-types/builtin/v16/util/adt"
@@ -31,12 +32,13 @@ func (m minerMigrator) MigrateState(ctx context.Context, store cbor.IpldStore, i
3132
3233 adtStore := adt16 .WrapStore (ctx , store )
3334
34- // Create the new state (v16) with VestingFunds set to nil.
35+ // Create the new state (v16) with the same values as the old state but VestedFunds and Deadlines
36+ // set to zero values (to be filled in below).
3537 outState := miner16.State {
3638 Info : inState .Info ,
3739 PreCommitDeposits : inState .PreCommitDeposits ,
3840 LockedFunds : inState .LockedFunds ,
39- VestingFunds : nil ,
41+ VestingFunds : nil , // set below
4042 FeeDebt : inState .FeeDebt ,
4143 InitialPledge : inState .InitialPledge ,
4244 PreCommittedSectors : inState .PreCommittedSectors ,
@@ -45,11 +47,14 @@ func (m minerMigrator) MigrateState(ctx context.Context, store cbor.IpldStore, i
4547 Sectors : inState .Sectors ,
4648 ProvingPeriodStart : inState .ProvingPeriodStart ,
4749 CurrentDeadline : inState .CurrentDeadline ,
48- Deadlines : inState . Deadlines ,
50+ Deadlines : cid . Undef , // set below
4951 EarlyTerminations : inState .EarlyTerminations ,
5052 DeadlineCronActive : inState .DeadlineCronActive ,
5153 }
5254
55+ // Copy over the vesting funds into the new structure - head (first VestingFund) in the miner
56+ // state, tail (the rest) in a separate block.
57+
5358 oldVestingFunds , err := inState .LoadVestingFunds (adtStore )
5459 if err != nil {
5560 return nil , xerrors .Errorf ("failed to load vesting funds for %s: %w" , in .Address , err )
@@ -76,6 +81,67 @@ func (m minerMigrator) MigrateState(ctx context.Context, store cbor.IpldStore, i
7681 }
7782 }
7883
84+ // Copy over the deadlines into the new structure, but add the new LivePower and DailyFee fields.
85+ // LivePower can be calculated from the partitions, and DailyFee starts at zero for existing
86+ // miners.
87+
88+ deadlines , err := inState .LoadDeadlines (adtStore )
89+ if err != nil {
90+ return nil , xerrors .Errorf ("failed to load deadlines for %s: %w" , in .Address , err )
91+ }
92+ var newDeadlines miner16.Deadlines
93+ for dlIdx := range deadlines .Due {
94+ oldDeadline , err := deadlines .LoadDeadline (adtStore , uint64 (dlIdx ))
95+ if err != nil {
96+ return nil , xerrors .Errorf ("failed to load deadline %d for %s: %w" , dlIdx , in .Address , err )
97+ }
98+
99+ // Copy old deadline
100+ newDeadline := miner16.Deadline {
101+ Partitions : oldDeadline .Partitions ,
102+ ExpirationsEpochs : oldDeadline .ExpirationsEpochs ,
103+ PartitionsPoSted : oldDeadline .PartitionsPoSted ,
104+ EarlyTerminations : oldDeadline .EarlyTerminations ,
105+ LiveSectors : oldDeadline .LiveSectors ,
106+ TotalSectors : oldDeadline .TotalSectors ,
107+ FaultyPower : miner16 .NewPowerPair (oldDeadline .FaultyPower .Raw , oldDeadline .FaultyPower .QA ),
108+ OptimisticPoStSubmissions : oldDeadline .OptimisticPoStSubmissions ,
109+ SectorsSnapshot : oldDeadline .SectorsSnapshot ,
110+ PartitionsSnapshot : oldDeadline .PartitionsSnapshot ,
111+ OptimisticPoStSubmissionsSnapshot : oldDeadline .OptimisticPoStSubmissionsSnapshot ,
112+ LivePower : miner16 .NewPowerPairZero (),
113+ DailyFee : abi .NewTokenAmount (0 ),
114+ }
115+
116+ // Sum up live power in the partitions of this deadline
117+ partitions , err := oldDeadline .PartitionsArray (adtStore )
118+ if err != nil {
119+ return nil , xerrors .Errorf ("failed to load partitions for deadline %d for %s: %w" , dlIdx , in .Address , err )
120+ }
121+ var partition miner16.Partition
122+ err = partitions .ForEach (& partition , func (partIdx int64 ) error {
123+ newDeadline .LivePower = newDeadline .LivePower .Add (partition .LivePower )
124+ return nil
125+ })
126+ if err != nil {
127+ return nil , xerrors .Errorf ("failed to sum up live power for deadline %d for %s: %w" , dlIdx , in .Address , err )
128+ }
129+
130+ // Store the new deadline
131+ dlcid , err := store .Put (ctx , & newDeadline )
132+ if err != nil {
133+ return nil , xerrors .Errorf ("failed to persist deadline %d for %s: %w" , dlIdx , in .Address , err )
134+ }
135+ newDeadlines .Due [dlIdx ] = dlcid
136+ }
137+
138+ // Store the new deadlines array
139+ dlscid , err := store .Put (ctx , & newDeadlines )
140+ if err != nil {
141+ return nil , xerrors .Errorf ("failed to persist deadlines for %s: %w" , in .Address , err )
142+ }
143+ outState .Deadlines = dlscid
144+
79145 // Store the new state.
80146 newHead , err := store .Put (ctx , & outState )
81147 if err != nil {
0 commit comments