Skip to content

Commit efab9d2

Browse files
authored
Refactor: remove time.Sleep() in SubmitBlocksToDA for loop (#1606)
closes #1602 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved the retry logic for submitting blocks, enhancing the efficiency and reliability of block submission processes. - Revised handling of submission statuses to adjust gas prices, block sizes, and retry behavior based on response from the DA layer. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent be8c028 commit efab9d2

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

block/manager.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ func (m *Manager) recordMetrics(block *types.Block) {
873873

874874
func (m *Manager) submitBlocksToDA(ctx context.Context) error {
875875
submittedAllBlocks := false
876-
backoff := initialBackoff
876+
var backoff time.Duration
877877
blocksToSubmit, err := m.pendingBlocks.getPendingBlocks(ctx)
878878
if len(blocksToSubmit) == 0 {
879879
// There are no pending blocks; return because there's nothing to do, but:
@@ -897,7 +897,15 @@ func (m *Manager) submitBlocksToDA(ctx context.Context) error {
897897
initialMaxBlobSize := maxBlobSize
898898
initialGasPrice := m.dalc.GasPrice
899899
gasPrice := m.dalc.GasPrice
900-
for ctx.Err() == nil && !submittedAllBlocks && attempt < maxSubmitAttempts {
900+
901+
daSubmitRetryLoop:
902+
for !submittedAllBlocks && attempt < maxSubmitAttempts {
903+
select {
904+
case <-ctx.Done():
905+
break daSubmitRetryLoop
906+
case <-time.After(backoff):
907+
}
908+
901909
res := m.dalc.SubmitBlocks(ctx, blocksToSubmit, maxBlobSize, gasPrice)
902910
switch res.Code {
903911
case da.StatusSuccess:
@@ -918,7 +926,7 @@ func (m *Manager) submitBlocksToDA(ctx context.Context) error {
918926
blocksToSubmit = notSubmittedBlocks
919927
// reset submission options when successful
920928
// scale back gasPrice gradually
921-
backoff = initialBackoff
929+
backoff = 0
922930
maxBlobSize = initialMaxBlobSize
923931
if m.dalc.GasMultiplier > 0 && gasPrice != -1 {
924932
gasPrice = gasPrice / m.dalc.GasMultiplier
@@ -934,18 +942,15 @@ func (m *Manager) submitBlocksToDA(ctx context.Context) error {
934942
gasPrice = gasPrice * m.dalc.GasMultiplier
935943
}
936944
m.logger.Info("retrying DA layer submission with", "backoff", backoff, "gasPrice", gasPrice, "maxBlobSize", maxBlobSize)
937-
time.Sleep(backoff)
938-
backoff = m.exponentialBackoff(backoff)
945+
939946
case da.StatusTooBig:
940-
m.logger.Error("DA layer submission failed", "error", res.Message, "attempt", attempt)
941947
maxBlobSize = maxBlobSize / 4
942-
time.Sleep(backoff)
943-
backoff = m.exponentialBackoff(backoff)
948+
fallthrough
944949
default:
945950
m.logger.Error("DA layer submission failed", "error", res.Message, "attempt", attempt)
946-
time.Sleep(backoff)
947951
backoff = m.exponentialBackoff(backoff)
948952
}
953+
949954
attempt += 1
950955
}
951956

@@ -962,6 +967,9 @@ func (m *Manager) submitBlocksToDA(ctx context.Context) error {
962967

963968
func (m *Manager) exponentialBackoff(backoff time.Duration) time.Duration {
964969
backoff *= 2
970+
if backoff == 0 {
971+
backoff = initialBackoff
972+
}
965973
if backoff > m.conf.DABlockTime {
966974
backoff = m.conf.DABlockTime
967975
}

0 commit comments

Comments
 (0)