Skip to content

Commit 9d9e879

Browse files
committed
fix(): modify submint tx and chunk err process
1 parent c069906 commit 9d9e879

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

types/const.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ const (
3434

3535
// Errors from /chunk we should never try and continue on.
3636
var FATAL_CHUNK_UPLOAD_ERRORS = map[string]struct{}{
37-
"invalid_json": struct{}{},
38-
"chunk_too_big": struct{}{},
39-
"data_path_too_big": struct{}{},
40-
"offset_too_big": struct{}{},
41-
"data_size_too_big": struct{}{},
42-
"chunk_proof_ratio_not_attractive": struct{}{},
43-
"invalid_proof": struct{}{},
37+
"{\"error\":\"disk_full\"}": struct{}{},
38+
"{\"error\":\"invalid_json\"}": struct{}{},
39+
"{\"error\":\"chunk_too_big\"}": struct{}{},
40+
"{\"error\":\"data_path_too_big\"}": struct{}{},
41+
"{\"error\":\"offset_too_big\"}": struct{}{},
42+
"{\"error\":\"data_size_too_big\"}": struct{}{},
43+
"{\"error\":\"chunk_proof_ratio_not_attractive\"}": struct{}{},
44+
"{\"error\":\"invalid_proof\"}": struct{}{},
4445
}
4546

4647
// about bundle

uploader.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,16 @@ func (tt *TransactionUploader) UploadChunk() error {
217217
if err != nil {
218218
return err
219219
}
220-
_, statusCode, err := tt.Client.SubmitChunks(gc)
220+
body, statusCode, err := tt.Client.SubmitChunks(gc) // always body is errMsg
221221
tt.LastRequestTimeEnd = time.Now().UnixNano() / 1000000
222222
tt.LastResponseStatus = statusCode
223223
if statusCode == 200 {
224224
tt.ChunkIndex++
225-
} else if err != nil {
226-
tt.LastResponseError = err.Error()
227-
if _, ok := types.FATAL_CHUNK_UPLOAD_ERRORS[err.Error()]; ok {
228-
return errors.New(fmt.Sprintf("Fatal error uploading chunk %d:%v", tt.ChunkIndex, err))
225+
} else {
226+
errStr := fmt.Sprintf("%s,%v,%d", body, err, statusCode)
227+
tt.LastResponseError = errStr
228+
if _, ok := types.FATAL_CHUNK_UPLOAD_ERRORS[body]; ok {
229+
return errors.New(fmt.Sprintf("Fatal error uploading chunk %d:%v", tt.ChunkIndex, body))
229230
}
230231
}
231232
return nil
@@ -315,10 +316,11 @@ func (tt *TransactionUploader) uploadTx(withBody bool) error {
315316
// Post the Transaction with Data.
316317
tt.Transaction.Data = utils.Base64Encode(tt.Data)
317318
}
318-
_, statusCode, err := tt.Client.SubmitTransaction(tt.Transaction)
319-
if err != nil {
320-
tt.LastResponseError = err.Error()
321-
return errors.New(fmt.Sprintf("Unable to upload Transaction: %d, %v", statusCode, err))
319+
body, statusCode, err := tt.Client.SubmitTransaction(tt.Transaction)
320+
if err != nil || statusCode >= 400 {
321+
tt.LastResponseError = fmt.Sprintf("%v,%s", err, body)
322+
tt.LastResponseStatus = statusCode
323+
return errors.New(fmt.Sprintf("Unable to upload Transaction: %d, %v, %s", statusCode, err, body))
322324
}
323325

324326
tt.LastRequestTimeEnd = time.Now().UnixNano() / 1000000
@@ -328,6 +330,7 @@ func (tt *TransactionUploader) uploadTx(withBody bool) error {
328330
tt.Transaction.Data = ""
329331
}
330332

333+
// tx already processed
331334
if statusCode >= 200 && statusCode < 300 {
332335
tt.TxPosted = true
333336
if withBody {

0 commit comments

Comments
 (0)