Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rollup resolution #532

Merged
merged 3 commits into from
Sep 4, 2024
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
5 changes: 5 additions & 0 deletions .changeset/two-keys-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blobscan/api": patch
---

Corrected the transaction indexing process to resolve the transaction sender instead of the receiver when looking for rollup transactions.
2 changes: 1 addition & 1 deletion packages/api/src/routers/indexer/indexData.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function createDBTransactions({
);

const blobGasPrice = calculateBlobGasPrice(block.excessBlobGas);
const rollup = getRollupByAddress(to, env.CHAIN_ID);
const rollup = getRollupByAddress(from, env.CHAIN_ID);

return {
blockHash: block.hash,
Expand Down
32 changes: 32 additions & 0 deletions packages/api/test/indexer.test.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,35 @@ export const INPUT_WITH_DUPLICATED_BLOBS: IndexDataInput = {
},
],
};

export const ROLLUP_BLOB_TRANSACTION_INPUT: IndexDataInput = {
block: {
number: 9999,
hash: "blockHash9999",
timestamp: 1694586221,
slot: 170,
blobGasUsed: "10000",
excessBlobGas: "5000",
},
transactions: [
{
hash: "txHash2002",
from: "0xc1b634853cb333d3ad8663715b08f41a3aec47cc",
to: "address10",
blockNumber: 9999,
index: 0,
gasPrice: "10000",
maxFeePerBlobGas: "1800",
},
],
blobs: [
{
versionedHash: "blobHash2000",
commitment: "commitment2000",
proof: "newProof2000",
data: "0x1234abcdeff123456789ab34223a4b2c2ed",
txHash: "txHash2002",
index: 0,
},
],
};
168 changes: 111 additions & 57 deletions packages/api/test/indexer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {

import type { Blob as PropagatorBlob } from "@blobscan/blob-propagator";
import type { BlobReference } from "@blobscan/blob-storage-manager";
import { Rollup } from "@blobscan/db/prisma/enums";
import { env } from "@blobscan/env";
import { ADDRESS_TO_ROLLUP_MAPPINGS } from "@blobscan/rollups";
import {
fixtures,
omitDBTimestampFields,
Expand All @@ -23,7 +26,11 @@ import { appRouter } from "../src/app-router";
import type { HandleReorgedSlotsInput } from "../src/routers/indexer/handleReorgedSlots";
import { calculateBlobGasPrice } from "../src/routers/indexer/indexData.utils";
import { createTestContext, unauthorizedRPCCallTest } from "./helpers";
import { INPUT_WITH_DUPLICATED_BLOBS, INPUT } from "./indexer.test.fixtures";
import {
INPUT_WITH_DUPLICATED_BLOBS,
INPUT,
ROLLUP_BLOB_TRANSACTION_INPUT,
} from "./indexer.test.fixtures";

describe("Indexer router", async () => {
let nonAuthorizedCaller: ReturnType<typeof appRouter.createCaller>;
Expand Down Expand Up @@ -89,67 +96,114 @@ describe("Indexer router", async () => {
`);
});

it("should index transactions correctly", async () => {
const indexedTxs = await authorizedContext.prisma.transaction
.findMany({
where: {
blockHash: INPUT.block.hash,
},
orderBy: [
describe("when indexing transactions", () => {
const expectedRollup = Rollup.ARBITRUM;

beforeAll(() => {
ADDRESS_TO_ROLLUP_MAPPINGS.set(
env.CHAIN_ID,
new Map([
...ROLLUP_BLOB_TRANSACTION_INPUT.transactions.map(
(tx) => [tx.from, expectedRollup] as [string, Rollup]
),
])
);
});

afterAll(() => {
ADDRESS_TO_ROLLUP_MAPPINGS.delete(env.CHAIN_ID);
});

it("should index transactions correctly", async () => {
const indexedTxs = await authorizedContext.prisma.transaction
.findMany({
where: {
blockHash: INPUT.block.hash,
},
orderBy: [
{
blockNumber: "asc",
},
{
index: "asc",
},
],
})
.then((r) => r.map(omitDBTimestampFields));
// const expectedBlobAsCalldataGasUsed = INPUT.transactions.map((tx) =>
// INPUT.blobs
// .filter((b) => b.txHash === tx.hash)
// .reduce((acc, b) => acc + getEIP2028CalldataGas(b.data), 0)
// );
// const blobAsCalldataGasUsed = indexedTxs.map(
// (tx) => tx.blobAsCalldataGasUsed
// );
const remainingParams = indexedTxs.map(
({ blobAsCalldataGasUsed: _, ...remainingParams }) =>
remainingParams
);

// TODO: Fix this test
// expect(
// blobAsCalldataGasUsed,
// "Transactions' blob as calldata gas used mismatch"
// ).toEqual(expectedBlobAsCalldataGasUsed);
expect(remainingParams).toMatchInlineSnapshot(`
[
{
blockNumber: "asc",
"blockHash": "blockHash2010",
"blockNumber": 2010,
"blockTimestamp": 2023-09-01T13:50:21.000Z,
"fromId": "address9",
"gasPrice": "10000",
"hash": "txHash999",
"index": 0,
"maxFeePerBlobGas": "1800",
"rollup": null,
"toId": "address10",
},
{
index: "asc",
"blockHash": "blockHash2010",
"blockNumber": 2010,
"blockTimestamp": 2023-09-01T13:50:21.000Z,
"fromId": "address7",
"gasPrice": "3000000",
"hash": "txHash1000",
"index": 1,
"maxFeePerBlobGas": "20000",
"rollup": null,
"toId": "address2",
},
],
})
.then((r) => r.map(omitDBTimestampFields));
// const expectedBlobAsCalldataGasUsed = INPUT.transactions.map((tx) =>
// INPUT.blobs
// .filter((b) => b.txHash === tx.hash)
// .reduce((acc, b) => acc + getEIP2028CalldataGas(b.data), 0)
// );
// const blobAsCalldataGasUsed = indexedTxs.map(
// (tx) => tx.blobAsCalldataGasUsed
// );
const remainingParams = indexedTxs.map(
({ blobAsCalldataGasUsed: _, ...remainingParams }) => remainingParams
);
]
`);
});

// TODO: Fix this test
// expect(
// blobAsCalldataGasUsed,
// "Transactions' blob as calldata gas used mismatch"
// ).toEqual(expectedBlobAsCalldataGasUsed);
expect(remainingParams).toMatchInlineSnapshot(`
[
{
"blockHash": "blockHash2010",
"blockNumber": 2010,
"blockTimestamp": 2023-09-01T13:50:21.000Z,
"fromId": "address9",
"gasPrice": "10000",
"hash": "txHash999",
"index": 0,
"maxFeePerBlobGas": "1800",
"rollup": null,
"toId": "address10",
},
{
"blockHash": "blockHash2010",
"blockNumber": 2010,
"blockTimestamp": 2023-09-01T13:50:21.000Z,
"fromId": "address7",
"gasPrice": "3000000",
"hash": "txHash1000",
"index": 1,
"maxFeePerBlobGas": "20000",
"rollup": null,
"toId": "address2",
},
]
`);
it("should label rollup transactions correctly", async () => {
await authorizedCaller.indexer.indexData(
ROLLUP_BLOB_TRANSACTION_INPUT
);

console.log(ADDRESS_TO_ROLLUP_MAPPINGS);

const indexedTxHashesAndRollups =
await authorizedContext.prisma.transaction
.findMany({
where: {
blockHash: ROLLUP_BLOB_TRANSACTION_INPUT.block.hash,
},
})
.then((r) =>
r.map(omitDBTimestampFields).map((tx) => [tx.hash, tx.rollup])
);

const expectedTxHashesAndRollups =
ROLLUP_BLOB_TRANSACTION_INPUT.transactions.map(({ hash }) => [
hash,
expectedRollup,
]);

expect(indexedTxHashesAndRollups).toEqual(expectedTxHashesAndRollups);
});
});

describe("when indexing blobs", () => {
Expand Down
Loading