Skip to content

Commit c69f27e

Browse files
authored
Loggable send TX results (#96)
1 parent 19321a9 commit c69f27e

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

multinode/transaction_sender.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (txSender *TransactionSender[TX, RESULT, CHAIN_ID, RPC]) reportSendTxAnomal
194194

195195
_, criticalErr := aggregateTxResults(resultsByCode)
196196
if criticalErr != nil {
197-
txSender.lggr.Criticalw("observed invariant violation on SendTransaction", "tx", tx, "resultsByCode", resultsByCode, "err", criticalErr)
197+
txSender.lggr.Criticalw("observed invariant violation on SendTransaction", "tx", tx, "resultsByCode", loggableSendTxResults(resultsByCode), "err", criticalErr)
198198
ctx, cancel := txSender.chStop.NewCtx()
199199
defer cancel()
200200
txSender.metrics.IncrementInvariantViolations(ctx, criticalErr.Error())
@@ -203,6 +203,26 @@ func (txSender *TransactionSender[TX, RESULT, CHAIN_ID, RPC]) reportSendTxAnomal
203203

204204
type sendTxResults[RESULT any] map[SendTxReturnCode][]sendTxResult[RESULT]
205205

206+
// loggableSendTxResults formats sendTxResults for logging so nested errors are
207+
// string messages instead of opaque pointer addresses in log sinks.
208+
func loggableSendTxResults[RESULT any](in sendTxResults[RESULT]) map[SendTxReturnCode][]map[string]any {
209+
out := make(map[SendTxReturnCode][]map[string]any, len(in))
210+
for code, results := range in {
211+
for _, r := range results {
212+
errStr := ""
213+
if r.error != nil {
214+
errStr = r.error.Error()
215+
}
216+
out[code] = append(out[code], map[string]any{
217+
"res": r.res,
218+
"code": r.code,
219+
"error": errStr,
220+
})
221+
}
222+
}
223+
return out
224+
}
225+
206226
func aggregateTxResults[RESULT any](resultsByCode sendTxResults[RESULT]) (result sendTxResult[RESULT], criticalErr error) {
207227
severeErrors, hasSevereErrors := findFirstIn(resultsByCode, sendTxSevereErrors)
208228
successResults, hasSuccess := findFirstIn(resultsByCode, sendTxSuccessfulCodes)
@@ -242,7 +262,7 @@ loop:
242262
for {
243263
select {
244264
case <-ctx.Done():
245-
txSender.lggr.Debugw("Failed to collect of the results before context was done", "tx", tx, "errorsByCode", errorsByCode)
265+
txSender.lggr.Debugw("Failed to collect of the results before context was done", "tx", tx, "errorsByCode", loggableSendTxResults(errorsByCode))
246266
err := ctx.Err()
247267
return emptyResult, txSender.classifyErr(err), err
248268
case r := <-txResults:
@@ -267,7 +287,7 @@ loop:
267287

268288
// ignore critical error as it's reported in reportSendTxAnomalies
269289
result, _ := aggregateTxResults(errorsByCode)
270-
txSender.lggr.Debugw("Collected results", "errorsByCode", errorsByCode, "result", result)
290+
txSender.lggr.Debugw("Collected results", "errorsByCode", loggableSendTxResults(errorsByCode), "result", result)
271291
return result.res, result.code, result.error
272292
}
273293

0 commit comments

Comments
 (0)