Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions src/app/api/block/[hash]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})),
};
}
Expand Down Expand Up @@ -73,16 +74,16 @@ async function buildAndCacheBlockData(
): Promise<BlockData> {
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,
};
}),
Expand Down Expand Up @@ -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;
Expand All @@ -147,6 +164,7 @@ async function enrichTransactionWithBundleData(txHash: string): Promise<{
bundleId,
executionTimeUs: txResult?.executionTimeUs ?? null,
stateRootTimeUs: meterResponse.stateRootTimeUs ?? null,
gasUsed: txResult?.gasUsed ?? null,
};
}

Expand All @@ -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 };
}),
);

Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/app/block/[hash]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ function TransactionRow({
<div className="text-sm font-medium text-gray-400">—</div>
)}
<div className="text-xs text-gray-500 mt-0.5">
{tx.gasUsed.toLocaleString()} gas
{tx.gasUsed != null
? `${tx.gasUsed.toLocaleString()} / ${tx.gasLimit.toLocaleString()} gas`
: `${tx.gasLimit.toLocaleString()} gas limit`}
</div>
</div>
</div>
Expand Down
12 changes: 9 additions & 3 deletions src/lib/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading