Skip to content

Commit

Permalink
fix: fall back if block not found when checking mined (#426)
Browse files Browse the repository at this point in the history
* fix: fall back if block not found when checking mined

* warn
  • Loading branch information
arcoraven authored Feb 23, 2024
1 parent ce609ee commit 8f3eb35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
4 changes: 0 additions & 4 deletions src/worker/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { clearCacheCron } from "../utils/cron/clearCacheCron";
import {
newConfigurationListener,
updatedConfigurationListener,
Expand Down Expand Up @@ -32,7 +31,4 @@ export const initWorker = async () => {
// Listen for new & updated webhooks data
await newWebhooksListener();
await updatedWebhooksListener();

// Rest Cache Cron
await clearCacheCron("worker");
};
43 changes: 23 additions & 20 deletions src/worker/tasks/updateMinedTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const updateMinedTx = async () => {
await prisma.$transaction(
async (pgtx) => {
const txs = await getSentTxs({ pgtx });

if (txs.length === 0) {
return;
}
Expand All @@ -32,13 +31,12 @@ export const updateMinedTx = async () => {
await Promise.all(
txs.map(async (tx) => {
const sdk = await getSdk({ chainId: parseInt(tx.chainId!) });
const receipt: ethers.providers.TransactionReceipt | undefined =
await sdk
.getProvider()
.getTransactionReceipt(tx.transactionHash!);
const provider =
sdk.getProvider() as ethers.providers.JsonRpcProvider;

const receipt: ethers.providers.TransactionReceipt | undefined =
await provider.getTransactionReceipt(tx.transactionHash!);

if (!receipt) {
// This tx is not yet mined or was dropped.

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

const response = (await sdk
.getProvider()
.getTransaction(
tx.transactionHash!,
)) as ethers.providers.TransactionResponse | null;

// Get the timestamp when the transaction was mined
const minedAt = new Date(
(
await getBlock({
block: receipt.blockNumber,
network: sdk.getProvider(),
})
).timestamp * 1000,
);
const response = (await provider.getTransaction(
tx.transactionHash!,
)) as ethers.providers.TransactionResponse | null;

// Get the timestamp when the transaction was mined. Fall back to curent time.
const block = await getBlock({
block: receipt.blockNumber,
network: provider,
});
if (!block) {
logger({
service: "worker",
level: "warn",
queueId: tx.id,
message: `Block not found (provider=${provider.connection.url}).`,
});
}
const minedAt = block
? new Date(block.timestamp * 1000)
: new Date();

return {
tx,
Expand Down

0 comments on commit 8f3eb35

Please sign in to comment.