From 56ebc7d0fa44ef5abdea4df4ab31fe697bcfde21 Mon Sep 17 00:00:00 2001 From: 0xGabi Date: Tue, 12 Mar 2024 21:52:51 -0300 Subject: [PATCH 1/2] fix(api): calculate blob gas as calldata for all the blobs in a tx --- .changeset/honest-llamas-cough.md | 5 ++++ .../src/routers/indexer/indexData.utils.ts | 26 ++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 .changeset/honest-llamas-cough.md diff --git a/.changeset/honest-llamas-cough.md b/.changeset/honest-llamas-cough.md new file mode 100644 index 000000000..27ac81379 --- /dev/null +++ b/.changeset/honest-llamas-cough.md @@ -0,0 +1,5 @@ +--- +"@blobscan/api": patch +--- + +Fixed blob gas as calldata calculation diff --git a/packages/api/src/routers/indexer/indexData.utils.ts b/packages/api/src/routers/indexer/indexData.utils.ts index 969168485..e1b4f41d3 100644 --- a/packages/api/src/routers/indexer/indexData.utils.ts +++ b/packages/api/src/routers/indexer/indexData.utils.ts @@ -8,8 +8,8 @@ import { Prisma } from "@blobscan/db"; import type { IndexDataInput } from "./indexData.schema"; -const MIN_BLOB_GASPRICE = BigInt(1); -const BLOB_GASPRICE_UPDATE_FRACTION = BigInt(3_338_477); +const MIN_BLOB_BASE_FEE = BigInt(1); +const BLOB_BASE_FEE_UPDATE_FRACTION = BigInt(3_338_477); export const GAS_PER_BLOB = 2 ** 17; // 131_072 @@ -56,12 +56,12 @@ export function calculateBlobSize(blob: string): number { return blob.slice(2).length / 2; } -export function calculateBlobGasPrice(excessDataGas: bigint): bigint { +export function calculateBlobGasPrice(excessBlobGas: bigint): bigint { return BigInt( fakeExponential( - MIN_BLOB_GASPRICE, - excessDataGas, - BLOB_GASPRICE_UPDATE_FRACTION + MIN_BLOB_BASE_FEE, + excessBlobGas, + BLOB_BASE_FEE_UPDATE_FRACTION ) ); } @@ -73,16 +73,18 @@ export function createDBTransactions({ }: IndexDataInput): WithoutTimestampFields[] { return transactions.map>( ({ from, gasPrice, hash, maxFeePerBlobGas, to }) => { - const txBlob: IndexDataInput["blobs"][0] | undefined = blobs.find( - (b) => b.txHash === hash - ); + const txBlobs = blobs.filter((b) => b.txHash === hash); - if (!txBlob) { + if (txBlobs.length === 0) { throw new Error(`Blob for transaction ${hash} not found`); } + const blobGasAsCalldataUsed = txBlobs.reduce( + (acc, b) => acc + getEIP2028CalldataGas(b.data), + BigInt(0) + ); + const blobGasPrice = calculateBlobGasPrice(block.excessBlobGas); - const blobAsCalldataGasUsed = getEIP2028CalldataGas(txBlob.data); return { blockHash: block.hash, @@ -92,7 +94,7 @@ export function createDBTransactions({ gasPrice: bigIntToDecimal(gasPrice), blobGasPrice: bigIntToDecimal(blobGasPrice), maxFeePerBlobGas: bigIntToDecimal(maxFeePerBlobGas), - blobAsCalldataGasUsed: bigIntToDecimal(blobAsCalldataGasUsed), + blobAsCalldataGasUsed: bigIntToDecimal(blobGasAsCalldataUsed), }; } ); From 93eb90a5639ba3fea15341a0a758546e5be75e50 Mon Sep 17 00:00:00 2001 From: Gabi Date: Tue, 12 Mar 2024 22:11:29 -0300 Subject: [PATCH 2/2] Update packages/api/src/routers/indexer/indexData.utils.ts Co-authored-by: elessar.eth --- packages/api/src/routers/indexer/indexData.utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/src/routers/indexer/indexData.utils.ts b/packages/api/src/routers/indexer/indexData.utils.ts index e1b4f41d3..53367c076 100644 --- a/packages/api/src/routers/indexer/indexData.utils.ts +++ b/packages/api/src/routers/indexer/indexData.utils.ts @@ -76,7 +76,7 @@ export function createDBTransactions({ const txBlobs = blobs.filter((b) => b.txHash === hash); if (txBlobs.length === 0) { - throw new Error(`Blob for transaction ${hash} not found`); + throw new Error(`Blobs for transaction ${hash} not found`); } const blobGasAsCalldataUsed = txBlobs.reduce(