Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Dec 16, 2024
1 parent 6c8aa77 commit a27e0a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
8 changes: 6 additions & 2 deletions block/produce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 18 additions & 7 deletions block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit a27e0a9

Please sign in to comment.