-
Notifications
You must be signed in to change notification settings - Fork 0
/
market.go
106 lines (89 loc) · 3.25 KB
/
market.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package nv10
import (
"context"
cid "github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
market2 "github.com/chenjianmei111/specs-actors/v2/actors/builtin/market"
adt2 "github.com/chenjianmei111/specs-actors/v2/actors/util/adt"
builtin3 "github.com/chenjianmei111/specs-actors/v3/actors/builtin"
market3 "github.com/chenjianmei111/specs-actors/v3/actors/builtin/market"
adt3 "github.com/chenjianmei111/specs-actors/v3/actors/util/adt"
)
type marketMigrator struct{}
func (m marketMigrator) migrateState(ctx context.Context, store cbor.IpldStore, in actorMigrationInput) (*actorMigrationResult, error) {
var inState market2.State
if err := store.Get(ctx, in.head, &inState); err != nil {
return nil, err
}
pendingProposalsCidOut, err := m.MapPendingProposals(ctx, store, inState.PendingProposals)
if err != nil {
return nil, err
}
proposalsCidOut, err := migrateAMTRaw(ctx, store, inState.Proposals, market3.ProposalsAmtBitwidth)
if err != nil {
return nil, err
}
statesCidOut, err := migrateAMTRaw(ctx, store, inState.States, market3.StatesAmtBitwidth)
if err != nil {
return nil, err
}
escrowTableCidOut, err := migrateHAMTRaw(ctx, store, inState.EscrowTable, adt3.BalanceTableBitwidth)
if err != nil {
return nil, err
}
lockedTableCidOut, err := migrateHAMTRaw(ctx, store, inState.LockedTable, adt3.BalanceTableBitwidth)
if err != nil {
return nil, err
}
dobeCidOut, err := migrateHAMTHAMTRaw(ctx, store, inState.DealOpsByEpoch, builtin3.DefaultHamtBitwidth, builtin3.DefaultHamtBitwidth)
if err != nil {
return nil, err
}
outState := market3.State{
Proposals: proposalsCidOut,
States: statesCidOut,
PendingProposals: pendingProposalsCidOut,
EscrowTable: escrowTableCidOut,
LockedTable: lockedTableCidOut,
NextID: inState.NextID,
DealOpsByEpoch: dobeCidOut,
LastCron: inState.LastCron,
TotalClientLockedCollateral: inState.TotalClientLockedCollateral,
TotalProviderLockedCollateral: inState.TotalProviderLockedCollateral,
TotalClientStorageFee: inState.TotalClientStorageFee,
}
newHead, err := store.Put(ctx, &outState)
return &actorMigrationResult{
newCodeCID: m.migratedCodeCID(),
newHead: newHead,
}, err
}
func (m marketMigrator) migratedCodeCID() cid.Cid {
return builtin3.StorageMarketActorCodeID
}
func (a marketMigrator) MapPendingProposals(ctx context.Context, store cbor.IpldStore, pendingProposalsRoot cid.Cid) (cid.Cid, error) {
oldPendingProposals, err := adt2.AsMap(adt2.WrapStore(ctx, store), pendingProposalsRoot)
if err != nil {
return cid.Undef, err
}
newPendingProposals, err := adt3.MakeEmptySet(adt3.WrapStore(ctx, store), builtin3.DefaultHamtBitwidth)
if err != nil {
return cid.Undef, err
}
err = oldPendingProposals.ForEach(nil, func(key string) error {
return newPendingProposals.Put(StringKey(key))
})
if err != nil {
return cid.Undef, err
}
newPendingProposalsCid, err := newPendingProposals.Root()
if err != nil {
return cid.Undef, err
}
return newPendingProposalsCid, nil
}
// An adt.Map key that just preserves the underlying string.
type StringKey string
func (k StringKey) Key() string {
return string(k)
}