Skip to content

Commit 8f3eb35

Browse files
authored
fix: fall back if block not found when checking mined (#426)
* fix: fall back if block not found when checking mined * warn
1 parent ce609ee commit 8f3eb35

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

src/worker/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { clearCacheCron } from "../utils/cron/clearCacheCron";
21
import {
32
newConfigurationListener,
43
updatedConfigurationListener,
@@ -32,7 +31,4 @@ export const initWorker = async () => {
3231
// Listen for new & updated webhooks data
3332
await newWebhooksListener();
3433
await updatedWebhooksListener();
35-
36-
// Rest Cache Cron
37-
await clearCacheCron("worker");
3834
};

src/worker/tasks/updateMinedTx.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const updateMinedTx = async () => {
2121
await prisma.$transaction(
2222
async (pgtx) => {
2323
const txs = await getSentTxs({ pgtx });
24-
2524
if (txs.length === 0) {
2625
return;
2726
}
@@ -32,13 +31,12 @@ export const updateMinedTx = async () => {
3231
await Promise.all(
3332
txs.map(async (tx) => {
3433
const sdk = await getSdk({ chainId: parseInt(tx.chainId!) });
35-
const receipt: ethers.providers.TransactionReceipt | undefined =
36-
await sdk
37-
.getProvider()
38-
.getTransactionReceipt(tx.transactionHash!);
3934
const provider =
4035
sdk.getProvider() as ethers.providers.JsonRpcProvider;
4136

37+
const receipt: ethers.providers.TransactionReceipt | undefined =
38+
await provider.getTransactionReceipt(tx.transactionHash!);
39+
4240
if (!receipt) {
4341
// This tx is not yet mined or was dropped.
4442

@@ -52,21 +50,26 @@ export const updateMinedTx = async () => {
5250
return;
5351
}
5452

55-
const response = (await sdk
56-
.getProvider()
57-
.getTransaction(
58-
tx.transactionHash!,
59-
)) as ethers.providers.TransactionResponse | null;
60-
61-
// Get the timestamp when the transaction was mined
62-
const minedAt = new Date(
63-
(
64-
await getBlock({
65-
block: receipt.blockNumber,
66-
network: sdk.getProvider(),
67-
})
68-
).timestamp * 1000,
69-
);
53+
const response = (await provider.getTransaction(
54+
tx.transactionHash!,
55+
)) as ethers.providers.TransactionResponse | null;
56+
57+
// Get the timestamp when the transaction was mined. Fall back to curent time.
58+
const block = await getBlock({
59+
block: receipt.blockNumber,
60+
network: provider,
61+
});
62+
if (!block) {
63+
logger({
64+
service: "worker",
65+
level: "warn",
66+
queueId: tx.id,
67+
message: `Block not found (provider=${provider.connection.url}).`,
68+
});
69+
}
70+
const minedAt = block
71+
? new Date(block.timestamp * 1000)
72+
: new Date();
7073

7174
return {
7275
tx,

0 commit comments

Comments
 (0)