Skip to content

Commit 9d8563e

Browse files
committed
feat(): modify concurrent download chunks
1 parent 0a73152 commit 9d8563e

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

client.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ func (c *Client) httpPost(_path string, payload []byte) (body []byte, statusCode
441441
func (c *Client) getChunk(offset int64) (*types.TransactionChunk, error) {
442442
_path := "chunk/" + strconv.FormatInt(offset, 10)
443443
body, statusCode, err := c.httpGet(_path)
444+
if statusCode == 429 {
445+
return nil, ErrRequestLimit
446+
}
444447
if statusCode != 200 {
445448
return nil, errors.New("not found chunk data")
446449
}
@@ -551,14 +554,16 @@ func (c *Client) ConcurrentDownloadChunkData(id string, concurrentNum int) ([]by
551554
chunkData, err := c.getChunkData(oss.Offset)
552555
if err != nil {
553556
count := 0
554-
for count < 50 {
557+
for count < 3 {
555558
time.Sleep(2 * time.Second)
556559
chunkData, err = c.getChunkData(oss.Offset)
557560
if err == nil {
558561
break
559562
}
560-
log.Error("retry getChunkData failed and try again...", "err", err, "offset", oss.Offset, "retryCount", count)
561-
count++
563+
log.Error("retry getChunkData failed and try again...", "err", err, "offset", oss.Offset, "retryCount", count, "arId", id)
564+
if err != ErrRequestLimit {
565+
count++
566+
}
562567
}
563568
}
564569
lock.Lock()
@@ -583,14 +588,16 @@ func (c *Client) ConcurrentDownloadChunkData(id string, concurrentNum int) ([]by
583588
chunkData, err := c.getChunkData(int64(i) + start)
584589
if err != nil {
585590
count := 0
586-
for count < 50 {
591+
for count < 3 {
587592
time.Sleep(2 * time.Second)
588593
chunkData, err = c.getChunkData(int64(i) + start)
589594
if err == nil {
590595
break
591596
}
592-
log.Error("retry getChunkData failed and try again...", "err", err, "offset", int64(i)+start, "retryCount", count)
593-
count++
597+
log.Error("retry getChunkData failed and try again...", "err", err, "offset", int64(i)+start, "retryCount", count, "arId", id)
598+
if err != ErrRequestLimit {
599+
count++
600+
}
594601
}
595602
}
596603
chunkArr = append(chunkArr, chunkData)

error.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package goar
33
import "errors"
44

55
var (
6-
ErrNotFound = errors.New("Not Found")
7-
ErrPendingTx = errors.New("Pending")
8-
ErrInvalidId = errors.New("Invalid ArId")
9-
ErrBadGateway = errors.New("Bad Gateway")
6+
ErrNotFound = errors.New("Not Found")
7+
ErrPendingTx = errors.New("Pending")
8+
ErrInvalidId = errors.New("Invalid ArId")
9+
ErrBadGateway = errors.New("Bad Gateway")
10+
ErrRequestLimit = errors.New("Arweave gateway request limit")
1011
)

0 commit comments

Comments
 (0)