/
events.go
290 lines (225 loc) · 12.4 KB
/
events.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
package retrievalmarket
import "fmt"
// ClientEvent is an event that occurs in a deal lifecycle on the client
type ClientEvent uint64
const (
// ClientEventOpen indicates a deal was initiated
ClientEventOpen ClientEvent = iota
// ClientEventWriteDealProposalErrored means a network error writing a deal proposal
ClientEventWriteDealProposalErrored
// ClientEventDealProposed means a deal was successfully sent to a miner
ClientEventDealProposed
// ClientEventDealRejected means a deal was rejected by the provider
ClientEventDealRejected
// ClientEventDealNotFound means a provider could not find a piece for a deal
ClientEventDealNotFound
// ClientEventDealAccepted means a provider accepted a deal
ClientEventDealAccepted
// ClientEventProviderCancelled means a provider has sent a message to cancel a deal
ClientEventProviderCancelled
// ClientEventUnknownResponseReceived means a client received a response it doesn't
// understand from the provider
ClientEventUnknownResponseReceived
// ClientEventPaymentChannelErrored means there was a failure creating a payment channel
ClientEventPaymentChannelErrored
// ClientEventAllocateLaneErrored means there was a failure creating a lane in a payment channel
ClientEventAllocateLaneErrored
// ClientEventPaymentChannelCreateInitiated means we are waiting for a message to
// create a payment channel to appear on chain
ClientEventPaymentChannelCreateInitiated
// ClientEventPaymentChannelReady means the newly created payment channel is ready for the
// deal to resume
ClientEventPaymentChannelReady
// ClientEventPaymentChannelAddingFunds mean we are waiting for funds to be
// added to a payment channel
ClientEventPaymentChannelAddingFunds
// ClientEventPaymentChannelAddFundsErrored means that adding funds to the payment channel
// failed
ClientEventPaymentChannelAddFundsErrored
// ClientEventLastPaymentRequested indicates the provider requested a final payment
ClientEventLastPaymentRequested
// ClientEventAllBlocksReceived indicates the provider has sent all blocks
ClientEventAllBlocksReceived
// ClientEventPaymentRequested indicates the provider requested a payment
ClientEventPaymentRequested
// ClientEventUnsealPaymentRequested indicates the provider requested a payment for unsealing the sector
ClientEventUnsealPaymentRequested
// ClientEventBlocksReceived indicates the provider has sent blocks
ClientEventBlocksReceived
// ClientEventSendFunds emits when we reach the threshold to send the next payment
ClientEventSendFunds
// ClientEventFundsExpended indicates a deal has run out of funds in the payment channel
// forcing the client to add more funds to continue the deal
ClientEventFundsExpended // when totalFunds is expended
// ClientEventBadPaymentRequested indicates the provider asked for funds
// in a way that does not match the terms of the deal
ClientEventBadPaymentRequested
// ClientEventCreateVoucherFailed indicates an error happened creating a payment voucher
ClientEventCreateVoucherFailed
// ClientEventWriteDealPaymentErrored indicates a network error trying to write a payment
ClientEventWriteDealPaymentErrored
// ClientEventPaymentSent indicates a payment was sent to the provider
ClientEventPaymentSent
// ClientEventComplete is fired when the provider sends a message
// indicating that a deal has completed
ClientEventComplete
// ClientEventDataTransferError emits when something go wrong at the data transfer level
ClientEventDataTransferError
// ClientEventCancelComplete happens when a deal cancellation is transmitted to the provider
ClientEventCancelComplete
// ClientEventEarlyTermination indications a provider send a deal complete without sending all data
ClientEventEarlyTermination
// ClientEventCompleteVerified means that a provider completed without requesting a final payment but
// we verified we received all data
ClientEventCompleteVerified
// ClientEventLaneAllocated is called when a lane is allocated
ClientEventLaneAllocated
// ClientEventVoucherShortfall means we tried to create a voucher but did not have enough funds in channel
// to create it
ClientEventVoucherShortfall
// ClientEventRecheckFunds runs when an external caller indicates there may be new funds in a payment channel
ClientEventRecheckFunds
// ClientEventCancel runs when a user cancels a deal
ClientEventCancel
// ClientEventWaitForLastBlocks is fired when the provider has told
// the client that all blocks were sent for the deal, and the client is
// waiting for the last blocks to arrive
ClientEventWaitForLastBlocks
// ClientEventPaymentChannelSkip is fired when the total deal price is zero
// so there's no need to set up a payment channel
ClientEventPaymentChannelSkip
// ClientEventPaymentNotSent indicates that payment was requested, but no
// payment was actually due, so a voucher was not sent to the provider
ClientEventPaymentNotSent
// ClientEventBlockstoreFinalized is fired when the blockstore has been
// finalized after receiving all blocks
ClientEventBlockstoreFinalized
// ClientEventFinalizeBlockstoreErrored is fired when there is an error
// finalizing the blockstore
ClientEventFinalizeBlockstoreErrored
)
// ClientEvents is a human readable map of client event name -> event description
var ClientEvents = map[ClientEvent]string{
ClientEventOpen: "ClientEventOpen",
ClientEventPaymentChannelErrored: "ClientEventPaymentChannelErrored",
ClientEventDealProposed: "ClientEventDealProposed",
ClientEventAllocateLaneErrored: "ClientEventAllocateLaneErrored",
ClientEventPaymentChannelCreateInitiated: "ClientEventPaymentChannelCreateInitiated",
ClientEventPaymentChannelReady: "ClientEventPaymentChannelReady",
ClientEventPaymentChannelAddingFunds: "ClientEventPaymentChannelAddingFunds",
ClientEventPaymentChannelAddFundsErrored: "ClientEventPaymentChannelAddFundsErrored",
ClientEventWriteDealProposalErrored: "ClientEventWriteDealProposalErrored",
ClientEventDealRejected: "ClientEventDealRejected",
ClientEventDealNotFound: "ClientEventDealNotFound",
ClientEventDealAccepted: "ClientEventDealAccepted",
ClientEventProviderCancelled: "ClientEventProviderCancelled",
ClientEventUnknownResponseReceived: "ClientEventUnknownResponseReceived",
ClientEventLastPaymentRequested: "ClientEventLastPaymentRequested",
ClientEventAllBlocksReceived: "ClientEventAllBlocksReceived",
ClientEventPaymentRequested: "ClientEventPaymentRequested",
ClientEventUnsealPaymentRequested: "ClientEventUnsealPaymentRequested",
ClientEventBlocksReceived: "ClientEventBlocksReceived",
ClientEventSendFunds: "ClientEventSendFunds",
ClientEventFundsExpended: "ClientEventFundsExpended",
ClientEventBadPaymentRequested: "ClientEventBadPaymentRequested",
ClientEventCreateVoucherFailed: "ClientEventCreateVoucherFailed",
ClientEventWriteDealPaymentErrored: "ClientEventWriteDealPaymentErrored",
ClientEventPaymentSent: "ClientEventPaymentSent",
ClientEventDataTransferError: "ClientEventDataTransferError",
ClientEventComplete: "ClientEventComplete",
ClientEventCancelComplete: "ClientEventCancelComplete",
ClientEventEarlyTermination: "ClientEventEarlyTermination",
ClientEventCompleteVerified: "ClientEventCompleteVerified",
ClientEventLaneAllocated: "ClientEventLaneAllocated",
ClientEventVoucherShortfall: "ClientEventVoucherShortfall",
ClientEventRecheckFunds: "ClientEventRecheckFunds",
ClientEventCancel: "ClientEventCancel",
ClientEventWaitForLastBlocks: "ClientEventWaitForLastBlocks",
ClientEventPaymentChannelSkip: "ClientEventPaymentChannelSkip",
ClientEventPaymentNotSent: "ClientEventPaymentNotSent",
ClientEventBlockstoreFinalized: "ClientEventBlockstoreFinalized",
ClientEventFinalizeBlockstoreErrored: "ClientEventFinalizeBlockstoreErrored",
}
func (e ClientEvent) String() string {
s, ok := ClientEvents[e]
if ok {
return s
}
return fmt.Sprintf("ClientEventUnknown: %d", e)
}
// ProviderEvent is an event that occurs in a deal lifecycle on the provider
type ProviderEvent uint64
const (
// ProviderEventOpen indicates a new deal was received from a client
ProviderEventOpen ProviderEvent = iota
// ProviderEventDealNotFound happens when the provider cannot find the piece for the
// deal proposed by the client
ProviderEventDealNotFound
// ProviderEventDealRejected happens when a provider rejects a deal proposed
// by the client
ProviderEventDealRejected
// ProviderEventDealAccepted happens when a provider accepts a deal
ProviderEventDealAccepted
// ProviderEventBlockSent happens when the provider reads another block
// in the piece
ProviderEventBlockSent
// ProviderEventBlocksCompleted happens when the provider reads the last block
// in the piece
ProviderEventBlocksCompleted
// ProviderEventPaymentRequested happens when a provider asks for payment from
// a client for blocks sent
ProviderEventPaymentRequested
// ProviderEventSaveVoucherFailed happens when an attempt to save a payment
// voucher fails
ProviderEventSaveVoucherFailed
// ProviderEventPartialPaymentReceived happens when a provider receives and processes
// a payment that is less than what was requested to proceed with the deal
ProviderEventPartialPaymentReceived
// ProviderEventPaymentReceived happens when a provider receives a payment
// and resumes processing a deal
ProviderEventPaymentReceived
// ProviderEventComplete indicates a retrieval deal was completed for a client
ProviderEventComplete
// ProviderEventUnsealError emits when something wrong occurs while unsealing data
ProviderEventUnsealError
// ProviderEventUnsealComplete emits when the unsealing process is done
ProviderEventUnsealComplete
// ProviderEventDataTransferError emits when something go wrong at the data transfer level
ProviderEventDataTransferError
// ProviderEventCancelComplete happens when a deal cancellation is transmitted to the provider
ProviderEventCancelComplete
// ProviderEventCleanupComplete happens when a deal is finished cleaning up and enters a complete state
ProviderEventCleanupComplete
// ProviderEventMultiStoreError occurs when an error happens attempting to operate on the multistore
ProviderEventMultiStoreError
// ProviderEventClientCancelled happens when the provider gets a cancel message from the client's data transfer
ProviderEventClientCancelled
// ProviderEventLastPaymentRequested is emitted when the transfer goes into finalization
ProviderEventLastPaymentRequested
// ProviderEventProcessPayment occurs when the provider has received a voucher from the client that it needs
// to process as a payment
ProviderEventProcessPayment
)
// ProviderEvents is a human readable map of provider event name -> event description
var ProviderEvents = map[ProviderEvent]string{
ProviderEventOpen: "ProviderEventOpen",
ProviderEventDealNotFound: "ProviderEventDealNotFound",
ProviderEventDealRejected: "ProviderEventDealRejected",
ProviderEventDealAccepted: "ProviderEventDealAccepted",
ProviderEventBlockSent: "ProviderEventBlockSent",
ProviderEventBlocksCompleted: "ProviderEventBlocksCompleted",
ProviderEventPaymentRequested: "ProviderEventPaymentRequested",
ProviderEventSaveVoucherFailed: "ProviderEventSaveVoucherFailed",
ProviderEventPartialPaymentReceived: "ProviderEventPartialPaymentReceived",
ProviderEventPaymentReceived: "ProviderEventPaymentReceived",
ProviderEventComplete: "ProviderEventComplete",
ProviderEventUnsealError: "ProviderEventUnsealError",
ProviderEventUnsealComplete: "ProviderEventUnsealComplete",
ProviderEventDataTransferError: "ProviderEventDataTransferError",
ProviderEventCancelComplete: "ProviderEventCancelComplete",
ProviderEventCleanupComplete: "ProviderEventCleanupComplete",
ProviderEventMultiStoreError: "ProviderEventMultiStoreError",
ProviderEventClientCancelled: "ProviderEventClientCancelled",
ProviderEventLastPaymentRequested: "ProviderEventLastPaymentRequested",
ProviderEventProcessPayment: "ProviderEventProcessPayment",
}