Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compute blockGasUsed as actual sum of gas spent by all txes
Browse files Browse the repository at this point in the history
akirapham authored and jairajdev committed Jun 6, 2024
1 parent afe7041 commit f220900
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
@@ -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))

0 comments on commit f220900

Please sign in to comment.