Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Dec 10, 2024
1 parent fce0605 commit a88ef1d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export function getBountyEnsureBytecode(
const minimum = minimumExcepted.toHexString().substring(2).padStart(64, "0");
const msgSender = sender.substring(2).padStart(64, "0").toLowerCase();
// rainlang bytecode:
// :ensure(sender context<0 0>()),
// :ensure(equal-to(sender context<0 0>()) \"unknown sender\"),
// :ensure(
// greater-than-or-equal-to(
// add(
Expand Down Expand Up @@ -283,7 +283,7 @@ export function getWithdrawEnsureBytecode(
const minimum = minimumExcepted.toHexString().substring(2).padStart(64, "0");
const msgSender = sender.substring(2).padStart(64, "0").toLowerCase();
// rainlang bytecode:
// :ensure(sender context<0 0>()),
// :ensure(equal-to(sender context<0 0>()) \"unknown sender\"),
// :ensure(
// greater-than-or-equal-to(
// add(
Expand Down
22 changes: 20 additions & 2 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ export enum ErrorSeverity {
HIGH = "HIGH",
}

/**
* Known errors
*/
export const KnownErrors = [
"unknown sender",
"minimumSenderOutput",
"MinimalOutputBalanceViolation",
] as const;

/**
* Specifies a decoded contract error
*/
Expand Down Expand Up @@ -167,7 +176,15 @@ export async function handleRevert(
receipt: TransactionReceipt,
rawtx: RawTx,
signerBalance: BigNumber,
): Promise<{ err: any; nodeError: boolean; snapshot: string } | undefined> {
): Promise<
| {
err: any;
nodeError: boolean;
snapshot: string;
rawRevertError?: TxRevertError;
}
| undefined
> {
const header = "transaction reverted onchain";
try {
const gasErr = checkGasIssue(receipt, rawtx, signerBalance);
Expand All @@ -189,13 +206,14 @@ export async function handleRevert(
});
const msg =
header +
" and simulation failed to find out what was the revert reason, please try to simulate the tx manualy for more details";
" and simulation failed to find the revert reason, please try to simulate the tx manualy for more details";
return { err: msg, nodeError: false, snapshot: msg };
} catch (err: any) {
return {
err,
nodeError: containsNodeError(err),
snapshot: errorSnapshot(header, err, { receipt, rawtx, signerBalance }),
rawRevertError: parseRevertError(err),
};
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/processOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { privateKeyToAccount } from "viem/accounts";
import { BigNumber, Contract, ethers } from "ethers";
import { Tracer } from "@opentelemetry/sdk-trace-base";
import { Context, SpanStatusCode } from "@opentelemetry/api";
import { ErrorSeverity, errorSnapshot, isTimeout } from "./error";
import { ErrorSeverity, errorSnapshot, isTimeout, KnownErrors } from "./error";
import {
Report,
BotConfig,
Expand Down Expand Up @@ -359,6 +359,9 @@ export const processOrders = async (
} else {
message = errorSnapshot("transaction reverted onchain", e.error.err);
}
if (KnownErrors.some((v) => message.includes(v))) {
span.setAttribute("severity", ErrorSeverity.HIGH);
}
span.setAttribute("errorDetails", message);
}
if (e.spanAttributes["txNoneNodeError"]) {
Expand Down
16 changes: 10 additions & 6 deletions src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ export async function handleTransaction(
);
} catch (e: any) {
try {
const newReceipt = await viemClient.getTransactionReceipt({ hash: txhash });
const newReceipt = await (async () => {
try {
return await viemClient.getTransactionReceipt({ hash: txhash });
} catch {
await sleep(Math.max(90_000 + time - Date.now(), 0));
return await viemClient.getTransactionReceipt({ hash: txhash });
}
})();
if (newReceipt) {
return handleReceipt(
txhash,
Expand Down Expand Up @@ -274,12 +281,9 @@ export async function handleReceipt(
}
return result;
} else {
// wait at least 60s before simulating the revert tx
// wait at least 90s before simulating the revert tx
// in order for rpcs to catch up
const wait = 60000 - Date.now() + time;
if (wait > 0) {
await sleep(wait);
}
await sleep(Math.max(90_000 + time - Date.now(), 0));
const simulation = await handleRevert(
signer,
txhash as `0x${string}`,
Expand Down

0 comments on commit a88ef1d

Please sign in to comment.