Skip to content

Commit 7abc12f

Browse files
arcoravenfarhanW3
andauthored
chore: add more logging to processTx (#592)
* chore: add more logging to processTx * more log lines * typo --------- Co-authored-by: Farhan Khwaja <132962163+farhanW3@users.noreply.github.com>
1 parent 0e45da6 commit 7abc12f

File tree

1 file changed

+46
-16
lines changed

1 file changed

+46
-16
lines changed

src/worker/tasks/processTx.ts

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,23 @@ type RpcResponseData = {
4545
};
4646

4747
export const processTx = async () => {
48+
logger({ service: "worker", level: "info", message: "[processTx] Start" });
49+
4850
try {
4951
const sendWebhookForQueueIds: WebhookData[] = [];
5052
const reportUsageForQueueIds: ReportUsageParams[] = [];
5153
await prisma.$transaction(
5254
async (pgtx) => {
5355
// 1. Select a batch of transactions and lock the rows so no other workers pick them up
5456
const txs = await getQueuedTxs({ pgtx });
55-
5657
if (txs.length === 0) {
5758
return;
5859
}
5960

60-
logger({
61-
service: "worker",
62-
level: "info",
63-
message: `Received ${txs.length} transactions to process`,
64-
});
65-
6661
// 2. Sort transactions and user operations.
6762
const txsToSend: Transactions[] = [];
6863
const userOpsToSend: Transactions[] = [];
6964
for (const tx of txs) {
70-
logger({
71-
service: "worker",
72-
level: "info",
73-
queueId: tx.id,
74-
message: `Processing`,
75-
});
76-
7765
if (tx.accountAddress && tx.signerAddress) {
7866
userOpsToSend.push(tx);
7967
} else {
@@ -92,6 +80,14 @@ export const processTx = async () => {
9280
}
9381
});
9482

83+
logger({
84+
service: "worker",
85+
level: "info",
86+
message: `[processTx] Found ${txsToSend.length} transactions and ${
87+
userOpsToSend.length
88+
} userOps across ${Object.keys(txsByWallet).length}.`,
89+
});
90+
9591
// 4. Send transaction batches in parallel.
9692
const sentTxs = Object.keys(txsByWallet).map(async (key) => {
9793
const txsToSend = txsByWallet[key];
@@ -118,6 +114,11 @@ export const processTx = async () => {
118114
chainId,
119115
address: walletAddress,
120116
});
117+
logger({
118+
service: "worker",
119+
level: "info",
120+
message: `[processTx] Got DB nonce ${dbNonceData?.nonce} for ${walletAddress}.`,
121+
});
121122

122123
// For each wallet address, check the nonce in database and the mempool
123124
const [mempoolNonceData, gasOverrides, sentAtBlockNumber] =
@@ -126,6 +127,11 @@ export const processTx = async () => {
126127
getDefaultGasOverrides(provider),
127128
provider.getBlockNumber(),
128129
]);
130+
logger({
131+
service: "worker",
132+
level: "info",
133+
message: `[processTx] Got onchain nonce ${mempoolNonceData} for ${walletAddress}.`,
134+
});
129135

130136
// - Take the larger of the nonces, and update database nonce to mempool value if mempool is greater
131137
let startNonce: BigNumber;
@@ -144,10 +150,15 @@ export const processTx = async () => {
144150
startNonce = dbNonce;
145151
}
146152

153+
logger({
154+
service: "worker",
155+
level: "info",
156+
message: `[processTx] Sending ${txsToSend.length} transactions from wallet ${walletAddress}.`,
157+
});
158+
147159
const rpcResponses: RpcResponseData[] = [];
148160
let txIndex = 0;
149161
let nonceIncrement = 0;
150-
151162
while (txIndex < txsToSend.length) {
152163
const nonce = startNonce.add(nonceIncrement);
153164
const tx = txsToSend[txIndex];
@@ -293,11 +304,18 @@ export const processTx = async () => {
293304
}
294305
}
295306

307+
const nextUnusedNonce = startNonce.add(nonceIncrement).toNumber();
296308
await updateWalletNonce({
297309
pgtx,
298310
address: walletAddress,
299311
chainId,
300-
nonce: startNonce.add(nonceIncrement).toNumber(),
312+
nonce: nextUnusedNonce,
313+
});
314+
315+
logger({
316+
service: "worker",
317+
level: "info",
318+
message: `[processTx] Updated nonce to ${nextUnusedNonce} for ${walletAddress}.`,
301319
});
302320

303321
// Update DB state in parallel.
@@ -516,7 +534,17 @@ export const processTx = async () => {
516534
}
517535
});
518536

537+
logger({
538+
service: "worker",
539+
level: "info",
540+
message: `[processTx] Awaiting transactions/userOps promises...`,
541+
});
519542
await Promise.all([...sentTxs, ...sentUserOps]);
543+
logger({
544+
service: "worker",
545+
level: "info",
546+
message: `[processTx] Transactions/userOps completed.`,
547+
});
520548
},
521549
{
522550
// TODO: Should be dynamic with the batch size.
@@ -534,6 +562,8 @@ export const processTx = async () => {
534562
error: err,
535563
});
536564
}
565+
566+
logger({ service: "worker", level: "info", message: "[processTx] Done" });
537567
};
538568

539569
const alertOnBackendWalletLowBalance = async (wallet: UserWallet) => {

0 commit comments

Comments
 (0)