Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions block/submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func (m *Manager) submitHeadersToDA(ctx context.Context) error {
gasPrice := m.gasPrice
initialGasPrice := gasPrice

daSubmitRetryLoop:
for !submittedAllHeaders && attempt < maxSubmitAttempts {
select {
case <-ctx.Done():
break daSubmitRetryLoop
m.logger.Info("context done, stopping header submission loop")
return nil
case <-time.After(backoff):
}

Expand All @@ -78,9 +78,9 @@ daSubmitRetryLoop:
}
}

ctx, cancel := context.WithTimeout(ctx, 60*time.Second) // TODO: make this configurable
res := types.SubmitWithHelpers(ctx, m.da, m.logger, headersBz, gasPrice, nil)
cancel()
submitctx, submitCtxCancel := context.WithTimeout(ctx, 60*time.Second) // TODO: make this configurable
res := types.SubmitWithHelpers(submitctx, m.da, m.logger, headersBz, gasPrice, nil)
submitCtxCancel()

switch res.Code {
case coreda.StatusSuccess:
Expand Down Expand Up @@ -115,6 +115,9 @@ daSubmitRetryLoop:
gasPrice = gasPrice * m.gasMultiplier
}
m.logger.Info("retrying DA layer submission with", "backoff", backoff, "gasPrice", gasPrice)
case coreda.StatusContextCanceled:
m.logger.Info("DA layer submission canceled", "attempt", attempt)
return nil
default:
m.logger.Error("DA layer submission failed", "error", res.Message, "attempt", attempt)
backoff = m.exponentialBackoff(backoff)
Expand Down Expand Up @@ -175,12 +178,12 @@ func (m *Manager) submitBatchToDA(ctx context.Context, batch coresequencer.Batch
initialGasPrice := m.gasPrice
gasPrice := initialGasPrice

daSubmitRetryLoop:
for !submittedAllTxs && attempt < maxSubmitAttempts {
for attempt < maxSubmitAttempts {
// Wait for backoff duration or exit if context is done
select {
case <-ctx.Done():
break daSubmitRetryLoop
m.logger.Info("context done, stopping batch submission loop")
return nil
case <-time.After(backoff):
}

Expand Down Expand Up @@ -251,12 +254,13 @@ daSubmitRetryLoop:
gasPrice = gasPrice * gasMultiplier
}
m.logger.Info("retrying DA layer submission with", "backoff", backoff, "gasPrice", gasPrice)

case coreda.StatusContextCanceled:
m.logger.Info("DA layer submission canceled due to context cancellation", "attempt", attempt)
return nil
case coreda.StatusTooBig:
// Blob size adjustment is handled within DA impl or SubmitWithOptions call
// fallthrough to default exponential backoff
fallthrough

default:
m.logger.Error("DA layer submission failed", "error", res.Message, "attempt", attempt)
backoff = m.exponentialBackoff(backoff)
Expand Down
1 change: 1 addition & 0 deletions core/da/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const (
StatusContextDeadline
StatusError
StatusIncorrectAccountSequence
StatusContextCanceled
)

// BaseResult contains basic information returned by DA layer.
Expand Down
1 change: 1 addition & 0 deletions core/da/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ var (
ErrTxIncorrectAccountSequence = errors.New("incorrect account sequence")
ErrContextDeadline = errors.New("context deadline")
ErrHeightFromFuture = errors.New("given height is from the future")
ErrContextCanceled = errors.New("context canceled")
)
16 changes: 16 additions & 0 deletions da/jsonrpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (api *API) Get(ctx context.Context, ids []da.ID, _ []byte) ([]da.Blob, erro
api.Logger.Debug("Making RPC call", "method", "Get", "num_ids", len(ids), "namespace", string(api.Namespace))
res, err := api.Internal.Get(ctx, ids, api.Namespace)
if err != nil {
if errors.Is(err, context.Canceled) {
api.Logger.Debug("RPC call canceled due to context cancellation", "method", "Get")
return res, context.Canceled
}
api.Logger.Error("RPC call failed", "method", "Get", "error", err)
// Wrap error for context, potentially using the translated error from the RPC library
return nil, fmt.Errorf("failed to get blobs: %w", err)
Expand All @@ -64,6 +68,10 @@ func (api *API) GetIDs(ctx context.Context, height uint64, _ []byte) (*da.GetIDs
api.Logger.Debug("RPC call indicates height from future", "method", "GetIDs", "height", height)
return nil, err // Return the specific ErrHeightFromFuture
}
if errors.Is(err, context.Canceled) {
api.Logger.Debug("RPC call canceled due to context cancellation", "method", "GetIDs")
return res, context.Canceled
}
api.Logger.Error("RPC call failed", "method", "GetIDs", "error", err)
return nil, err
}
Expand Down Expand Up @@ -119,6 +127,10 @@ func (api *API) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, _
api.Logger.Debug("Making RPC call", "method", "Submit", "num_blobs", len(blobs), "gas_price", gasPrice, "namespace", string(api.Namespace))
res, err := api.Internal.Submit(ctx, blobs, gasPrice, api.Namespace)
if err != nil {
if errors.Is(err, context.Canceled) {
api.Logger.Debug("RPC call canceled due to context cancellation", "method", "Submit")
return res, context.Canceled
}
api.Logger.Error("RPC call failed", "method", "Submit", "error", err)
} else {
api.Logger.Debug("RPC call successful", "method", "Submit", "num_ids_returned", len(res))
Expand Down Expand Up @@ -168,6 +180,10 @@ func (api *API) SubmitWithOptions(ctx context.Context, inputBlobs []da.Blob, gas
api.Logger.Debug("Making RPC call", "method", "SubmitWithOptions", "num_blobs_original", len(inputBlobs), "num_blobs_to_submit", len(blobsToSubmit), "gas_price", gasPrice, "namespace", string(api.Namespace))
res, err := api.Internal.SubmitWithOptions(ctx, blobsToSubmit, gasPrice, api.Namespace, options)
if err != nil {
if errors.Is(err, context.Canceled) {
api.Logger.Debug("RPC call canceled due to context cancellation", "method", "SubmitWithOptions")
return res, context.Canceled
}
api.Logger.Error("RPC call failed", "method", "SubmitWithOptions", "error", err)
} else {
api.Logger.Debug("RPC call successful", "method", "SubmitWithOptions", "num_ids_returned", len(res))
Expand Down
1 change: 1 addition & 0 deletions da/jsonrpc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ func getKnownErrorsMapping() jsonrpc.Errors {
errs.Register(jsonrpc.ErrorCode(coreda.StatusAlreadyInMempool), &coreda.ErrTxAlreadyInMempool)
errs.Register(jsonrpc.ErrorCode(coreda.StatusIncorrectAccountSequence), &coreda.ErrTxIncorrectAccountSequence)
errs.Register(jsonrpc.ErrorCode(coreda.StatusContextDeadline), &coreda.ErrContextDeadline)
errs.Register(jsonrpc.ErrorCode(coreda.StatusContextCanceled), &coreda.ErrContextCanceled)
return errs
}
10 changes: 10 additions & 0 deletions types/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ func SubmitWithHelpers(

// Handle errors returned by SubmitWithOptions
if err != nil {
if errors.Is(err, context.Canceled) {
logger.Debug("DA submission canceled via helper due to context cancellation")
return coreda.ResultSubmit{
BaseResult: coreda.BaseResult{
Code: coreda.StatusContextCanceled,
Message: "submission canceled",
IDs: ids,
},
}
}
status := coreda.StatusError
switch {
case errors.Is(err, coreda.ErrTxTimedOut):
Expand Down