Skip to content

Commit ba3aa4d

Browse files
committed
watcher: refactor
1 parent 1bf6a32 commit ba3aa4d

28 files changed

+145
-724
lines changed

watcher/scripts/backfillArbitrum.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import axios from 'axios';
44
import ora from 'ora';
55
import { initDb } from '../src/databases/utils';
66
import { AXIOS_CONFIG_JSON } from '../src/consts';
7-
import { ArbitrumWatcher } from '../src/watchers/ArbitrumWatcher';
8-
import { LOG_MESSAGE_PUBLISHED_TOPIC } from '../src/watchers/EVMWatcher';
7+
import { EVMWatcher, LOG_MESSAGE_PUBLISHED_TOPIC } from '../src/watchers/EVMWatcher';
98
import { Chain, contracts } from '@wormhole-foundation/sdk-base';
109

1110
// This script exists because the Arbitrum RPC node only supports a 10 block range which is super slow
@@ -27,7 +26,7 @@ import { Chain, contracts } from '@wormhole-foundation/sdk-base';
2726
log.succeed(`Fetched ${blockNumbers.length} logs from Arbiscan`);
2827
// use the watcher to fetch corresponding blocks
2928
log = ora('Fetching blocks...').start();
30-
const watcher = new ArbitrumWatcher('Mainnet');
29+
const watcher = new EVMWatcher('Mainnet', 'Arbitrum', 'finalized', 'vaa');
3130
for (const blockNumber of blockNumbers) {
3231
log.text = `Fetching block ${blockNumber}`;
3332
const { vaasByBlock } = await watcher.getMessagesForBlocks(blockNumber, blockNumber);

watcher/scripts/locateMessageGaps.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { TIMEOUT } from '../src/consts';
99
import { BigtableDatabase } from '../src/databases/BigtableDatabase';
1010
import { parseMessageId } from '../src/databases/utils';
11-
import { makeFinalizedWatcher } from '../src/watchers/utils';
11+
import { makeFinalizedVaaWatcher } from '../src/watchers/utils';
1212
import { Watcher } from '../src/watchers/Watcher';
1313
import { ChainId, Network, toChain, toChainId } from '@wormhole-foundation/sdk-base';
1414

@@ -95,7 +95,7 @@ import { ChainId, Network, toChain, toChainId } from '@wormhole-foundation/sdk-b
9595
}
9696
let watcher: Watcher;
9797
try {
98-
watcher = makeFinalizedWatcher(network, chainName);
98+
watcher = makeFinalizedVaaWatcher(network, chainName);
9999
} catch (e) {
100100
console.error('skipping gap for unsupported chain', chainName);
101101
continue;

watcher/src/watchers/AlgorandWatcher.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class AlgorandWatcher extends Watcher {
1818
indexerClient: algosdk.Indexer;
1919

2020
constructor(network: Network) {
21-
super(network, 'Algorand');
21+
super(network, 'Algorand', 'vaa');
2222

2323
if (!ALGORAND_INFO[this.network].algodServer) {
2424
throw new Error('ALGORAND_INFO.algodServer is not defined!');

watcher/src/watchers/AptosWatcher.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class AptosWatcher extends Watcher {
2121
eventHandle: string;
2222

2323
constructor(network: Network) {
24-
super(network, 'Aptos');
24+
super(network, 'Aptos', 'vaa');
2525
this.client = new AptosClient(RPCS_BY_CHAIN[this.network][this.chain]!);
2626
this.coreBridgeAddress = contracts.coreBridge(network, 'Aptos');
2727
this.eventHandle = `${this.coreBridgeAddress}::state::WormholeMessageHandle`;

watcher/src/watchers/ArbitrumWatcher.ts

-135
This file was deleted.

watcher/src/watchers/BSCWatcher.ts

-12
This file was deleted.

watcher/src/watchers/CosmwasmWatcher.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class CosmwasmWatcher extends Watcher {
1616
latestBlockHeight: number;
1717

1818
constructor(network: Network, chain: PlatformToChains<'Cosmwasm'>) {
19-
super(network, chain);
19+
super(network, chain, 'vaa');
2020
if (chain === 'Injective') {
2121
throw new Error('Please use InjectiveExplorerWatcher for injective');
2222
}

watcher/src/watchers/EVMWatcher.ts

+4-24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { makeBlockKey, makeVaaKey } from '../databases/utils';
77
import { Watcher } from './Watcher';
88
import { Network, PlatformToChains, contracts } from '@wormhole-foundation/sdk-base';
99
import { ethers_contracts } from '@wormhole-foundation/sdk-evm-core';
10+
import { Mode } from '@wormhole-foundation/wormhole-monitor-common';
1011

1112
// This is the hash for topic[0] of the core contract event LogMessagePublished
1213
// https://github.com/wormhole-foundation/wormhole/blob/main/ethereum/contracts/Implementation.sol#L12
@@ -34,34 +35,13 @@ export class EVMWatcher extends Watcher {
3435
constructor(
3536
network: Network,
3637
chain: PlatformToChains<'Evm'>,
37-
finalizedBlockTag: BlockTag = 'latest'
38+
finalizedBlockTag: BlockTag,
39+
mode: Mode
3840
) {
39-
super(network, chain);
41+
super(network, chain, mode);
4042
this.lastTimestamp = 0;
4143
this.latestFinalizedBlockNumber = 0;
4244
this.finalizedBlockTag = finalizedBlockTag;
43-
// Special cases for batch size
44-
if (chain === 'Acala' || chain === 'Karura' || chain === 'Berachain') {
45-
this.maximumBatchSize = 50;
46-
} else if (
47-
chain === 'Blast' ||
48-
chain === 'Klaytn' ||
49-
chain === 'Scroll' ||
50-
chain === 'Snaxchain' ||
51-
chain === 'Unichain' ||
52-
chain === 'Worldchain' ||
53-
chain === 'Monad' ||
54-
chain === 'Ink' ||
55-
chain === 'HyperEVM' ||
56-
chain === 'Seievm' ||
57-
chain === 'Xlayer'
58-
) {
59-
this.maximumBatchSize = 10;
60-
}
61-
// Special cases for watch loop delay
62-
if (chain === 'Berachain') {
63-
this.watchLoopDelay = 1000;
64-
}
6545
}
6646

6747
async getBlock(blockNumberOrTag: number | BlockTag): Promise<Block> {

0 commit comments

Comments
 (0)