diff --git a/block/produce.go b/block/produce.go index fad7b362c..d622a1866 100644 --- a/block/produce.go +++ b/block/produce.go @@ -82,9 +82,13 @@ func (m *Manager) ProduceBlockLoop(ctx context.Context, bytesProducedC chan int) return nil case bytesProducedC <- bytesProducedN: default: - evt := &events.DataHealthStatus{Error: fmt.Errorf("Block production paused. Time between last block produced and last block submitted higher than max skew time: %s last block in settlement time: %s %w", m.Conf.MaxSkewTime, m.GetLastBlockInSettlementTime(), gerrc.ErrResourceExhausted)} + lastBlockTimeInSettlement, err := m.GetLastBlockInSettlementTime() + if err != nil { + m.logger.Error("Unable to get last block in settlement time") + } + evt := &events.DataHealthStatus{Error: fmt.Errorf("Block production paused. Time between last block produced and last block submitted higher than max skew time: %s last block in settlement time: %s %w", m.Conf.MaxSkewTime, lastBlockTimeInSettlement, gerrc.ErrResourceExhausted)} uevent.MustPublish(ctx, m.Pubsub, evt, events.HealthStatusList) - m.logger.Error("Pausing block production until new batch is submitted.", "Batch skew time", m.GetBatchSkewTime(), "Max batch skew time", m.Conf.MaxSkewTime, "Last block in settlement time", m.GetLastBlockInSettlementTime()) + m.logger.Error("Pausing block production until new batch is submitted.", "Batch skew time", m.GetBatchSkewTime(), "Max batch skew time", m.Conf.MaxSkewTime, "Last block in settlement time", lastBlockTimeInSettlement) select { case <-ctx.Done(): return nil diff --git a/block/submit.go b/block/submit.go index 41da8192e..8409cb696 100644 --- a/block/submit.go +++ b/block/submit.go @@ -311,16 +311,23 @@ func (m *Manager) UpdateLastSubmittedHeight(event pubsub.Message) { } } -func (m *Manager) GetLastBlockInSettlementTime() time.Time { +func (m *Manager) GetLastBlockInSettlementTime() (time.Time, error) { lastBlockInSettlement, err := m.Store.LoadBlock(m.LastSettlementHeight.Load()) - if err != nil { + if err != nil && !errors.Is(err, gerrc.ErrNotFound) { + return time.Time{}, err + } + if errors.Is(err, gerrc.ErrNotFound) { firstBlock, err := m.Store.LoadBlock(uint64(m.Genesis.InitialHeight)) - if err != nil { - return time.Now() + if err != nil && !errors.Is(err, gerrc.ErrNotFound) { + return time.Time{}, err + } + if errors.Is(err, gerrc.ErrNotFound) { + return time.Now(), nil } - return firstBlock.Header.GetTimestamp() + return firstBlock.Header.GetTimestamp(), nil + } - return lastBlockInSettlement.Header.GetTimestamp() + return lastBlockInSettlement.Header.GetTimestamp(), nil } // GetBatchSkewTime returns the time between the last produced block and the last block submitted to SL @@ -329,7 +336,11 @@ func (m *Manager) GetBatchSkewTime() time.Duration { if err != nil { return 0 } - return lastBlockProduced.Header.GetTimestamp().Sub(m.GetLastBlockInSettlementTime()) + lastBlockInSettlementTime, err := m.GetLastBlockInSettlementTime() + if err != nil { + return 0 + } + return lastBlockProduced.Header.GetTimestamp().Sub(lastBlockInSettlementTime) } func UpdateBatchSubmissionGauges(skewBytes uint64, skewBlocks uint64, skewTime time.Duration) {