diff --git a/src/app/api/block/[hash]/route.ts b/src/app/api/block/[hash]/route.ts index bf48204..dcfc94c 100644 --- a/src/app/api/block/[hash]/route.ts +++ b/src/app/api/block/[hash]/route.ts @@ -20,7 +20,8 @@ function serializeBlockData(block: BlockData) { gasLimit: block.gasLimit.toString(), transactions: block.transactions.map((tx) => ({ ...tx, - gasUsed: tx.gasUsed.toString(), + gasLimit: tx.gasLimit.toString(), + gasUsed: tx.gasUsed?.toString() ?? null, })), }; } @@ -73,16 +74,16 @@ async function buildAndCacheBlockData( ): Promise { const transactions: BlockTransaction[] = await Promise.all( rpcBlock.transactions.map(async (tx, index) => { - const { bundleId, executionTimeUs, stateRootTimeUs } = - await enrichTransactionWithBundleData(tx.hash); + const enriched = await enrichTransactionWithBundleData(tx.hash); return { hash: tx.hash, from: tx.from, to: tx.to, - gasUsed: tx.gas, - executionTimeUs, - stateRootTimeUs, - bundleId, + gasLimit: tx.gas, + gasUsed: enriched.gasUsed != null ? BigInt(enriched.gasUsed) : null, + executionTimeUs: enriched.executionTimeUs, + stateRootTimeUs: enriched.stateRootTimeUs, + bundleId: enriched.bundleId, index, }; }), @@ -114,23 +115,39 @@ async function enrichTransactionWithBundleData(txHash: string): Promise<{ bundleId: string | null; executionTimeUs: number | null; stateRootTimeUs: number | null; + gasUsed: number | null; }> { const metadata = await getTransactionMetadataByHash(txHash); if (!metadata || metadata.bundle_ids.length === 0) { - return { bundleId: null, executionTimeUs: null, stateRootTimeUs: null }; + return { + bundleId: null, + executionTimeUs: null, + stateRootTimeUs: null, + gasUsed: null, + }; } const bundleId = metadata.bundle_ids[0]; const bundleHistory = await getBundleHistory(bundleId); if (!bundleHistory) { - return { bundleId, executionTimeUs: null, stateRootTimeUs: null }; + return { + bundleId, + executionTimeUs: null, + stateRootTimeUs: null, + gasUsed: null, + }; } const receivedEvent = bundleHistory.history.find( (e) => e.event === "Received", ); if (!receivedEvent?.data?.bundle?.meter_bundle_response?.results) { - return { bundleId, executionTimeUs: null, stateRootTimeUs: null }; + return { + bundleId, + executionTimeUs: null, + stateRootTimeUs: null, + gasUsed: null, + }; } const meterResponse = receivedEvent.data.bundle.meter_bundle_response; @@ -147,6 +164,7 @@ async function enrichTransactionWithBundleData(txHash: string): Promise<{ bundleId, executionTimeUs: txResult?.executionTimeUs ?? null, stateRootTimeUs: meterResponse.stateRootTimeUs ?? null, + gasUsed: txResult?.gasUsed ?? null, }; } @@ -163,9 +181,8 @@ async function refetchMissingTransactionSimulations( const refetchResults = await Promise.all( transactionsToRefetch.map(async (tx) => { - const { bundleId, executionTimeUs, stateRootTimeUs } = - await enrichTransactionWithBundleData(tx.hash); - return { hash: tx.hash, bundleId, executionTimeUs, stateRootTimeUs }; + const enriched = await enrichTransactionWithBundleData(tx.hash); + return { hash: tx.hash, ...enriched }; }), ); @@ -179,6 +196,9 @@ async function refetchMissingTransactionSimulations( bundleId: refetchResult.bundleId, executionTimeUs: refetchResult.executionTimeUs, stateRootTimeUs: refetchResult.stateRootTimeUs, + ...(refetchResult.gasUsed != null && { + gasUsed: BigInt(refetchResult.gasUsed), + }), }; } return tx; diff --git a/src/app/block/[hash]/page.tsx b/src/app/block/[hash]/page.tsx index 71bcca7..b159cdb 100644 --- a/src/app/block/[hash]/page.tsx +++ b/src/app/block/[hash]/page.tsx @@ -152,7 +152,9 @@ function TransactionRow({
)}
- {tx.gasUsed.toLocaleString()} gas + {tx.gasUsed != null + ? `${tx.gasUsed.toLocaleString()} / ${tx.gasLimit.toLocaleString()} gas` + : `${tx.gasLimit.toLocaleString()} gas limit`}
diff --git a/src/lib/s3.ts b/src/lib/s3.ts index 60f8f3a..9086f70 100644 --- a/src/lib/s3.ts +++ b/src/lib/s3.ts @@ -184,7 +184,8 @@ export interface BlockTransaction { hash: string; from: string; to: string | null; - gasUsed: bigint; + gasLimit: bigint; + gasUsed: bigint | null; executionTimeUs: number | null; stateRootTimeUs: number | null; bundleId: string | null; @@ -220,9 +221,14 @@ export async function getBlockFromCache( gasUsed: BigInt(parsed.gasUsed), gasLimit: BigInt(parsed.gasLimit), transactions: parsed.transactions.map( - (tx: BlockTransaction & { gasUsed: string }) => ({ + (tx: { + gasLimit?: string; + gasUsed?: string | null; + [key: string]: unknown; + }) => ({ ...tx, - gasUsed: BigInt(tx.gasUsed), + gasLimit: BigInt(tx.gasLimit ?? tx.gasUsed ?? "0"), + gasUsed: tx.gasUsed != null ? BigInt(tx.gasUsed) : null, }), ), } as BlockData;