Skip to content

Commit

Permalink
chore(ARCO-194): add logs for debugging on server
Browse files Browse the repository at this point in the history
  • Loading branch information
pawellewandowski98 committed Nov 26, 2024
1 parent 7c21db8 commit fb84e45
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/metamorph/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,10 @@ func (p *Processor) StartProcessStatusUpdatesInStorage() {
return
case statusUpdate := <-p.storageStatusUpdateCh:
// Ensure no duplicate statuses
p.logger.Info("Status update received", slog.String("hash", statusUpdate.Hash.String()), slog.String("status", statusUpdate.Status.String()))
err := p.updateStatusMap(statusUpdate)
if err != nil {
p.logger.Error("failed to update status", slog.String("err", err.Error()))
p.logger.Error("failed to update status", slog.String("err", err.Error()), slog.String("hash", statusUpdate.Hash.String()))
return
}

Expand All @@ -428,6 +429,7 @@ func (p *Processor) StartProcessStatusUpdatesInStorage() {
}

if statusUpdateCount >= p.processStatusUpdatesBatchSize {
p.logger.Info("Status update count is greater than batch size", slog.Int("count", statusUpdateCount), slog.Int("batch_size", p.processStatusUpdatesBatchSize))
err := p.checkAndUpdate(ctx)
if err != nil {
p.logger.Error("failed to check and update statuses", slog.String("err", err.Error()))
Expand All @@ -436,6 +438,8 @@ func (p *Processor) StartProcessStatusUpdatesInStorage() {
// Reset ticker to delay the next tick, ensuring the interval starts after the batch is processed.
// This prevents unnecessary immediate updates and maintains the intended time interval between batches.
ticker.Reset(p.processStatusUpdatesInterval)
} else {
p.logger.Debug("Status update count is less than batch size", slog.Int("count", statusUpdateCount), slog.Int("batch_size", p.processStatusUpdatesBatchSize))
}
case <-ticker.C:
statusUpdateCount, err := p.getStatusUpdateCount()
Expand Down Expand Up @@ -466,12 +470,15 @@ func (p *Processor) checkAndUpdate(ctx context.Context) error {
tracing.EndTracing(span, err)
}()

p.logger.Info("checkAndUpdate - Checking and updating statuses")

statusUpdatesMap, err := p.getAndDeleteAllTransactionStatuses()
if err != nil {
return err
}

if len(statusUpdatesMap) == 0 {
p.logger.Info("checkAndUpdate - No statuses to update")
return nil
}

Expand All @@ -480,8 +487,10 @@ func (p *Processor) checkAndUpdate(ctx context.Context) error {

for _, status := range statusUpdatesMap {
if len(status.CompetingTxs) > 0 {
p.logger.Info("checkAndUpdate - Double spend detected", slog.String("hash", status.Hash.String()))
doubleSpendUpdates = append(doubleSpendUpdates, status)
} else {
p.logger.Info("checkAndUpdate - Status update", slog.String("hash", status.Hash.String()), slog.String("status", status.Status.String()))
statusUpdates = append(statusUpdates, status)
}
}
Expand Down
5 changes: 5 additions & 0 deletions internal/metamorph/processor_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,29 @@ func (p *Processor) updateStatusMap(statusUpdate store.UpdateStatus) error {
currentStatusUpdate, err := p.getTransactionStatus(statusUpdate.Hash)
if err != nil {
if errors.Is(err, cache.ErrCacheNotFound) {
p.logger.Info("updateStatusMap - status record not found, creating new one", slog.String("hash", statusUpdate.Hash.String()))
// if record doesn't exist, save new one
return p.setTransactionStatus(statusUpdate)
}
return err
}

if shouldUpdateCompetingTxs(statusUpdate, *currentStatusUpdate) {
p.logger.Info("updateStatusMap - updating competing txs", slog.String("hash", statusUpdate.Hash.String()))
currentStatusUpdate.CompetingTxs = mergeUnique(statusUpdate.CompetingTxs, currentStatusUpdate.CompetingTxs)
}

if shouldUpdateStatus(statusUpdate, *currentStatusUpdate) {
p.logger.Info("updateStatusMap - updating status", slog.String("hash", statusUpdate.Hash.String()), slog.String("old_status", currentStatusUpdate.Status.String()), slog.String("new_status", statusUpdate.Status.String()))
currentStatusUpdate.Status = statusUpdate.Status
statusUpdate.StatusHistory = append(currentStatusUpdate.StatusHistory, store.StatusWithTimestamp{
Status: statusUpdate.Status,
Timestamp: p.now(),
})
}

p.logger.Info("updateStatusMap - updating status in cache", slog.String("hash", statusUpdate.Hash.String()), slog.String("status", statusUpdate.Status.String()), slog.Any("status_history", statusUpdate.StatusHistory))

return p.setTransactionStatus(*currentStatusUpdate)
}

Expand Down

0 comments on commit fb84e45

Please sign in to comment.