@@ -15,17 +15,18 @@ const (
1515 noGasPrice = - 1
1616)
1717
18-
19- type RetryStrategy struct {
18+ // retryStrategy manages retry logic with backoff and gas price adjustments for DA submissions
19+ type retryStrategy struct {
2020 attempt int
2121 backoff time.Duration
2222 gasPrice float64
2323 initialGasPrice float64
2424 maxAttempts int
2525}
2626
27- func NewRetryStrategy (initialGasPrice float64 ) * RetryStrategy {
28- return & RetryStrategy {
27+ // newRetryStrategy creates a new retryStrategy with the given initial gas price
28+ func newRetryStrategy (initialGasPrice float64 ) * retryStrategy {
29+ return & retryStrategy {
2930 attempt : 0 ,
3031 backoff : 0 ,
3132 gasPrice : initialGasPrice ,
@@ -34,27 +35,32 @@ func NewRetryStrategy(initialGasPrice float64) *RetryStrategy {
3435 }
3536}
3637
37- func (r * RetryStrategy ) ShouldContinue () bool {
38+ // ShouldContinue returns true if the retry strategy should continue attempting submissions
39+ func (r * retryStrategy ) ShouldContinue () bool {
3840 return r .attempt < r .maxAttempts
3941}
4042
41- func (r * RetryStrategy ) NextAttempt () {
43+ // NextAttempt increments the attempt counter
44+ func (r * retryStrategy ) NextAttempt () {
4245 r .attempt ++
4346}
4447
45- func (r * RetryStrategy ) ResetOnSuccess (gasMultiplier float64 ) {
48+ // ResetOnSuccess resets backoff and adjusts gas price downward after a successful submission
49+ func (r * retryStrategy ) ResetOnSuccess (gasMultiplier float64 ) {
4650 r .backoff = 0
4751 if gasMultiplier > 0 && r .gasPrice != noGasPrice {
4852 r .gasPrice = r .gasPrice / gasMultiplier
4953 r .gasPrice = max (r .gasPrice , r .initialGasPrice )
5054 }
5155}
5256
53- func (r * RetryStrategy ) BackoffOnFailure (m * Manager ) {
57+ // BackoffOnFailure applies exponential backoff after a submission failure
58+ func (r * retryStrategy ) BackoffOnFailure (m * Manager ) {
5459 r .backoff = m .exponentialBackoff (r .backoff )
5560}
5661
57- func (r * RetryStrategy ) BackoffOnMempool (mempoolTTL int , blockTime time.Duration , gasMultiplier float64 ) {
62+ // BackoffOnMempool applies mempool-specific backoff and increases gas price when transaction is stuck in mempool
63+ func (r * retryStrategy ) BackoffOnMempool (mempoolTTL int , blockTime time.Duration , gasMultiplier float64 ) {
5864 r .backoff = blockTime * time .Duration (mempoolTTL )
5965 if gasMultiplier > 0 && r .gasPrice != noGasPrice {
6066 r .gasPrice = r .gasPrice * gasMultiplier
@@ -75,7 +81,7 @@ func handleSuccessfulSubmission[T any](
7581 marshaled [][]byte ,
7682 res * coreda.ResultSubmit ,
7783 postSubmit func ([]T , * coreda.ResultSubmit , float64 ),
78- retryStrategy * RetryStrategy ,
84+ retryStrategy * retryStrategy ,
7985 itemType string ,
8086) SubmissionOutcome [T ] {
8187 m .recordDAMetrics ("submission" , DAModeSuccess )
@@ -111,7 +117,7 @@ func handleSuccessfulSubmission[T any](
111117func handleMempoolFailure (
112118 m * Manager ,
113119 res * coreda.ResultSubmit ,
114- retryStrategy * RetryStrategy ,
120+ retryStrategy * retryStrategy ,
115121 attempt int ,
116122) {
117123 m .logger .Error ("DA layer submission failed" ,
@@ -131,7 +137,7 @@ func handleTooBigError[T any](
131137 ctx context.Context ,
132138 remaining []T ,
133139 marshaled [][]byte ,
134- retryStrategy * RetryStrategy ,
140+ retryStrategy * retryStrategy ,
135141 postSubmit func ([]T , * coreda.ResultSubmit , float64 ),
136142 itemType string ,
137143 attempt int ,
@@ -178,7 +184,7 @@ func handleTooBigError[T any](
178184func handleGenericFailure (
179185 m * Manager ,
180186 res * coreda.ResultSubmit ,
181- retryStrategy * RetryStrategy ,
187+ retryStrategy * retryStrategy ,
182188 attempt int ,
183189) {
184190 m .logger .Error ("DA layer submission failed" ,
@@ -269,7 +275,7 @@ func submitToDA[T any](
269275 return err
270276 }
271277
272- retryStrategy := NewRetryStrategy (m .gasPrice )
278+ retryStrategy := newRetryStrategy (m .gasPrice )
273279 remaining := items
274280 numSubmitted := 0
275281
@@ -341,7 +347,7 @@ func handleSubmissionResult[T any](
341347 res coreda.ResultSubmit ,
342348 remaining []T ,
343349 marshaled [][]byte ,
344- retryStrategy * RetryStrategy ,
350+ retryStrategy * retryStrategy ,
345351 postSubmit func ([]T , * coreda.ResultSubmit , float64 ),
346352 itemType string ,
347353) SubmissionOutcome [T ] {
0 commit comments