Skip to content

Commit f802c1c

Browse files
authored
fix: Updated minedTx flow + removed deleteAllNonce on start-up (#461)
* fix: Updated minedTx flow + removed deleteNonce on start-up * Updated getSentTx() to use nonce * added new error enum to usage reporting
1 parent 68763ae commit f802c1c

File tree

5 files changed

+54
-29
lines changed

5 files changed

+54
-29
lines changed

src/db/transactions/getSentTxs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const getSentTxs = async ({ pgtx }: GetSentTxsParams = {}): Promise<
2222
AND "minedAt" IS NULL
2323
AND "errorMessage" IS NULL
2424
AND "retryCount" < ${config.maxTxsToUpdate}
25-
ORDER BY "sentAt" ASC
25+
ORDER BY "nonce" ASC
2626
LIMIT ${config.maxTxsToUpdate}
2727
FOR UPDATE SKIP LOCKED
2828
`;

src/server/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import fastify, { FastifyInstance } from "fastify";
33
import * as fs from "fs";
44
import path from "path";
55
import { URL } from "url";
6-
import { deleteAllWalletNonces } from "../db/wallets/deleteAllWalletNonces";
76
import { clearCacheCron } from "../utils/cron/clearCacheCron";
87
import { env } from "../utils/env";
98
import { logger } from "../utils/logger";
@@ -34,10 +33,6 @@ interface HttpsObject {
3433
}
3534

3635
export const initServer = async () => {
37-
// Reset any server state that is safe to reset.
38-
// This allows the server to start in a predictable state.
39-
await deleteAllWalletNonces({});
40-
4136
// Enables the server to run on https://localhost:PORT, if ENABLE_HTTPS is provided.
4237
let httpsObject: HttpsObject | undefined = undefined;
4338
if (env.ENABLE_HTTPS) {

src/utils/usage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export enum UsageEventTxActionEnum {
4747
SendTx = "send_tx",
4848
CancelTx = "cancel_tx",
4949
APIRequest = "api_request",
50+
ErrorTx = "error_tx",
5051
}
5152

5253
interface UsageEventSchema extends Omit<UsageEvent, "action"> {

src/worker/tasks/retryTx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const retryTx = async () => {
9898
retryCount: tx.retryCount + 1 || 0,
9999
provider: provider.connection.url || undefined,
100100
},
101-
action: UsageEventTxActionEnum.NotSendTx,
101+
action: UsageEventTxActionEnum.ErrorTx,
102102
});
103103

104104
reportUsage(reportUsageForQueueIds);

src/worker/tasks/updateMinedTx.ts

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,57 @@ export const updateMinedTx = async () => {
4848
const sentAt = new Date(tx.sentAt!);
4949
const ageInMilliseconds = Date.now() - sentAt.getTime();
5050
if (ageInMilliseconds > MEMPOOL_DURATION_TIMEOUT_MS) {
51-
await cancelTransactionAndUpdate({
52-
queueId: tx.id,
53-
pgtx,
54-
});
55-
56-
sendWebhookForQueueIds.push({
57-
queueId: tx.id,
58-
status: TransactionStatusEnum.Cancelled,
59-
});
60-
61-
reportUsageForQueueIds.push({
62-
input: {
63-
fromAddress: tx.fromAddress || undefined,
64-
toAddress: tx.toAddress || undefined,
65-
value: tx.value || undefined,
66-
chainId: tx.chainId || undefined,
67-
transactionHash: tx.transactionHash || undefined,
68-
provider: provider.connection.url || undefined,
69-
msSinceSend: Date.now() - tx.sentAt!.getTime(),
70-
},
71-
action: UsageEventTxActionEnum.CancelTx,
72-
});
51+
try {
52+
await cancelTransactionAndUpdate({
53+
queueId: tx.id,
54+
pgtx,
55+
});
56+
57+
sendWebhookForQueueIds.push({
58+
queueId: tx.id,
59+
status: TransactionStatusEnum.Cancelled,
60+
});
61+
62+
reportUsageForQueueIds.push({
63+
input: {
64+
fromAddress: tx.fromAddress || undefined,
65+
toAddress: tx.toAddress || undefined,
66+
value: tx.value || undefined,
67+
chainId: tx.chainId || undefined,
68+
transactionHash: tx.transactionHash || undefined,
69+
provider: provider.connection.url || undefined,
70+
msSinceSend: Date.now() - tx.sentAt!.getTime(),
71+
},
72+
action: UsageEventTxActionEnum.CancelTx,
73+
});
74+
} catch (error) {
75+
await updateTx({
76+
pgtx,
77+
queueId: tx.id,
78+
data: {
79+
status: TransactionStatusEnum.Errored,
80+
errorMessage: "Transaction timed out.",
81+
},
82+
});
83+
84+
sendWebhookForQueueIds.push({
85+
queueId: tx.id,
86+
status: TransactionStatusEnum.Errored,
87+
});
88+
89+
reportUsageForQueueIds.push({
90+
input: {
91+
fromAddress: tx.fromAddress || undefined,
92+
toAddress: tx.toAddress || undefined,
93+
value: tx.value || undefined,
94+
chainId: tx.chainId || undefined,
95+
transactionHash: tx.transactionHash || undefined,
96+
provider: provider.connection.url || undefined,
97+
msSinceSend: Date.now() - tx.sentAt!.getTime(),
98+
},
99+
action: UsageEventTxActionEnum.ErrorTx,
100+
});
101+
}
73102
}
74103
return;
75104
}

0 commit comments

Comments
 (0)