Skip to content

Commit ce3af1a

Browse files
authored
Update accuracy of sentAt timing (#353)
* Improve accuracy of sentAt * Update * undo
1 parent 9dc6e3f commit ce3af1a

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/db/transactions/updateTx.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ type UpdateTxData =
2222
}
2323
| {
2424
status: TransactionStatusEnum.Submitted;
25+
sentAt: Date;
2526
transactionHash: string;
2627
res: ethers.providers.TransactionResponse | null;
2728
sentAtBlockNumber: number;
2829
retryCount?: number;
2930
}
3031
| {
3132
status: TransactionStatusEnum.UserOpSent;
33+
sentAt: Date;
3234
userOpHash: string;
3335
}
3436
| {
@@ -84,7 +86,7 @@ export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
8486
id: queueId,
8587
},
8688
data: {
87-
sentAt: new Date(),
89+
sentAt: data.sentAt,
8890
transactionHash: data.transactionHash,
8991
sentAtBlockNumber: data.sentAtBlockNumber,
9092
retryCount: data.retryCount,
@@ -103,7 +105,7 @@ export const updateTx = async ({ pgtx, queueId, data }: UpdateTxParams) => {
103105
id: queueId,
104106
},
105107
data: {
106-
sentAt: new Date(),
108+
sentAt: data.sentAt,
107109
userOpHash: data.userOpHash,
108110
},
109111
});

src/worker/tasks/processTx.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { getWithdrawalValue } from "../utils/withdraw";
2929
type SentTxStatus =
3030
| {
3131
transactionHash: string;
32+
sentAt: Date;
3233
status: TransactionStatusEnum.Submitted;
3334
queueId: string;
3435
res: ethers.providers.TransactionResponse | null;
@@ -205,13 +206,13 @@ export const processTx = async () => {
205206
queueId: string;
206207
tx: ethers.providers.TransactionRequest;
207208
res: RpcResponse;
209+
sentAt: Date;
208210
}[] = [];
209211
for (const tx of txsToSend) {
210212
const nonce = startNonce.add(sentTxCount);
211213

212214
try {
213215
let value: ethers.BigNumberish = tx.value!;
214-
215216
if (tx.extension === "withdraw") {
216217
value = await getWithdrawalValue({
217218
provider,
@@ -299,6 +300,7 @@ export const processTx = async () => {
299300
queueId: tx.queueId!,
300301
tx: txRequest,
301302
res: rpcResponse,
303+
sentAt: new Date(),
302304
});
303305

304306
if (!rpcResponse.error && !!rpcResponse.result) {
@@ -342,7 +344,7 @@ export const processTx = async () => {
342344

343345
// Update transaction records with updated data
344346
const txStatuses: SentTxStatus[] = await Promise.all(
345-
rpcResponses.map(async ({ queueId, tx, res }) => {
347+
rpcResponses.map(async ({ queueId, tx, res, sentAt }) => {
346348
if (res.result) {
347349
const txHash = res.result;
348350
const txRes = (await provider.getTransaction(
@@ -357,6 +359,7 @@ export const processTx = async () => {
357359
});
358360

359361
return {
362+
sentAt,
360363
transactionHash: txHash,
361364
status: TransactionStatusEnum.Submitted,
362365
queueId: queueId,
@@ -393,6 +396,7 @@ export const processTx = async () => {
393396
pgtx,
394397
queueId: tx.queueId,
395398
data: {
399+
sentAt: tx.sentAt,
396400
status: TransactionStatusEnum.Submitted,
397401
transactionHash: tx.transactionHash,
398402
res: tx.res,
@@ -462,13 +466,15 @@ export const processTx = async () => {
462466
const userOpHash = await signer.smartAccountAPI.getUserOpHash(
463467
userOp,
464468
);
469+
465470
await signer.httpRpcClient.sendUserOpToBundler(userOp);
466471

467472
// TODO: Need to update with other user op data
468473
await updateTx({
469474
pgtx,
470475
queueId: tx.queueId!,
471476
data: {
477+
sentAt: new Date(),
472478
status: TransactionStatusEnum.UserOpSent,
473479
userOpHash,
474480
},

src/worker/tasks/retryTx.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const retryTx = async () => {
7272
message: `Retrying with nonce ${tx.nonce}`,
7373
});
7474

75+
const sentAt = new Date();
7576
let res: ethers.providers.TransactionResponse;
7677
try {
7778
res = await sdk.getSigner()!.sendTransaction({
@@ -113,6 +114,7 @@ export const retryTx = async () => {
113114
pgtx,
114115
queueId: tx.id,
115116
data: {
117+
sentAt,
116118
status: TransactionStatusEnum.Submitted,
117119
res,
118120
sentAtBlockNumber: await sdk.getProvider().getBlockNumber(),

0 commit comments

Comments
 (0)