From 33845160858882ebd02dff6fe0ee013791b50d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zdyba=C5=82?= Date: Sat, 4 Jun 2022 01:06:47 +0200 Subject: [PATCH] feat: improved block submission error handling --- block/manager.go | 16 +++++++++++++++- da/celestia/celestia.go | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/block/manager.go b/block/manager.go index e2e8f07685..47be36aa65 100644 --- a/block/manager.go +++ b/block/manager.go @@ -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 @@ -395,6 +398,7 @@ 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 { @@ -402,6 +406,8 @@ func (m *Manager) submitBlockToDA(ctx context.Context, block *types.Block) error submitted = true } else { m.logger.Error("DA layer submission failed", "error", res.Message, "attempt", attempt) + time.Sleep(backoff) + backoff = m.exponentialBackoff(backoff) } } @@ -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 } diff --git a/da/celestia/celestia.go b/da/celestia/celestia.go index c24d08e026..2dbe09c55a 100644 --- a/da/celestia/celestia.go +++ b/da/celestia/celestia.go @@ -3,6 +3,7 @@ package celestia import ( "context" "encoding/json" + "fmt" "time" "github.com/gogo/protobuf/proto" @@ -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), }, } }