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

feat: index cairovm errors #1526

Merged
merged 3 commits into from
Nov 6, 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
80 changes: 79 additions & 1 deletion indexer/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions indexer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { padString, toHexString } from "./utils/hex.ts";
import {
ethValidationFailed,
isKakarotTransaction,
isRevertedWithOutOfResources,
isReverted,
} from "./utils/filter.ts";

// Constants
Expand Down Expand Up @@ -256,7 +256,7 @@ function processTransactions(
return (transactions ?? [])
.filter(
(tx) =>
isRevertedWithOutOfResources(tx.receipt) &&
isReverted(tx.receipt) &&
isKakarotTransaction(tx.transaction),
)
.map((tx) => createProcessedTransaction(tx, blockInfo, cumulativeGasUsages))
Expand Down
4 changes: 2 additions & 2 deletions indexer/src/types/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export interface TransactionContext {
export interface ExtendedJsonRpcTx extends JsonRpcTx {
/** The y parity of the signature. */
yParity?: string;
/** Indicates if the transaction is reverted due to running out of resources. */
isRunOutOfResources?: boolean;
/** Indicates the reverted message if the transaction was reverted. */
reverted?: string;
}

/**
Expand Down
15 changes: 7 additions & 8 deletions indexer/src/types/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Utils
import { padBigint, padBytes } from "../utils/hex.ts";
import { isRevertedWithOutOfResources } from "../utils/filter.ts";
import { isReverted } from "../utils/filter.ts";

// Starknet
import { Transaction, TransactionReceipt, uint256 } from "../deps.ts";
Expand Down Expand Up @@ -121,20 +121,19 @@ export function setYParityFlag(
}

/**
* Adds the isRunOutOfResources flag to the transaction result if the transaction
* was reverted due to running out of resources.
* Adds the reverted field to the transaction result if the transaction was reverted.
*
* @param receipt - The transaction receipt object.
* @param result - The transaction result object in Ethereum format.
*/
export function setFlagRunOutOfResources(
export function setRevertedFlag(
receipt: TransactionReceipt,
result: ExtendedJsonRpcTx,
): void {
// Check if the transaction was reverted due to running out of resources
if (isRevertedWithOutOfResources(receipt)) {
// Set the isRunOutOfResources flag to true in the result
result.isRunOutOfResources = true;
if (isReverted(receipt)) {
// Set the reverted field to the result
result.reverted = receipt.revertReason;
}
}

Expand Down Expand Up @@ -236,7 +235,7 @@ export function typedTransactionToEthTx({

setYParityFlag(typedTransaction, jsonTx, result);

setFlagRunOutOfResources(receipt, result);
setRevertedFlag(receipt, result);

return result;
}
Expand Down
9 changes: 4 additions & 5 deletions indexer/src/utils/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@ export function ethValidationFailed(event: Event): boolean {
}

/**
* Checks if a transaction receipt indicates that it was reverted due to running out of resources.
* Checks if a transaction receipt indicates that it was reverted.
*
* @param {TransactionReceipt} receipt - The transaction receipt to check.
* @returns {boolean} - Returns true if the transaction was reverted due to out of resources, otherwise false.
* @returns {boolean} - Returns true if the transaction was reverted, otherwise false.
*/
export function isRevertedWithOutOfResources(
export function isReverted(
receipt: TransactionReceipt,
): boolean {
return (
receipt.executionStatus.includes("REVERTED") &&
(receipt.revertReason ?? "").includes("RunResources has no remaining steps")
receipt.executionStatus.includes("REVERTED")
ClementWalter marked this conversation as resolved.
Show resolved Hide resolved
);
}
18 changes: 9 additions & 9 deletions indexer/tests/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import {
ethValidationFailed,
isKakarotTransaction,
isRevertedWithOutOfResources,
isReverted,
} from "../src/utils/filter.ts";
import { Event, Transaction, TransactionReceipt } from "../src/deps.ts";

Expand Down Expand Up @@ -247,7 +247,7 @@ Deno.test(
);

Deno.test(
"isRevertedWithOutOfResources: true on status reverted and revert reason",
"isReverted: true on status reverted and revert reason",
() => {
const receipt: TransactionReceipt = {
executionStatus: "EXECUTION_STATUS_REVERTED",
Expand All @@ -260,12 +260,12 @@ Deno.test(
revertReason:
"Could not reach the end of the program. RunResources has no remaining steps",
};
assert(isRevertedWithOutOfResources(receipt));
assert(isReverted(receipt));
},
);

Deno.test(
"isRevertedWithOutOfResources: false on status reverted and no revert reason",
"isReverted: true on status reverted and no revert reason",
() => {
const receipt: TransactionReceipt = {
executionStatus: "EXECUTION_STATUS_REVERTED",
Expand All @@ -276,11 +276,11 @@ Deno.test(
l2ToL1Messages: [],
events: [],
};
assertFalse(isRevertedWithOutOfResources(receipt));
assert(isReverted(receipt));
},
);

Deno.test("isRevertedWithOutOfResources: false on status succeeded", () => {
Deno.test("isReverted: false on status succeeded", () => {
const receipt: TransactionReceipt = {
executionStatus: "EXECUTION_STATUS_SUCCEEDED",
transactionHash: "0x01",
Expand All @@ -292,11 +292,11 @@ Deno.test("isRevertedWithOutOfResources: false on status succeeded", () => {
revertReason:
"Could not reach the end of the program. RunResources has no remaining steps",
};
assertFalse(isRevertedWithOutOfResources(receipt));
assertFalse(isReverted(receipt));
});

Deno.test(
"isRevertedWithOutOfResources: false on incorrect revert reason",
"isReverted: true no matter the revert reason if status is reverted",
() => {
const receipt: TransactionReceipt = {
executionStatus: "EXECUTION_STATUS_REVERTED",
Expand All @@ -308,6 +308,6 @@ Deno.test(
events: [],
revertReason: "eth validation failed",
};
assertFalse(isRevertedWithOutOfResources(receipt));
assert(isReverted(receipt));
},
);
Loading
Loading