Skip to content

Commit 710d5a7

Browse files
authored
Add TracingID (#90)
1 parent e8bc2c7 commit 710d5a7

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

chains/txmgr/broadcaster.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,9 @@ func (eb *Broadcaster[CID, HEAD, ADDR, THASH, BHASH, SEQ, FEE]) handleInProgress
463463
}
464464

465465
lgr := etx.GetLogger(logger.With(eb.lggr, "fee", attempt.TxFee))
466-
lgr.Infow("Sending transaction", "txAttemptID", attempt.ID, "txHash", attempt.Hash, "meta", etx.Meta, "feeLimit", attempt.ChainSpecificFeeLimit, "callerProvidedFeeLimit", etx.FeeLimit, "attempt", attempt, "etx", etx)
467466
errType, err := eb.client.SendTransactionReturnCode(ctx, etx, attempt, lgr)
467+
lgr.Infow("Broadcasted transaction", "txAttemptID", attempt.ID, "txHash", attempt.Hash, "tracingID", etx.GetTracingID(lgr), "meta", etx.Meta, "feeLimit",
468+
attempt.ChainSpecificFeeLimit, "callerProvidedFeeLimit", etx.FeeLimit, "attempt", attempt, "etxID", etx.ID, "etx", etx, "errType", errType, "err", err)
468469

469470
// The validation below is only applicable to Hedera because it has instant finality and a unique sequence behavior
470471
if eb.chainType == hederaChainType {

chains/txmgr/confirmer.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ func (ec *Confirmer[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) ProcessIncluded
347347
continue
348348
}
349349
confirmedTxIDs = append(confirmedTxIDs, tx.ID)
350+
ec.lggr.Infow("Transaction confirmed", "etxID", tx.ID, "tracingID", tx.GetTracingID(ec.lggr))
350351
observeUntilTxConfirmed(ctx, ec.metrics, tx, head)
351352
}
352353
// Mark the transactions included on-chain with a purge attempt as fatal error with the terminally stuck error message
@@ -796,12 +797,14 @@ func (ec *Confirmer[CID, HEAD, ADDR, THASH, BHASH, R, SEQ, FEE]) ForceRebroadcas
796797
continue
797798
}
798799
attempt.Tx = *etx // for logging
799-
ec.lggr.Debugw("Sending transaction", "txAttemptID", attempt.ID, "txHash", attempt.Hash, "err", err, "meta", etx.Meta, "feeLimit", attempt.ChainSpecificFeeLimit, "callerProvidedFeeLimit", etx.FeeLimit, "attempt", attempt)
800-
if errCode, err := ec.client.SendTransactionReturnCode(ctx, *etx, attempt, ec.lggr); errCode != multinode.Successful && err != nil {
801-
ec.lggr.Errorw(fmt.Sprintf("ForceRebroadcast: failed to rebroadcast tx %v with sequence %v, gas limit %v, and caller provided fee Limit %v : %s", etx.ID, *etx.Sequence, attempt.ChainSpecificFeeLimit, etx.FeeLimit, err.Error()), "err", err, "fee", attempt.TxFee)
802-
continue
800+
errType, err := ec.client.SendTransactionReturnCode(ctx, *etx, attempt, ec.lggr)
801+
if errType == multinode.Successful || errType == multinode.TransactionAlreadyKnown {
802+
ec.lggr.Infow("ForceRebroadcast: Broadcasted transaction", "txAttemptID", attempt.ID, "txHash", attempt.Hash, "tracingID", etx.GetTracingID(ec.lggr), "meta", etx.Meta, "feeLimit",
803+
attempt.ChainSpecificFeeLimit, "callerProvidedFeeLimit", etx.FeeLimit, "attempt", attempt, "etxID", etx.ID, "etx", etx, "errType", errType, "err", err)
804+
} else {
805+
ec.lggr.Errorw("ForceRebroadcast: Broadcasted transaction", "txAttemptID", attempt.ID, "txHash", attempt.Hash, "tracingID", etx.GetTracingID(ec.lggr), "meta", etx.Meta, "feeLimit",
806+
attempt.ChainSpecificFeeLimit, "callerProvidedFeeLimit", etx.FeeLimit, "attempt", attempt, "etxID", etx.ID, "etx", etx, "errType", errType, "err", err)
803807
}
804-
ec.lggr.Infof("ForceRebroadcast: successfully rebroadcast tx %v with hash: 0x%x", etx.ID, attempt.Hash)
805808
}
806809
}
807810
return nil

chains/txmgr/types/tx.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ type TxMeta[ADDR chains.Hashable, TX_HASH chains.Hashable] struct {
163163
// Dual Broadcast
164164
DualBroadcast *bool `json:"DualBroadcast,omitempty"`
165165
DualBroadcastParams *string `json:"DualBroadcastParams,omitempty"`
166+
167+
// TracingID is used for tracing the entire lifecycle of a transaction from OCR Transmit to confirmation on-chain.
168+
TracingID *string `json:"TracingID,omitempty"`
166169
}
167170

168171
type TxAttempt[
@@ -263,6 +266,18 @@ func (e *Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) GetMeta() (*TxMeta[A
263266
return &m, nil
264267
}
265268

269+
func (e *Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) GetTracingID(lgr logger.Logger) string {
270+
meta, err := e.GetMeta()
271+
if err != nil {
272+
lgr.Errorw("failed to get meta of the transaction", "err", err)
273+
return ""
274+
}
275+
if meta == nil || meta.TracingID == nil {
276+
return ""
277+
}
278+
return *meta.TracingID
279+
}
280+
266281
// GetLogger returns a new logger with metadata fields.
267282
func (e *Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) GetLogger(lgr logger.Logger) logger.SugaredLogger {
268283
lgr = logger.With(lgr,

0 commit comments

Comments
 (0)