Skip to content

Commit

Permalink
chore: add scan mempool chunk delay
Browse files Browse the repository at this point in the history
  • Loading branch information
perfogic committed Oct 3, 2024
1 parent 1dcbd11 commit 66ccb84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/orchestrator/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export const RELAY_HEADER_BATCH_SIZE = 250;
export const SCAN_MEMPOOL_CHUNK_SIZE = 1000;
export const SCAN_MEMPOOL_CHUNK_INTERVAL_DELAY = 100;
export const RELAY_DEPOSIT_BLOCKS_SIZE = 200; // 10 blocks
export const RETRY_DELAY = 1000; // 1 second
export const ITERATION_DELAY = {
Expand Down
9 changes: 8 additions & 1 deletion packages/orchestrator/src/services/relayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
RELAY_DEPOSIT_BLOCKS_SIZE,
RELAY_HEADER_BATCH_SIZE,
RETRY_DELAY,
SCAN_MEMPOOL_CHUNK_INTERVAL_DELAY,
SCAN_MEMPOOL_CHUNK_SIZE,
} from "../../constants";
import { chunkArray } from "../../utils/array";
Expand Down Expand Up @@ -335,7 +336,6 @@ class RelayerService implements RelayerInterface {
const txChunks = chunkArray(mempoolTxs, SCAN_MEMPOOL_CHUNK_SIZE);
let i = 0;
for (const txChunk of txChunks) {
console.log("Chunk", i);
i++;
let detailMempoolTxs: BitcoinTransaction[] = await retry(
async () => {
Expand All @@ -351,6 +351,11 @@ class RelayerService implements RelayerInterface {
3,
RETRY_DELAY
);
console.log(
"Chunk",
i,
detailMempoolTxs.map((item) => item.hash)
);

for (const tx of detailMempoolTxs) {
let txid = tx.txid;
Expand Down Expand Up @@ -397,6 +402,8 @@ class RelayerService implements RelayerInterface {
);
}
}

await setTimeout(SCAN_MEMPOOL_CHUNK_INTERVAL_DELAY);
}
} catch (err) {
this.logger.error(`[SCAN_TX_FROM_MEMPOOL] ${err?.message}`);
Expand Down

0 comments on commit 66ccb84

Please sign in to comment.