@@ -271,8 +271,6 @@ func (c ChainReaderWriterEth1) FrozenBlocks(ctx context.Context) uint64 {
271271 return ret .FrozenBlocks
272272}
273273
274- const retryTimeout = 10 * time .Millisecond
275-
276274func (c ChainReaderWriterEth1 ) InsertBlocksAndWait (ctx context.Context , blocks []* types.Block ) error {
277275 request := & execution.InsertBlocksRequest {
278276 Blocks : eth1_utils .ConvertBlocksToRPC (blocks ),
@@ -281,22 +279,26 @@ func (c ChainReaderWriterEth1) InsertBlocksAndWait(ctx context.Context, blocks [
281279 if err != nil {
282280 return err
283281 }
284- retryInterval := time .NewTicker (retryTimeout )
285- defer retryInterval .Stop ()
282+
283+ // limit the number of retries
284+ ctx , cancel := context .WithTimeout (ctx , 10 * time .Second )
285+ defer cancel ()
286286
287287 for response .Result == execution .ExecutionStatus_Busy {
288+ const retryDelay = 100 * time .Millisecond
288289 select {
289- case <- retryInterval .C :
290- response , err = c .executionModule .InsertBlocks (ctx , request )
291- if err != nil {
292- return err
293- }
290+ case <- time .After (retryDelay ):
294291 case <- ctx .Done ():
295292 return ctx .Err ()
296293 }
294+
295+ response , err = c .executionModule .InsertBlocks (ctx , request )
296+ if err != nil {
297+ return err
298+ }
297299 }
298300 if response .Result != execution .ExecutionStatus_Success {
299- return fmt .Errorf ("insertHeadersAndWait: invalid code recieved from execution module: %s" , response .Result .String ())
301+ return fmt .Errorf ("InsertBlocksAndWait: executionModule.InsertBlocks ExecutionStatus = %s" , response .Result .String ())
300302 }
301303 return nil
302304}
@@ -321,31 +323,7 @@ func (c ChainReaderWriterEth1) InsertBlocks(ctx context.Context, blocks []*types
321323
322324func (c ChainReaderWriterEth1 ) InsertBlockAndWait (ctx context.Context , block * types.Block ) error {
323325 blocks := []* types.Block {block }
324- request := & execution.InsertBlocksRequest {
325- Blocks : eth1_utils .ConvertBlocksToRPC (blocks ),
326- }
327-
328- response , err := c .executionModule .InsertBlocks (ctx , request )
329- if err != nil {
330- return err
331- }
332- retryInterval := time .NewTicker (retryTimeout )
333- defer retryInterval .Stop ()
334- for response .Result == execution .ExecutionStatus_Busy {
335- select {
336- case <- retryInterval .C :
337- response , err = c .executionModule .InsertBlocks (ctx , request )
338- if err != nil {
339- return err
340- }
341- case <- ctx .Done ():
342- return context .Canceled
343- }
344- }
345- if response .Result != execution .ExecutionStatus_Success {
346- return fmt .Errorf ("insertHeadersAndWait: invalid code recieved from execution module: %s" , response .Result .String ())
347- }
348- return c .InsertBlocksAndWait (ctx , []* types.Block {block })
326+ return c .InsertBlocksAndWait (ctx , blocks )
349327}
350328
351329func (c ChainReaderWriterEth1 ) ValidateChain (ctx context.Context , hash libcommon.Hash , number uint64 ) (execution.ExecutionStatus , * string , libcommon.Hash , error ) {
0 commit comments