@@ -184,30 +184,39 @@ func (c *Client) SplitableUpload(ctx context.Context, w3Client *web3go.Client, d
184184
185185// BatchUpload submit multiple data to 0g storage contract batchly in single on-chain transaction, then transfer the data to the storage nodes selected from indexer service.
186186func (c * Client ) BatchUpload (ctx context.Context , w3Client * web3go.Client , datas []core.IterableData , option ... transfer.BatchUploadOption ) (eth_common.Hash , []eth_common.Hash , error ) {
187- expectedReplica := uint ( 1 )
187+ var opts transfer. BatchUploadOption
188188 if len (option ) > 0 {
189- for _ , opt := range option [0 ].DataOptions {
190- expectedReplica = max (expectedReplica , opt .ExpectedReplica )
191- }
189+ opts = option [0 ]
190+ }
191+
192+ expectedReplica := uint (1 )
193+ for _ , opt := range opts .DataOptions {
194+ expectedReplica = max (expectedReplica , opt .ExpectedReplica )
192195 }
193196 var maxSegNum uint64
194197 for _ , data := range datas {
195198 maxSegNum = max (maxSegNum , data .NumSegments ())
196199 }
197200 dropped := make ([]string , 0 )
201+ maxRetry := 3
202+ attempts := 0
198203 for {
199- uploader , err := c .NewUploaderFromIndexerNodes (ctx , maxSegNum , w3Client , expectedReplica , dropped , option [ 0 ] .Method , option [ 0 ] .FullTrusted )
204+ uploader , err := c .NewUploaderFromIndexerNodes (ctx , maxSegNum , w3Client , expectedReplica , dropped , opts .Method , opts .FullTrusted )
200205 if err != nil {
201206 return eth_common.Hash {}, nil , err
202207 }
203- hash , roots , err := uploader .BatchUpload (ctx , datas , option ... )
208+ hash , roots , err := uploader .BatchUpload (ctx , datas , opts )
204209 var rpcError * node.RPCError
205210 if errors .As (err , & rpcError ) {
206211 dropped = append (dropped , rpcError .URL )
207212 c .logger .Infof ("dropped problematic node and retry: %v" , rpcError .Error ())
208213 } else {
209214 return hash , roots , err
210215 }
216+ attempts ++
217+ if attempts >= maxRetry {
218+ return hash , roots , err
219+ }
211220 }
212221}
213222
@@ -245,28 +254,36 @@ func (c *Client) UploadFileSegments(
245254 return errors .New ("segment data is empty" )
246255 }
247256
248- expectedReplica := uint ( 1 )
257+ var opt transfer. UploadOption
249258 if len (option ) > 0 {
250- expectedReplica = max ( expectedReplica , option [0 ]. ExpectedReplica )
259+ opt = option [0 ]
251260 }
252261
262+ expectedReplica := max (uint (1 ), opt .ExpectedReplica )
263+
253264 numSeg := core .NumSplits (int64 (fileSeg .FileInfo .Tx .Size ), core .DefaultSegmentSize )
254265 dropped := make ([]string , 0 )
266+ maxRetry := 3
267+ attempts := 0
255268 for {
256- uploaders , err := c .NewFileSegmentUploaderFromIndexerNodes (ctx , numSeg , expectedReplica , dropped , option [ 0 ] .Method , true )
269+ uploaders , err := c .NewFileSegmentUploaderFromIndexerNodes (ctx , numSeg , expectedReplica , dropped , opt .Method , true )
257270 if err != nil {
258271 return err
259272 }
260273
261274 var rpcError * node.RPCError
262275 for _ , uploader := range uploaders {
263- if err := uploader .Upload (ctx , fileSeg , option ... ); errors .As (err , & rpcError ) {
276+ if err := uploader .Upload (ctx , fileSeg , opt ); errors .As (err , & rpcError ) {
264277 dropped = append (dropped , rpcError .URL )
265278 c .logger .Infof ("dropped problematic node and retry: %v" , rpcError .Error ())
266279 } else {
267280 return err
268281 }
269282 }
283+ attempts ++
284+ if attempts >= maxRetry {
285+ return rpcError
286+ }
270287 }
271288}
272289
0 commit comments