Skip to content

Commit

Permalink
Improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dimriou committed Dec 2, 2024
1 parent 7b0a1d1 commit 5f55245
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
5 changes: 3 additions & 2 deletions core/chains/evm/txm/txm.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (t *Txm) sendTransactionWithError(ctx context.Context, tx *types.Transactio
start := time.Now()
txErr := t.client.SendTransaction(ctx, tx, attempt)
tx.AttemptCount++
t.lggr.Infow("Broadcasted attempt", "tx", tx, "attempt", attempt, "duration", time.Since(start), "txErr: ", txErr)
t.lggr.Infow("Broadcasted attempt", "tx", tx.PrettyPrint(), "attempt", attempt.PrettyPrint(), "duration", time.Since(start), "txErr: ", txErr)
if txErr != nil && t.errorHandler != nil {
if err = t.errorHandler.HandleError(tx, txErr, t.attemptBuilder, t.client, t.txStore, t.setNonce, false); err != nil {
return
Expand Down Expand Up @@ -410,7 +410,8 @@ func (t *Txm) backfillTransactions(ctx context.Context, address common.Address)
if tx.AttemptCount >= maxAllowedAttempts {
return true, fmt.Errorf("reached max allowed attempts for txID: %d. TXM won't broadcast any more attempts."+
"If this error persists, it means the transaction won't be confirmed and the TXM needs to be restarted."+
"Look for any error messages from previous attempts that may indicate why this happened, i.e. wallet is out of funds. Tx: %v", tx.ID, tx)
"Look for any error messages from previous broadcasted attempts that may indicate why this happened, i.e. wallet is out of funds. Tx: %v", tx.ID,
tx.PrettyPrintWithAttempts())
}

if time.Since(tx.LastBroadcastAt) > (t.config.BlockTime*time.Duration(t.config.RetryBlockThreshold)) || tx.LastBroadcastAt.IsZero() {
Expand Down
29 changes: 20 additions & 9 deletions core/chains/evm/txm/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,24 @@ type Transaction struct {
CallbackCompleted bool
}

// func (t *Transaction) String() string {
// return fmt.Sprintf(`{"ID":%d, "IdempotencyKey":%v, "ChainID":%v, "Nonce":%d, "FromAddress":%v, "ToAddress":%v, "Value":%v, `+
// `"Data":%v, "SpecifiedGasLimit":%d, "CreatedAt":%v, "LastBroadcastAt":%v, "State":%v, "IsPurgeable":%v, "AttemptCount":%d, `+
// `"Meta":%v, "Subject":%v, "PipelineTaskRunID":%v, "MinConfirmations":%v, "SignalCallback":%v, "CallbackCompleted":%v`,
// t.ID, *t.IdempotencyKey, t.ChainID, t.Nonce, t.FromAddress, t.ToAddress, t.Value, t.Data, t.SpecifiedGasLimit, t.CreatedAt, t.LastBroadcastAt,
// t.State, t.IsPurgeable, t.AttemptCount, t.Meta, t.Subject, t.PipelineTaskRunID, t.MinConfirmations, t.SignalCallback, t.CallbackCompleted)
// }
func (t *Transaction) PrettyPrint() string {
return fmt.Sprintf(`{txID:%d, IdempotencyKey:%v, ChainID:%v, Nonce:%d, FromAddress:%v, ToAddress:%v, Value:%v, `+
`Data:%v, SpecifiedGasLimit:%d, CreatedAt:%v, InitialBroadcastAt:%v, LastBroadcastAt:%v, State:%v, IsPurgeable:%v, AttemptCount:%d, `+
`Meta:%v, Subject:%v}`,
t.ID, *t.IdempotencyKey, t.ChainID, t.Nonce, t.FromAddress, t.ToAddress, t.Value, t.Data, t.SpecifiedGasLimit, t.CreatedAt, t.InitialBroadcastAt,
t.LastBroadcastAt, t.State, t.IsPurgeable, t.AttemptCount, t.Meta, t.Subject)
}

func (t *Transaction) PrettyPrintWithAttempts() string {
attempts := " Attempts: ["
for _, a := range t.Attempts {
attempts += a.PrettyPrint() + ", "
}
attempts += "]"

return t.PrettyPrint() + attempts
}

func (t *Transaction) FindAttemptByHash(attemptHash common.Hash) (*Attempt, error) {
for _, a := range t.Attempts {
if a.Hash == attemptHash {
Expand Down Expand Up @@ -117,8 +128,8 @@ func (a *Attempt) DeepCopy() *Attempt {
return &txCopy
}

func (a *Attempt) String() string {
return fmt.Sprintf(`{"ID":%d, "TxID":%d, "Hash":%v, "Fee":%v, "GasLimit":%d, "Type":%v, "CreatedAt":%v, "BroadcastAt":%v}`,
func (a *Attempt) PrettyPrint() string {
return fmt.Sprintf(`{ID:%d, TxID:%d, Hash:%v, Fee:%v, GasLimit:%d, Type:%v, CreatedAt:%v, BroadcastAt:%v}`,
a.ID, a.TxID, a.Hash, a.Fee, a.GasLimit, a.Type, a.CreatedAt, a.BroadcastAt)
}

Expand Down

0 comments on commit 5f55245

Please sign in to comment.