Skip to content

Commit 65252f7

Browse files
committed
watcher: supervisor supports ntt mode
1 parent 41df34b commit 65252f7

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

watcher/src/consts.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Chain, Network, contracts } from '@wormhole-foundation/sdk-base';
2+
import { Mode } from '@wormhole-foundation/wormhole-monitor-common';
23
import { AxiosRequestConfig } from 'axios';
34

45
export const TIMEOUT = 0.5 * 1000;
56
export const HB_INTERVAL = 5 * 60 * 1000; // 5 Minutes
67
export type WorkerData = {
78
network: Network;
89
chain: Chain;
10+
mode: Mode;
911
};
1012

1113
// Notes about RPCs

watcher/src/index.ts

-6
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,8 @@ const supportedNTTChains: Chain[] =
8686
: [];
8787

8888
if (mode === 'vaa') {
89-
for (const chain of supportedChains) {
90-
makeFinalizedWatcher(network, chain).watch();
91-
}
9289
startSupervisor(supportedChains);
9390
} else if (mode === 'ntt') {
94-
for (const chain of supportedNTTChains) {
95-
makeFinalizedNTTWatcher(network, chain).watch();
96-
}
9791
startSupervisor(supportedNTTChains);
9892
} else {
9993
throw new Error(`Unknown mode: ${mode}`);

watcher/src/workers/supervisor.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Worker } from 'worker_threads';
22
import { HB_INTERVAL, WorkerData } from '../consts';
33
import { getLogger } from '../utils/logger';
4-
import { getNetwork } from '@wormhole-foundation/wormhole-monitor-common';
4+
import { Mode, getMode, getNetwork } from '@wormhole-foundation/wormhole-monitor-common';
55
import { Chain, Network } from '@wormhole-foundation/sdk-base';
66

77
interface WorkerInfo {
@@ -13,10 +13,11 @@ interface WorkerInfo {
1313
const workers: { [key: string]: WorkerInfo } = {};
1414
const logger = getLogger('supervisor');
1515
const network: Network = getNetwork();
16+
const mode: Mode = getMode();
1617

1718
function spawnWorker(data: WorkerData) {
1819
const workerName = `${data.chain}Worker`;
19-
logger.info(`Spawning worker ${workerName} on network ${network}...`);
20+
logger.info(`Spawning worker ${workerName} on network ${network} in mode ${mode}...`);
2021
const worker = new Worker('./dist/src/workers/worker.js', { workerData: data });
2122

2223
worker.on('message', (message) => {
@@ -55,7 +56,7 @@ function monitorWorkers() {
5556

5657
export function startSupervisor(supportedChains: Chain[]) {
5758
supportedChains.forEach((chain) => {
58-
const workerData: WorkerData = { network, chain };
59+
const workerData: WorkerData = { network, chain, mode };
5960
spawnWorker(workerData);
6061
});
6162

watcher/src/workers/worker.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import { initDb } from '../databases/utils';
2-
import { makeFinalizedWatcher } from '../watchers/utils';
2+
import { makeFinalizedNTTWatcher, makeFinalizedWatcher } from '../watchers/utils';
33
import { workerData } from 'worker_threads';
44

55
initDb(false);
66
const network = workerData.network;
77
const chain = workerData.chain;
8-
console.log(`Making watcher for ${network} ${chain}...`);
9-
makeFinalizedWatcher(network, chain).watch();
10-
console.log(`Watcher for ${network} ${chain} started.`);
8+
const mode = workerData.mode;
9+
console.log(`Making watcher for ${network}, ${chain}, ${mode}...`);
10+
if (mode === 'vaa') {
11+
makeFinalizedWatcher(network, chain).watch();
12+
} else if (mode === 'ntt') {
13+
makeFinalizedNTTWatcher(network, chain).watch();
14+
} else {
15+
throw new Error(`Unknown mode: ${mode}`);
16+
}
17+
console.log(`Watcher for ${network}, ${chain}, ${mode} started.`);

0 commit comments

Comments
 (0)