Skip to content

Commit 79443b5

Browse files
arajasekZenGround0
andauthored
Market migration: Correctly migrate deal states (#108)
* Market migration: Correctly migrate deal states Co-authored-by: zenground0 <[email protected]> Co-authored-by: ZenGround0 <[email protected]>
1 parent 67cc2b3 commit 79443b5

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

builtin/v9/migration/market.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
adt8 "github.com/filecoin-project/go-state-types/builtin/v8/util/adt"
1010
market9 "github.com/filecoin-project/go-state-types/builtin/v9/market"
1111
adt9 "github.com/filecoin-project/go-state-types/builtin/v9/util/adt"
12+
"github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
1213
"github.com/ipfs/go-cid"
1314
typegen "github.com/whyrusleeping/cbor-gen"
1415
"golang.org/x/xerrors"
@@ -32,9 +33,42 @@ func migrateMarket(ctx context.Context, adtStore adt8.Store, dealAllocationTuple
3233
return cid.Undef, xerrors.Errorf("failed to flush pending deal allocations map: %w", err)
3334
}
3435

36+
dealStates8, err := adt9.AsArray(adtStore, marketStateV8.States, market8.StatesAmtBitwidth)
37+
if err != nil {
38+
return cid.Undef, xerrors.Errorf("failed to load v8 states array: %w", err)
39+
}
40+
41+
emptyStatesArrayCid, err := adt9.StoreEmptyArray(adtStore, market9.StatesAmtBitwidth)
42+
if err != nil {
43+
return cid.Undef, xerrors.Errorf("failed to create empty states array: %w", err)
44+
}
45+
46+
dealStates9, err := adt9.AsArray(adtStore, emptyStatesArrayCid, market9.StatesAmtBitwidth)
47+
if err != nil {
48+
return cid.Undef, xerrors.Errorf("failed to load v9 states array: %w", err)
49+
}
50+
51+
var dealState8 market8.DealState
52+
err = dealStates8.ForEach(&dealState8, func(i int64) error {
53+
return dealStates9.Set(uint64(i), &market9.DealState{
54+
SectorStartEpoch: dealState8.SectorStartEpoch,
55+
LastUpdatedEpoch: dealState8.LastUpdatedEpoch,
56+
SlashEpoch: dealState8.SlashEpoch,
57+
VerifiedClaim: verifreg.NoAllocationID,
58+
})
59+
})
60+
if err != nil {
61+
return cid.Undef, xerrors.Errorf("failed to iterate over v8 states: %w", err)
62+
}
63+
64+
dealStates9Root, err := dealStates9.Root()
65+
if err != nil {
66+
return cid.Undef, xerrors.Errorf("failed to flush dealStates 9: %w", err)
67+
}
68+
3569
marketStateV9 := market9.State{
3670
Proposals: marketStateV8.Proposals,
37-
States: marketStateV8.States,
71+
States: dealStates9Root,
3872
PendingProposals: marketStateV8.PendingProposals,
3973
EscrowTable: marketStateV8.EscrowTable,
4074
LockedTable: marketStateV8.LockedTable,

0 commit comments

Comments
 (0)