Skip to content

Commit f11c8b7

Browse files
committed
watcher: storing latest block
1 parent 7eeac4a commit f11c8b7

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

watcher/src/databases/Database.ts

+3
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ export class Database {
2020
async storeVaasByBlock(chain: ChainName, vaasByBlock: VaasByBlock): Promise<void> {
2121
throw new Error('Not Implemented');
2222
}
23+
async storeLatestBlock(chain: ChainName, lastBlockKey: string, isNTT: boolean): Promise<void> {
24+
throw new Error('Not Implemented');
25+
}
2326
}

watcher/src/databases/utils.ts

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ export const initDb = (startWatching: boolean = true): Database => {
7575
return database;
7676
};
7777

78+
export const storeLatestBlock = async (
79+
chain: ChainName,
80+
lastBlockKey: string,
81+
isNTT: boolean
82+
): Promise<void> => {
83+
return database.storeLatestBlock(chain, lastBlockKey, isNTT);
84+
};
85+
7886
export const getResumeBlockByChain = async (
7987
network: Environment,
8088
chain: ChainName,

watcher/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ for (const chain of supportedChains) {
8484
const supportedNTTChains: ChainName[] =
8585
network === 'testnet'
8686
? [
87+
//'solana',
8788
'sepolia',
88-
//'arbitrum_sepolia'
89+
'arbitrum_sepolia',
8990
]
9091
: [];
9192

watcher/src/watchers/NTTWatcher.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ export class NTTWatcher extends Watcher {
221221
return block.number;
222222
}
223223

224-
// TODO: Not sure we want to return VaasByBlock here
225-
async getNttMessagesForBlocks(fromBlock: number, toBlock: number) {
224+
async getNttMessagesForBlocks(fromBlock: number, toBlock: number): Promise<string> {
226225
const nttAddress = NTT_CONTRACT[this.network][this.chain];
227226
if (!nttAddress) {
228227
throw new Error(`NTT manager contract not defined for ${this.network}`);
@@ -427,6 +426,9 @@ export class NTTWatcher extends Watcher {
427426
dumpLifecycleMap(this.lifecycleMap);
428427
await sleep(3000);
429428
}
429+
// Create blockKey
430+
const blockKey = makeBlockKey(toBlock.toString(), timestampsByBlock[toBlock]);
431+
return blockKey;
430432
}
431433
}
432434

watcher/src/watchers/Watcher.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { z } from 'zod';
88
import { TIMEOUT } from '../consts';
99
import { VaasByBlock } from '../databases/types';
10-
import { getResumeBlockByChain, storeVaasByBlock } from '../databases/utils';
10+
import { getResumeBlockByChain, storeLatestBlock, storeVaasByBlock } from '../databases/utils';
1111
import { getLogger, WormholeLogger } from '../utils/logger';
1212

1313
export class Watcher {
@@ -31,7 +31,7 @@ export class Watcher {
3131
throw new Error('Not Implemented');
3232
}
3333

34-
async getNttMessagesForBlocks(fromBlock: number, toBlock: number) {
34+
async getNttMessagesForBlocks(fromBlock: number, toBlock: number): Promise<string> {
3535
throw new Error('Not Implemented');
3636
}
3737

@@ -71,7 +71,8 @@ export class Watcher {
7171
toBlock = Math.min(fromBlock + this.maximumBatchSize - 1, toBlock);
7272
this.logger.info(`fetching messages from ${fromBlock} to ${toBlock}`);
7373
if (this.isNTT) {
74-
await this.getNttMessagesForBlocks(fromBlock, toBlock);
74+
const blockKey = await this.getNttMessagesForBlocks(fromBlock, toBlock);
75+
await storeLatestBlock(this.chain, blockKey, true);
7576
} else {
7677
const vaasByBlock = await this.getMessagesForBlocks(fromBlock, toBlock);
7778
await storeVaasByBlock(this.chain, vaasByBlock);

0 commit comments

Comments
 (0)