Skip to content

Commit

Permalink
fix: compute blockGasUsed as actual sum of gas spent by all txes
Browse files Browse the repository at this point in the history
  • Loading branch information
akirapham authored and jairajdev committed Jun 6, 2024
1 parent b32e421 commit 704a6b2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/external/Collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 704a6b2

Please sign in to comment.