/
migrations.go
257 lines (226 loc) · 7.81 KB
/
migrations.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package migrations
import (
"context"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer"
cbg "github.com/whyrusleeping/cbor-gen"
"github.com/filecoin-project/go-address"
versioning "github.com/filecoin-project/go-ds-versioning/pkg"
"github.com/filecoin-project/go-ds-versioning/pkg/versioned"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/specs-actors/v8/actors/builtin/market"
"github.com/filecoin-project/go-fil-markets/filestore"
"github.com/filecoin-project/go-fil-markets/storagemarket"
)
//go:generate cbor-gen-for ClientDeal0 MinerDeal0 Balance0 SignedStorageAsk0 StorageAsk0 DataRef0 ProviderDealState0 AskRequest0 AskResponse0 Proposal0 Response0 SignedResponse0 DealStatusRequest0 DealStatusResponse0
// Balance0 is version 0 of Balance
type Balance0 struct {
Locked abi.TokenAmount
Available abi.TokenAmount
}
// StorageAsk0 is version 0 of StorageAsk
type StorageAsk0 struct {
Price abi.TokenAmount
VerifiedPrice abi.TokenAmount
MinPieceSize abi.PaddedPieceSize
MaxPieceSize abi.PaddedPieceSize
Miner address.Address
Timestamp abi.ChainEpoch
Expiry abi.ChainEpoch
SeqNo uint64
}
// SignedStorageAsk0 is version 0 of SignedStorageAsk
type SignedStorageAsk0 struct {
Ask *StorageAsk0
Signature *crypto.Signature
}
// MinerDeal0 is version 0 of MinerDeal
type MinerDeal0 struct {
market.ClientDealProposal
ProposalCid cid.Cid
AddFundsCid *cid.Cid
PublishCid *cid.Cid
Miner peer.ID
Client peer.ID
State storagemarket.StorageDealStatus
PiecePath filestore.Path
MetadataPath filestore.Path
SlashEpoch abi.ChainEpoch
FastRetrieval bool
Message string
StoreID *uint64
FundsReserved abi.TokenAmount
Ref *DataRef0
AvailableForRetrieval bool
DealID abi.DealID
CreationTime cbg.CborTime
}
// ClientDeal0 is version 0 of ClientDeal
type ClientDeal0 struct {
market.ClientDealProposal
ProposalCid cid.Cid
AddFundsCid *cid.Cid
State storagemarket.StorageDealStatus
Miner peer.ID
MinerWorker address.Address
DealID abi.DealID
DataRef *DataRef0
Message string
PublishMessage *cid.Cid
SlashEpoch abi.ChainEpoch
PollRetryCount uint64
PollErrorCount uint64
FastRetrieval bool
StoreID *uint64
FundsReserved abi.TokenAmount
CreationTime cbg.CborTime
}
// DataRef0 is version 0 of DataRef
type DataRef0 struct {
TransferType string
Root cid.Cid
PieceCid *cid.Cid
PieceSize abi.UnpaddedPieceSize
}
// ProviderDealState0 is version 0 of ProviderDealState
type ProviderDealState0 struct {
State storagemarket.StorageDealStatus
Message string
Proposal *market.DealProposal
ProposalCid *cid.Cid
AddFundsCid *cid.Cid
PublishCid *cid.Cid
DealID abi.DealID
FastRetrieval bool
}
// Proposal0 is version 0 of Proposal
type Proposal0 struct {
DealProposal *market.ClientDealProposal
Piece *DataRef0
FastRetrieval bool
}
// Response0 is version 0 of Response
type Response0 struct {
State storagemarket.StorageDealStatus
// DealProposalRejected
Message string
Proposal cid.Cid
// StorageDealProposalAccepted
PublishMessage *cid.Cid
}
// SignedResponse0 is version 0 of SignedResponse
type SignedResponse0 struct {
Response Response0
Signature *crypto.Signature
}
// AskRequest0 is version 0 of AskRequest
type AskRequest0 struct {
Miner address.Address
}
// AskResponse0 is version 0 of AskResponse
type AskResponse0 struct {
Ask *SignedStorageAsk0
}
// DealStatusRequest0 is version 0 of DealStatusRequest
type DealStatusRequest0 struct {
Proposal cid.Cid
Signature crypto.Signature
}
// DealStatusResponse0 is version 0 of DealStatusResponse
type DealStatusResponse0 struct {
DealState ProviderDealState0
Signature crypto.Signature
}
// MigrateDataRef0To1 migrates a tuple encoded data tref to a map encoded data ref
func MigrateDataRef0To1(oldDr *DataRef0) *storagemarket.DataRef {
if oldDr == nil {
return nil
}
return &storagemarket.DataRef{
TransferType: oldDr.TransferType,
Root: oldDr.Root,
PieceCid: oldDr.PieceCid,
PieceSize: oldDr.PieceSize,
}
}
// MigrateClientDeal0To1 migrates a tuple encoded client deal to a map encoded client deal
func MigrateClientDeal0To1(oldCd *ClientDeal0) (*storagemarket.ClientDeal, error) {
return &storagemarket.ClientDeal{
ClientDealProposal: oldCd.ClientDealProposal,
ProposalCid: oldCd.ProposalCid,
AddFundsCid: oldCd.AddFundsCid,
State: oldCd.State,
Miner: oldCd.Miner,
MinerWorker: oldCd.MinerWorker,
DealID: oldCd.DealID,
DataRef: MigrateDataRef0To1(oldCd.DataRef),
Message: oldCd.Message,
PublishMessage: oldCd.PublishMessage,
SlashEpoch: oldCd.SlashEpoch,
PollRetryCount: oldCd.PollRetryCount,
PollErrorCount: oldCd.PollErrorCount,
FastRetrieval: oldCd.FastRetrieval,
FundsReserved: oldCd.FundsReserved,
CreationTime: oldCd.CreationTime,
}, nil
}
// MigrateMinerDeal0To1 migrates a tuple encoded miner deal to a map encoded miner deal
func MigrateMinerDeal0To1(oldCd *MinerDeal0) (*storagemarket.MinerDeal, error) {
return &storagemarket.MinerDeal{
ClientDealProposal: oldCd.ClientDealProposal,
ProposalCid: oldCd.ProposalCid,
AddFundsCid: oldCd.AddFundsCid,
PublishCid: oldCd.PublishCid,
Miner: oldCd.Miner,
Client: oldCd.Client,
State: oldCd.State,
PiecePath: oldCd.PiecePath,
MetadataPath: oldCd.MetadataPath,
SlashEpoch: oldCd.SlashEpoch,
FastRetrieval: oldCd.FastRetrieval,
Message: oldCd.Message,
FundsReserved: oldCd.FundsReserved,
Ref: MigrateDataRef0To1(oldCd.Ref),
AvailableForRetrieval: oldCd.AvailableForRetrieval,
DealID: oldCd.DealID,
CreationTime: oldCd.CreationTime,
}, nil
}
// MigrateStorageAsk0To1 migrates a tuple encoded storage ask to a map encoded storage ask
func MigrateStorageAsk0To1(oldSa *StorageAsk0) *storagemarket.StorageAsk {
return &storagemarket.StorageAsk{
Price: oldSa.Price,
VerifiedPrice: oldSa.VerifiedPrice,
MinPieceSize: oldSa.MinPieceSize,
MaxPieceSize: oldSa.MaxPieceSize,
Miner: oldSa.Miner,
Timestamp: oldSa.Timestamp,
Expiry: oldSa.Expiry,
SeqNo: oldSa.SeqNo,
}
}
// GetMigrateSignedStorageAsk0To1 returns a function that migrates a tuple encoded signed storage ask to a map encoded signed storage ask
// It needs a signing function to resign the ask -- there's no way around that
func GetMigrateSignedStorageAsk0To1(sign func(ctx context.Context, ask *storagemarket.StorageAsk) (*crypto.Signature, error)) func(*SignedStorageAsk0) (*storagemarket.SignedStorageAsk, error) {
return func(oldSsa *SignedStorageAsk0) (*storagemarket.SignedStorageAsk, error) {
newSa := MigrateStorageAsk0To1(oldSsa.Ask)
sig, err := sign(context.TODO(), newSa)
if err != nil {
return nil, err
}
return &storagemarket.SignedStorageAsk{
Ask: newSa,
Signature: sig,
}, nil
}
}
// ClientMigrations are migrations for the client's store of storage deals
var ClientMigrations = versioned.BuilderList{
versioned.NewVersionedBuilder(MigrateClientDeal0To1, versioning.VersionKey("1")),
}
// ProviderMigrations are migrations for the providers's store of storage deals
var ProviderMigrations = versioned.BuilderList{
versioned.NewVersionedBuilder(MigrateMinerDeal0To1, versioning.VersionKey("1")).FilterKeys([]string{
"/latest-ask", "/storage-ask/latest", "/storage-ask/1/latest", "/storage-ask/versions/current"}),
}