Skip to content

Commit 4d244a1

Browse files
committed
watcher: improve fetchMissingVaaMessages
1 parent c99a51e commit 4d244a1

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

watcher/scripts/fetchMissingVAAs.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ const missingVaas: { [id: string]: string | undefined } = {};
2727
const now = Math.floor(Date.now() / 1000);
2828
try {
2929
let log = ora('Fetching messages without a signed VAA...').start();
30+
// @ts-ignore
31+
const beforeFetch = performance.now();
3032
const missingVaaMessages = await bt.fetchMissingVaaMessages();
31-
log.succeed();
33+
// @ts-ignore
34+
const afterFetch = performance.now();
35+
log.succeed(
36+
`Fetched messages without a signed VAA in ${((afterFetch - beforeFetch) / 1000).toFixed(2)}s`
37+
);
3238
const total = missingVaaMessages.length;
3339
let found = 0;
3440
let search = 0;
@@ -64,7 +70,8 @@ const missingVaas: { [id: string]: string | undefined } = {};
6470
tooNew++;
6571
}
6672
} else {
67-
missingVaas[id] = observedMessage.data.info.txHash?.[0].value;
73+
// TODO: txHash is no longer returned, do a bulk lookup at the end
74+
missingVaas[id] = observedMessage.data.info.txHash?.[0].value || '';
6875
}
6976
}
7077
log.succeed();

watcher/src/databases/BigtableDatabase.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,25 @@ export class BigtableDatabase extends Database {
184184
}
185185
}
186186

187+
/**
188+
* Returns message table rows where `hasSignedVAA === 0`. Note, this does not return all columns.
189+
*/
187190
async fetchMissingVaaMessages(): Promise<BigtableMessagesResultRow[]> {
188191
const instance = this.bigtable.instance(this.instanceId);
189192
const messageTable = instance.table(this.msgTableId);
190-
// TODO: how to filter to only messages with hasSignedVaa === 0
191-
const observedMessages = (await messageTable.getRows())[0] as BigtableMessagesResultRow[];
192-
const missingVaaMessages = observedMessages.filter(
193-
(x) => x.data.info.hasSignedVaa?.[0].value === 0
194-
);
195-
return missingVaaMessages;
193+
const observedMessages = (
194+
await messageTable.getRows({
195+
filter: [
196+
{
197+
column: /^hasSignedVaa$/,
198+
},
199+
{
200+
value: { start: { value: 0, inclusive: true }, end: { value: 1, inclusive: false } },
201+
},
202+
],
203+
})
204+
)[0] as BigtableMessagesResultRow[];
205+
return observedMessages;
196206
}
197207

198208
async watchMissing(): Promise<void> {

0 commit comments

Comments
 (0)