From d382202bd2e28de938d971f969b8d953540d1ed9 Mon Sep 17 00:00:00 2001 From: Elias Tazartes <66871571+Eikix@users.noreply.github.com> Date: Tue, 16 Apr 2024 18:52:57 +0200 Subject: [PATCH] Fix/null blockhash (#975) * feat: write zero block hash in accepted on l2 sn txs * add one log * fix comments * fix format hex * fix comments --- indexer/src/main.ts | 8 +++++--- indexer/src/types/log.ts | 4 ++-- indexer/src/types/receipt.ts | 4 ++-- indexer/src/types/transaction.ts | 12 +++++++----- indexer/src/utils/hex.ts | 7 ++++--- src/eth_provider/provider.rs | 4 ++-- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/indexer/src/main.ts b/indexer/src/main.ts index dc5feb25a..82193ad82 100644 --- a/indexer/src/main.ts +++ b/indexer/src/main.ts @@ -1,5 +1,5 @@ // Utils -import { padString, toHexString } from "./utils/hex.ts"; +import { NULL_BLOCK_HASH, padString, toHexString } from "./utils/hex.ts"; // Types import { toEthTx, toTypedEthTx } from "./types/transaction.ts"; @@ -95,8 +95,6 @@ const isKakarotTransaction = (transaction: Transaction) => { return true; }; -const NULL_BLOCK_HASH = padString("0x", 32); - export default async function transform({ header, events, @@ -120,6 +118,10 @@ export default async function transform({ (events ?? []).map(async ({ transaction, receipt, event }) => { // Can be false if the transaction is not related to a specific instance of the Kakarot contract. // This is typically the case if there are multiple Kakarot contracts on the same chain. + console.log( + "🔍 Processing transaction with Starknet hash: ", + transaction.meta.hash, + ); const isKakarotTx = isKakarotTransaction(transaction); if (!isKakarotTx) { return null; diff --git a/indexer/src/types/log.ts b/indexer/src/types/log.ts index b833c2c71..7078ba1db 100644 --- a/indexer/src/types/log.ts +++ b/indexer/src/types/log.ts @@ -1,5 +1,5 @@ // Utils -import { padBigint } from "../utils/hex.ts"; +import { NULL_BLOCK_HASH, padBigint } from "../utils/hex.ts"; // Starknet import { Event, hash } from "../deps.ts"; @@ -83,7 +83,7 @@ export function toEthLog({ logIndex: null, transactionIndex: bigIntToHex(BigInt(transaction.transactionIndex ?? 0)), transactionHash: transaction.hash, - blockHash: isPendingBlock ? null : blockHash, + blockHash: isPendingBlock ? NULL_BLOCK_HASH : blockHash, blockNumber, address, data: `0x${paddedData}`, diff --git a/indexer/src/types/receipt.ts b/indexer/src/types/receipt.ts index 36cda4fd5..2b5041ce5 100644 --- a/indexer/src/types/receipt.ts +++ b/indexer/src/types/receipt.ts @@ -1,5 +1,5 @@ // Utils -import { padBytes } from "../utils/hex.ts"; +import { NULL_BLOCK_HASH, padBytes } from "../utils/hex.ts"; // Types import { fromJsonRpcLog, JsonRpcLog } from "./log.ts"; @@ -68,7 +68,7 @@ export function toEthReceipt({ return { transactionHash: transaction.hash, transactionIndex: bigIntToHex(BigInt(transaction.transactionIndex ?? 0)), - blockHash: isPendingBlock ? null : blockHash, + blockHash: isPendingBlock ? NULL_BLOCK_HASH : blockHash, blockNumber, from: transaction.from, to: transaction.to, diff --git a/indexer/src/types/transaction.ts b/indexer/src/types/transaction.ts index a7aca4cc5..5a270c941 100644 --- a/indexer/src/types/transaction.ts +++ b/indexer/src/types/transaction.ts @@ -73,10 +73,11 @@ export function toEthTx({ } // If the transaction is a legacy, we can calculate it from the v value. // v = 35 + 2 * chainId + yParity -> chainId = (v - 35) / 2 - const chainId = isLegacyTx(transaction) && - transaction.supports(Capability.EIP155ReplayProtection) - ? bigIntToHex((BigInt(txJSON.v) - 35n) / 2n) - : txJSON.chainId; + const chainId = + isLegacyTx(transaction) && + transaction.supports(Capability.EIP155ReplayProtection) + ? bigIntToHex((BigInt(txJSON.v) - 35n) / 2n) + : txJSON.chainId; const result: JsonRpcTx & { yParity?: string } = { blockHash: isPendingBlock ? null : blockHash, @@ -93,7 +94,7 @@ export function toEthTx({ input: txJSON.data!, nonce: txJSON.nonce!, to: transaction.to?.toString() ?? null, - transactionIndex: isPendingBlock ? null : padBigint(BigInt(index ?? 0), 32), + transactionIndex: isPendingBlock ? null : padBigint(BigInt(index ?? 0), 8), value: txJSON.value!, v: txJSON.v, r: txJSON.r, @@ -166,6 +167,7 @@ export function toTypedEthTx({ throw e; } // TODO: Ping alert webhooks + console.error(e); return null; } } diff --git a/indexer/src/utils/hex.ts b/indexer/src/utils/hex.ts index aae9be94f..05de16ffa 100644 --- a/indexer/src/utils/hex.ts +++ b/indexer/src/utils/hex.ts @@ -2,6 +2,8 @@ import { bigIntToHex, bytesToHex } from "../deps.ts"; import { PrefixedHexString, stripHexPrefix } from "../deps.ts"; +export const NULL_BLOCK_HASH = padString("0x", 32); + /** * @param hex - A decimal string. */ @@ -20,7 +22,7 @@ export function padString( hex: PrefixedHexString | undefined, length: number, ): PrefixedHexString { - return "0x" + (stripHexPrefix(hex ?? "0x").padStart(2 * length, "0")); + return "0x" + stripHexPrefix(hex ?? "0x").padStart(2 * length, "0"); } /** @@ -31,8 +33,7 @@ export function padBigint( b: bigint | undefined, length: number, ): PrefixedHexString { - return "0x" + - (stripHexPrefix(bigIntToHex(b ?? 0n)).padStart(2 * length, "0")); + return "0x" + stripHexPrefix(bigIntToHex(b ?? 0n)).padStart(2 * length, "0"); } /** diff --git a/src/eth_provider/provider.rs b/src/eth_provider/provider.rs index 224882a62..40f8300a9 100644 --- a/src/eth_provider/provider.rs +++ b/src/eth_provider/provider.rs @@ -276,7 +276,7 @@ where let mut filter = into_filter("tx.blockHash", &hash, HASH_PADDING); let index: usize = index.into(); - filter.insert("tx.transactionIndex", format_hex(index, 64)); + filter.insert("tx.transactionIndex", format_hex(index, U64_PADDING)); Ok(self.database.get_one::(filter, None).await?.map(Into::into)) } @@ -289,7 +289,7 @@ where let mut filter = into_filter("tx.blockNumber", &block_number, U64_PADDING); let index: usize = index.into(); - filter.insert("tx.transactionIndex", format_hex(index, 64)); + filter.insert("tx.transactionIndex", format_hex(index, U64_PADDING)); Ok(self.database.get_one::(filter, None).await?.map(Into::into)) }