From 704a6b21c602876220f494b0c9162db364ecca68 Mon Sep 17 00:00:00 2001 From: akirapham Date: Sat, 25 May 2024 05:06:45 +0700 Subject: [PATCH] fix: compute blockGasUsed as actual sum of gas spent by all txes --- src/external/Collector.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/external/Collector.ts b/src/external/Collector.ts index c352aac0..ffb322ad 100644 --- a/src/external/Collector.ts +++ b/src/external/Collector.ts @@ -299,7 +299,6 @@ class Collector extends BaseExternal { /* prettier-ignore */ if (verbose) console.log(`Collector: getBlock blockQuery: ${blockQuery}`) const response = await axios.get(blockQuery).then((response) => response.data) - console.log('blockQuery', blockQuery, response) if (!response.success) return null const { readableBlock, number } = response @@ -329,11 +328,19 @@ class Collector extends BaseExternal { .then((response) => { if (!response.data.success) return [] return response.data.transactions.map((tx: any) => { - const thisDecodeTransaction = this.decodeTransaction(tx) - blockGasUsed = BigNumber.from(blockGasUsed).add(thisDecodeTransaction.gas).toHexString() - //need to review the safety of this for caching and support that this could change! + const decodedTx = this.decodeTransaction(tx) + let gasUsedByThisTx = decodedTx.gas + if ( + tx.wrappedEVMAccount && + tx.wrappedEVMAccount.readableReceipt && + tx.wrappedEVMAccount.readableReceipt.gasUsed + ) { + gasUsedByThisTx = tx.wrappedEVMAccount.readableReceipt.gasUsed + } + blockGasUsed = BigNumber.from(blockGasUsed).add(gasUsedByThisTx).toHexString() + // need to review the safety of this for caching and support that this could change! // UPDATE: We're now handling the response as per the "details" flag by mutating the "transactions" field. The default cache storage contains the full transaction details. - return thisDecodeTransaction + return decodedTx }) }) .catch((e) => { @@ -477,7 +484,6 @@ class Collector extends BaseExternal { nestedCountersInstance.countEvent('collector', 'decodeTransaction') let result: any = null let txObj = null - try { const raw = tx.originalTxData.tx.raw as string txObj = TransactionFactory.fromSerializedData(toBuffer(raw))