Skip to content

Commit

Permalink
chore: function visibility, default retry option
Browse files Browse the repository at this point in the history
MiniFrenchBread committed Feb 28, 2024
1 parent 58c1781 commit 8f55b6f
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions common/blockchain/rpc.go
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 6 additions & 6 deletions transfer/uploader.go
Original file line number Diff line number Diff line change
@@ -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 {
2 changes: 1 addition & 1 deletion transfer/uploader_dup_file.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 8f55b6f

Please sign in to comment.