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
16 changes: 15 additions & 1 deletion block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ const defaultDABlockTime = 30 * time.Second

// maxSubmitAttempts defines how many times Optimint will re-try to publish block to DA layer.
// This is temporary solution. It will be removed in future versions.
const maxSubmitAttempts = 10
const maxSubmitAttempts = 30

// initialBackoff defines initial value for block submission backoff
var initialBackoff = 100 * time.Millisecond

type newBlockEvent struct {
block *types.Block
Expand Down Expand Up @@ -395,13 +398,16 @@ func (m *Manager) submitBlockToDA(ctx context.Context, block *types.Block) error
m.logger.Debug("submitting block to DA layer", "height", block.Header.Height)

submitted := false
backoff := initialBackoff
for attempt := 1; ctx.Err() == nil && !submitted && attempt <= maxSubmitAttempts; attempt++ {
res := m.dalc.SubmitBlock(block)
if res.Code == da.StatusSuccess {
m.logger.Info("successfully submitted optimint block to DA layer", "optimintHeight", block.Header.Height, "daHeight", res.DAHeight)
submitted = true
} else {
m.logger.Error("DA layer submission failed", "error", res.Message, "attempt", attempt)
time.Sleep(backoff)
backoff = m.exponentialBackoff(backoff)
}
}

Expand All @@ -415,6 +421,14 @@ func (m *Manager) submitBlockToDA(ctx context.Context, block *types.Block) error
return nil
}

func (m *Manager) exponentialBackoff(backoff time.Duration) time.Duration {
backoff *= 2
if backoff > m.conf.DABlockTime {
backoff = m.conf.DABlockTime
}
return backoff
}

func (m *Manager) publishHeader(block *types.Block) {
m.HeaderOutCh <- &block.Header
}
Expand Down
3 changes: 2 additions & 1 deletion da/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package celestia
import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/gogo/protobuf/proto"
Expand Down Expand Up @@ -81,7 +82,7 @@ func (c *DataAvailabilityLayerClient) SubmitBlock(block *types.Block) da.ResultS
return da.ResultSubmitBlock{
DAResult: da.DAResult{
Code: da.StatusError,
Message: txResponse.RawLog,
Message: fmt.Sprintf("Codespace: '%s', Code: %d, Message: %s", txResponse.Codespace, txResponse.Code, txResponse.RawLog),
},
}
}
Expand Down