Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watcher: refactor #407

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions watcher/scripts/backfillArbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import axios from 'axios';
import ora from 'ora';
import { initDb } from '../src/databases/utils';
import { AXIOS_CONFIG_JSON } from '../src/consts';
import { ArbitrumWatcher } from '../src/watchers/ArbitrumWatcher';
import { LOG_MESSAGE_PUBLISHED_TOPIC } from '../src/watchers/EVMWatcher';
import { EVMWatcher, LOG_MESSAGE_PUBLISHED_TOPIC } from '../src/watchers/EVMWatcher';
import { Chain, contracts } from '@wormhole-foundation/sdk-base';

// This script exists because the Arbitrum RPC node only supports a 10 block range which is super slow
Expand All @@ -27,7 +26,7 @@ import { Chain, contracts } from '@wormhole-foundation/sdk-base';
log.succeed(`Fetched ${blockNumbers.length} logs from Arbiscan`);
// use the watcher to fetch corresponding blocks
log = ora('Fetching blocks...').start();
const watcher = new ArbitrumWatcher('Mainnet');
const watcher = new EVMWatcher('Mainnet', 'Arbitrum', 'finalized', 'vaa');
for (const blockNumber of blockNumbers) {
log.text = `Fetching block ${blockNumber}`;
const { vaasByBlock } = await watcher.getMessagesForBlocks(blockNumber, blockNumber);
Expand Down
4 changes: 2 additions & 2 deletions watcher/scripts/locateMessageGaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { TIMEOUT } from '../src/consts';
import { BigtableDatabase } from '../src/databases/BigtableDatabase';
import { parseMessageId } from '../src/databases/utils';
import { makeFinalizedWatcher } from '../src/watchers/utils';
import { makeFinalizedVaaWatcher } from '../src/watchers/utils';
import { Watcher } from '../src/watchers/Watcher';
import { ChainId, Network, toChain, toChainId } from '@wormhole-foundation/sdk-base';

Expand Down Expand Up @@ -95,7 +95,7 @@ import { ChainId, Network, toChain, toChainId } from '@wormhole-foundation/sdk-b
}
let watcher: Watcher;
try {
watcher = makeFinalizedWatcher(network, chainName);
watcher = makeFinalizedVaaWatcher(network, chainName);
} catch (e) {
console.error('skipping gap for unsupported chain', chainName);
continue;
Expand Down
2 changes: 1 addition & 1 deletion watcher/src/watchers/AlgorandWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AlgorandWatcher extends Watcher {
indexerClient: algosdk.Indexer;

constructor(network: Network) {
super(network, 'Algorand');
super(network, 'Algorand', 'vaa');

if (!ALGORAND_INFO[this.network].algodServer) {
throw new Error('ALGORAND_INFO.algodServer is not defined!');
Expand Down
2 changes: 1 addition & 1 deletion watcher/src/watchers/AptosWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class AptosWatcher extends Watcher {
eventHandle: string;

constructor(network: Network) {
super(network, 'Aptos');
super(network, 'Aptos', 'vaa');
this.client = new AptosClient(RPCS_BY_CHAIN[this.network][this.chain]!);
this.coreBridgeAddress = contracts.coreBridge(network, 'Aptos');
this.eventHandle = `${this.coreBridgeAddress}::state::WormholeMessageHandle`;
Expand Down
135 changes: 0 additions & 135 deletions watcher/src/watchers/ArbitrumWatcher.ts

This file was deleted.

12 changes: 0 additions & 12 deletions watcher/src/watchers/BSCWatcher.ts

This file was deleted.

2 changes: 1 addition & 1 deletion watcher/src/watchers/CosmwasmWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class CosmwasmWatcher extends Watcher {
latestBlockHeight: number;

constructor(network: Network, chain: PlatformToChains<'Cosmwasm'>) {
super(network, chain);
super(network, chain, 'vaa');
if (chain === 'Injective') {
throw new Error('Please use InjectiveExplorerWatcher for injective');
}
Expand Down
28 changes: 4 additions & 24 deletions watcher/src/watchers/EVMWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { makeBlockKey, makeVaaKey } from '../databases/utils';
import { Watcher } from './Watcher';
import { Network, PlatformToChains, contracts } from '@wormhole-foundation/sdk-base';
import { ethers_contracts } from '@wormhole-foundation/sdk-evm-core';
import { Mode } from '@wormhole-foundation/wormhole-monitor-common';

// This is the hash for topic[0] of the core contract event LogMessagePublished
// https://github.com/wormhole-foundation/wormhole/blob/main/ethereum/contracts/Implementation.sol#L12
Expand Down Expand Up @@ -34,34 +35,13 @@ export class EVMWatcher extends Watcher {
constructor(
network: Network,
chain: PlatformToChains<'Evm'>,
finalizedBlockTag: BlockTag = 'latest'
finalizedBlockTag: BlockTag,
mode: Mode
) {
super(network, chain);
super(network, chain, mode);
this.lastTimestamp = 0;
this.latestFinalizedBlockNumber = 0;
this.finalizedBlockTag = finalizedBlockTag;
// Special cases for batch size
if (chain === 'Acala' || chain === 'Karura' || chain === 'Berachain') {
this.maximumBatchSize = 50;
} else if (
chain === 'Blast' ||
chain === 'Klaytn' ||
chain === 'Scroll' ||
chain === 'Snaxchain' ||
chain === 'Unichain' ||
chain === 'Worldchain' ||
chain === 'Monad' ||
chain === 'Ink' ||
chain === 'HyperEVM' ||
chain === 'Seievm' ||
chain === 'Xlayer'
) {
this.maximumBatchSize = 10;
}
// Special cases for watch loop delay
if (chain === 'Berachain') {
this.watchLoopDelay = 1000;
}
}

async getBlock(blockNumberOrTag: number | BlockTag): Promise<Block> {
Expand Down
Loading
Loading