Skip to content

Commit

Permalink
fix: truncate last 255 chars of failure_reason
Browse files Browse the repository at this point in the history
  • Loading branch information
bendanzhentan committed Nov 24, 2023
1 parent 14e6d60 commit 17ef561
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/bot/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func ProcessUnprovenBotDelegatedWithdrawals(ctx context.Context, log log.Logger,
return
} else if strings.Contains(err.Error(), "execution reverted") {
// Proven transaction reverted, mark it with the failure reason
result := db.Model(&unproven).Update("failure_reason", err.Error())
result := db.Model(&unproven).Update("failure_reason", truncFailureReason(err.Error()))
if result.Error != nil {
log.Error("failed to update failure reason of l2_contract_events", "error", result.Error)
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func ProcessUnfinalizedBotDelegatedWithdrawals(ctx context.Context, log log.Logg
continue
} else if strings.Contains(err.Error(), "execution reverted") {
// Finalized transaction reverted, mark it with the failure reason
result := db.Model(&unfinalized).Update("failure_reason", err.Error())
result := db.Model(&unfinalized).Update("failure_reason", truncFailureReason(err.Error()))
if result.Error != nil {
log.Error("failed to update failure reason of l2_contract_events", "error", result.Error)
}
Expand Down Expand Up @@ -330,3 +330,14 @@ func queryL2ScannedBlock(db *gorm.DB, cfg *core.Config) (*core.L2ScannedBlock, e
}
return &l2ScannedBlock, nil
}

// NOTE: types.L2ContractEvent.FailureReason is defined as `type:varchar(256)` in database.
func truncFailureReason(reason string) string {
const maxFailureReasonLength = 255

if len(reason) < maxFailureReasonLength {
return reason
} else {
return reason[len(reason)-maxFailureReasonLength:]
}
}

0 comments on commit 17ef561

Please sign in to comment.