From 6e3e64862df688b420bf252f630bcc8bd23c0ce3 Mon Sep 17 00:00:00 2001 From: bdchatham Date: Tue, 14 Apr 2026 10:56:00 -0700 Subject: [PATCH] fix: deduplicate block fetch in getTransactionReceipt getTransactionReceipt fetched the same block twice: once inside the ante-failure branch (Status==0 && GasUsed==0) to recover sender info, and again unconditionally for receipt encoding. Hoist the single fetch above the branch so both paths share it, eliminating the redundant block store lookup on every receipt query that hits the ante-failure path. Co-Authored-By: Claude Opus 4.6 (1M context) --- evmrpc/tx.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/evmrpc/tx.go b/evmrpc/tx.go index c260b2a77c..6a1d58cbad 100644 --- a/evmrpc/tx.go +++ b/evmrpc/tx.go @@ -132,16 +132,17 @@ func getTransactionReceipt( } return nil, err } + // Fetch block once — used both for ante-failure receipt population and encoding. + height := int64(receipt.BlockNumber) //nolint:gosec + block, err := blockByNumberRespectingWatermarks(ctx, t.tmClient, t.watermarks, &height, 1) + if err != nil { + return nil, err + } + // Fill in the receipt if the transaction has failed and used 0 gas // This case is for when a tx fails before it makes it to the VM if receipt.Status == 0 && receipt.GasUsed == 0 { receipt = cloneReceiptForMutation(receipt) - // Get the block - height := int64(receipt.BlockNumber) //nolint:gosec - block, err := blockByNumberRespectingWatermarks(ctx, t.tmClient, t.watermarks, &height, 1) - if err != nil { - return nil, err - } // Find the transaction in the block for _, tx := range block.Block.Txs { @@ -168,11 +169,6 @@ func getTransactionReceipt( } } } - height := int64(receipt.BlockNumber) //nolint:gosec - block, err := blockByNumberRespectingWatermarks(ctx, t.tmClient, t.watermarks, &height, 1) - if err != nil { - return nil, err - } return encodeReceipt(t.ctxProvider, t.txConfigProvider, receipt, t.keeper, block, includeSynthetic, t.globalBlockCache, t.cacheCreationMutex) }