Skip to content

Commit

Permalink
feat(evm::listener): if synced, wait for some time before checking again
Browse files Browse the repository at this point in the history
  • Loading branch information
imsk17 committed Sep 4, 2024
1 parent 680be84 commit b44796c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/handler/evm/utils/listenForLockEvents.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setTimeout } from "node:timers/promises";
import type { EntityManager } from "@mikro-orm/sqlite";
import type { JsonRpcProvider } from "ethers";
import type { EventBuilder } from "../..";
Expand Down Expand Up @@ -27,6 +28,10 @@ const listenForLockEvents = (
lastBlock + blockChunks < latestBlockNumber
? lastBlock + blockChunks
: latestBlockNumber;
if (lastBlock >= latestBlock) {
await setTimeout(2000); // Sleep for 2 seconds
continue;
}

const logs = await provider.getLogs({
fromBlock: lastBlock,
Expand All @@ -48,7 +53,7 @@ const listenForLockEvents = (
lastBlock: lastBlock,
});
await em.flush();
await new Promise<undefined>((e) => setTimeout(e, 10000));
await setTimeout(10000);
continue;
}
for (const log of logs.filter(
Expand Down Expand Up @@ -92,7 +97,7 @@ const listenForLockEvents = (
`${e} while listening for lock events. Sleeping for 10 seconds`,
chainIdent,
);
await new Promise((e) => setTimeout(e, 10000));
await setTimeout(10000);
}
}
};
Expand Down

0 comments on commit b44796c

Please sign in to comment.