Skip to content

Commit 5d05375

Browse files
committed
fix(tempo/server): log tx hash + receipt detail on chain reverts
The patched chargeserver.verifyTransaction currently swallows the underlying tx hash on broadcast and the revert reason on a non-0x1 receipt. Operators investigating "transaction reverted" failures have no way to inspect the failed tx without code-level instrumentation. This is the same diagnostic gap PR #34 (this PR) closed for the keychain signature path; extending it to broadcast/receipt: - Log txHash on successful broadcast (and on SendRawTransaction failure, with the underlying error). - On a non-0x1 receipt: log status / blockNumber / gasUsed / revertReason and the full receipt map. Surface the revert reason in the response body when the chain provides one. - Log fetchReceipt errors with the txHash for context. Receipt bodies are chain-public; no secrets exposed. Production cost is one extra log line per successful broadcast plus a multi-field log on failure. Mirrored from blockparty-global/sre-services PR #190 + #194.
1 parent d1bcbc5 commit 5d05375

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

pkg/tempo/server/charge.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,13 @@ func (i *Intent) verifyTransaction(
451451

452452
txHash, err := rpc.SendRawTransaction(ctx, serialized)
453453
if err != nil {
454-
return nil, mpp.ErrVerificationFailed("transaction submission failed")
454+
log.Printf("[mpp] verifyTransaction: SendRawTransaction failed: %v", err)
455+
return nil, mpp.ErrVerificationFailed(fmt.Sprintf("transaction submission failed: %v", err))
455456
}
457+
log.Printf("[mpp] verifyTransaction: tx broadcast: hash=%s", txHash)
456458
receiptMap, err := fetchReceipt(ctx, rpc, txHash)
457459
if err != nil {
460+
log.Printf("[mpp] verifyTransaction: fetchReceipt failed: %v (hash=%s)", err, txHash)
458461
return nil, err
459462
}
460463
if !receiptMatches(receiptMap, credential, request, sender.Hex()) {
@@ -539,7 +542,20 @@ func fetchReceipt(ctx context.Context, rpc tempo.RPCClient, hash string) (map[st
539542
if receipt, ok := response.Result.(map[string]any); ok && len(receipt) > 0 {
540543
status := asString(receipt["status"])
541544
if status != "0x1" {
542-
return nil, mpp.ErrVerificationFailed("transaction reverted")
545+
// Surface the on-chain revert reason. Tempo's eth_getTransactionReceipt
546+
// includes status, gasUsed, blockNumber, and any revert reason the chain
547+
// chooses to return. Logging the whole receipt (other than logs[]) gives
548+
// us deterministic context the next time we hit a chain revert.
549+
rev := asString(receipt["revertReason"])
550+
blk := asString(receipt["blockNumber"])
551+
gas := asString(receipt["gasUsed"])
552+
log.Printf("[mpp] fetchReceipt: tx reverted: hash=%s status=%s blockNumber=%s gasUsed=%s revertReason=%q full_receipt=%+v",
553+
hash, status, blk, gas, rev, receipt)
554+
detail := "transaction reverted"
555+
if rev != "" {
556+
detail = fmt.Sprintf("transaction reverted: %s", rev)
557+
}
558+
return nil, mpp.ErrVerificationFailed(detail)
543559
}
544560
return receipt, nil
545561
}

0 commit comments

Comments
 (0)