Skip to content

Commit

Permalink
chore: update script
Browse files Browse the repository at this point in the history
  • Loading branch information
perfogic committed Oct 3, 2024
1 parent af482b8 commit b589a46
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/orchestrator/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const SCAN_MEMPOOL_CHUNK_SIZE = 1000;
export const SCAN_MEMPOOL_CHUNK_DELAY = 1000; // 1 second
export const RELAY_DEPOSIT_BLOCKS_SIZE = 200; // 10 blocks
export const RETRY_DELAY = 1000; // 1 second
export const SCAN_RAW_MEMPOOL_CHUNK_SIZE = 3000;
export const ITERATION_DELAY = {
RELAY_HEADER_BATCH_DELAY: 500,
RELAY_HEADER_INTERVAL: 10000,
Expand Down
34 changes: 20 additions & 14 deletions packages/orchestrator/src/script.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RPCClient } from "rpc-bitcoin";
import { RETRY_DELAY } from "./constants";
import { chunkArray } from "./utils/array";
import { retry } from "./utils/catchAsync";

const main = async () => {
Expand All @@ -12,20 +13,25 @@ const main = async () => {

let mempoolTxs = await btcClient.getrawmempool({});
const time = new Date().getTime();
let detailMempoolTxs = await retry(
async () => {
return (
await btcClient.batch([
...mempoolTxs.map((txid: string) => ({
method: "getrawtransaction",
params: [txid, true],
})),
])
).map((item) => item.result);
},
10,
RETRY_DELAY
);
const txChunks = chunkArray(mempoolTxs, 3000);
let detailMempoolTxs = [];
for (const txChunk of txChunks) {
let result = await retry(
async () => {
return (
await btcClient.batch([
...txChunk.map((txid: string) => ({
method: "getrawtransaction",
params: [txid, true],
})),
])
).map((item) => item.result);
},
3,
RETRY_DELAY
);
detailMempoolTxs = [...result];
}
const nextTime = new Date().getTime();

console.log(detailMempoolTxs.length, (nextTime - time) / 1000);
Expand Down
7 changes: 7 additions & 0 deletions packages/orchestrator/src/utils/array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const chunkArray = <T>(array: T[], chunkSize: number): T[][] => {
const chunks = [];
for (let i = 0; i < array.length; i += chunkSize) {
chunks.push(array.slice(i, i + chunkSize));
}
return chunks;
};

0 comments on commit b589a46

Please sign in to comment.