Skip to content

Commit

Permalink
watcher: supervisor supports ntt mode
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Apr 5, 2024
1 parent 41df34b commit 65252f7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 2 additions & 0 deletions watcher/src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Chain, Network, contracts } from '@wormhole-foundation/sdk-base';
import { Mode } from '@wormhole-foundation/wormhole-monitor-common';
import { AxiosRequestConfig } from 'axios';

export const TIMEOUT = 0.5 * 1000;
export const HB_INTERVAL = 5 * 60 * 1000; // 5 Minutes
export type WorkerData = {
network: Network;
chain: Chain;
mode: Mode;
};

// Notes about RPCs
Expand Down
6 changes: 0 additions & 6 deletions watcher/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,8 @@ const supportedNTTChains: Chain[] =
: [];

if (mode === 'vaa') {
for (const chain of supportedChains) {
makeFinalizedWatcher(network, chain).watch();
}
startSupervisor(supportedChains);
} else if (mode === 'ntt') {
for (const chain of supportedNTTChains) {
makeFinalizedNTTWatcher(network, chain).watch();
}
startSupervisor(supportedNTTChains);
} else {
throw new Error(`Unknown mode: ${mode}`);
Expand Down
7 changes: 4 additions & 3 deletions watcher/src/workers/supervisor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Worker } from 'worker_threads';
import { HB_INTERVAL, WorkerData } from '../consts';
import { getLogger } from '../utils/logger';
import { getNetwork } from '@wormhole-foundation/wormhole-monitor-common';
import { Mode, getMode, getNetwork } from '@wormhole-foundation/wormhole-monitor-common';
import { Chain, Network } from '@wormhole-foundation/sdk-base';

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

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

worker.on('message', (message) => {
Expand Down Expand Up @@ -55,7 +56,7 @@ function monitorWorkers() {

export function startSupervisor(supportedChains: Chain[]) {
supportedChains.forEach((chain) => {
const workerData: WorkerData = { network, chain };
const workerData: WorkerData = { network, chain, mode };
spawnWorker(workerData);
});

Expand Down
15 changes: 11 additions & 4 deletions watcher/src/workers/worker.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { initDb } from '../databases/utils';
import { makeFinalizedWatcher } from '../watchers/utils';
import { makeFinalizedNTTWatcher, makeFinalizedWatcher } from '../watchers/utils';
import { workerData } from 'worker_threads';

initDb(false);
const network = workerData.network;
const chain = workerData.chain;
console.log(`Making watcher for ${network} ${chain}...`);
makeFinalizedWatcher(network, chain).watch();
console.log(`Watcher for ${network} ${chain} started.`);
const mode = workerData.mode;
console.log(`Making watcher for ${network}, ${chain}, ${mode}...`);
if (mode === 'vaa') {
makeFinalizedWatcher(network, chain).watch();
} else if (mode === 'ntt') {
makeFinalizedNTTWatcher(network, chain).watch();
} else {
throw new Error(`Unknown mode: ${mode}`);
}
console.log(`Watcher for ${network}, ${chain}, ${mode} started.`);

0 comments on commit 65252f7

Please sign in to comment.