diff --git a/common/blockchain/rpc.go b/common/blockchain/rpc.go index b2d7153..be53a5f 100644 --- a/common/blockchain/rpc.go +++ b/common/blockchain/rpc.go @@ -62,13 +62,14 @@ func WaitForReceipt(client *web3go.Client, txHash common.Hash, successRequired b if len(opts) > 0 { opt = opts[0] } else { + // default infinite wait opt.Rounds = 0 - opt.Interval = time.Second + opt.Interval = time.Second * 3 } var tries uint for receipt == nil { - if tries > opt.Rounds+1 { + if tries > opt.Rounds+1 && opt.Rounds != 0 { return nil, errors.New("no receipt after max retries") } time.Sleep(opt.Interval) diff --git a/transfer/uploader.go b/transfer/uploader.go index 5d2c405..9e079ac 100644 --- a/transfer/uploader.go +++ b/transfer/uploader.go @@ -111,7 +111,7 @@ func (uploader *Uploader) BatchUpload(datas []core.IterableData, waitForLogEntry var txHash common.Hash if len(toSubmitDatas) > 0 { var err error - if txHash, _, err = uploader.submitLogEntry(toSubmitDatas, toSubmitTags, waitForLogEntry); err != nil { + if txHash, _, err = uploader.SubmitLogEntry(toSubmitDatas, toSubmitTags, waitForLogEntry); err != nil { return common.Hash{}, nil, errors.WithMessage(err, "Failed to submit log entry") } if waitForLogEntry { @@ -124,7 +124,7 @@ func (uploader *Uploader) BatchUpload(datas []core.IterableData, waitForLogEntry for i := 0; i < n; i++ { // Upload file to storage node - if err := uploader.uploadFile(datas[i], trees[i], 0, opts[i].Disperse, opts[i].TaskSize); err != nil { + if err := uploader.UploadFile(datas[i], trees[i], 0, opts[i].Disperse, opts[i].TaskSize); err != nil { return common.Hash{}, nil, errors.WithMessage(err, "Failed to upload file") } @@ -192,7 +192,7 @@ func (uploader *Uploader) Upload(data core.IterableData, option ...UploadOption) segNum := uint64(0) if info == nil { // Append log on blockchain - if _, _, err = uploader.submitLogEntry([]core.IterableData{data}, [][]byte{opt.Tags}, true); err != nil { + if _, _, err = uploader.SubmitLogEntry([]core.IterableData{data}, [][]byte{opt.Tags}, true); err != nil { return errors.WithMessage(err, "Failed to submit log entry") } @@ -215,7 +215,7 @@ func (uploader *Uploader) Upload(data core.IterableData, option ...UploadOption) } // Upload file to storage node - if err = uploader.uploadFile(data, tree, segNum, opt.Disperse, opt.TaskSize); err != nil { + if err = uploader.UploadFile(data, tree, segNum, opt.Disperse, opt.TaskSize); err != nil { return errors.WithMessage(err, "Failed to upload file") } @@ -229,7 +229,7 @@ func (uploader *Uploader) Upload(data core.IterableData, option ...UploadOption) return nil } -func (uploader *Uploader) submitLogEntry(datas []core.IterableData, tags [][]byte, waitForReceipt bool) (common.Hash, *types.Receipt, error) { +func (uploader *Uploader) SubmitLogEntry(datas []core.IterableData, tags [][]byte, waitForReceipt bool) (common.Hash, *types.Receipt, error) { // Construct submission submissions := make([]contract.Submission, len(datas)) for i := 0; i < len(datas); i++ { @@ -298,7 +298,7 @@ func (uploader *Uploader) waitForLogEntry(root common.Hash, finalityRequired boo } // TODO error tolerance -func (uploader *Uploader) uploadFile(data core.IterableData, tree *merkle.Tree, segIndex uint64, disperse bool, taskSize uint) error { +func (uploader *Uploader) UploadFile(data core.IterableData, tree *merkle.Tree, segIndex uint64, disperse bool, taskSize uint) error { stageTimer := time.Now() if taskSize == 0 { diff --git a/transfer/uploader_dup_file.go b/transfer/uploader_dup_file.go index b71923f..76960bf 100644 --- a/transfer/uploader_dup_file.go +++ b/transfer/uploader_dup_file.go @@ -19,7 +19,7 @@ const SubmitEventHash = "0x167ce04d2aa1981994d3a31695da0d785373335b1078cec239a1a // file finality on storage node. func (uploader *Uploader) uploadDuplicatedFile(data core.IterableData, tags []byte, root common.Hash) error { // submit transaction on blockchain - _, receipt, err := uploader.submitLogEntry([]core.IterableData{data}, [][]byte{tags}, true) + _, receipt, err := uploader.SubmitLogEntry([]core.IterableData{data}, [][]byte{tags}, true) if err != nil { return errors.WithMessage(err, "Failed to submit log entry") }