Skip to content

Commit

Permalink
watcher: improve fetchMissingVaaMessages
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-gray committed Mar 28, 2024
1 parent c99a51e commit 4d244a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
11 changes: 9 additions & 2 deletions watcher/scripts/fetchMissingVAAs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ const missingVaas: { [id: string]: string | undefined } = {};
const now = Math.floor(Date.now() / 1000);
try {
let log = ora('Fetching messages without a signed VAA...').start();
// @ts-ignore
const beforeFetch = performance.now();
const missingVaaMessages = await bt.fetchMissingVaaMessages();
log.succeed();
// @ts-ignore
const afterFetch = performance.now();
log.succeed(
`Fetched messages without a signed VAA in ${((afterFetch - beforeFetch) / 1000).toFixed(2)}s`
);
const total = missingVaaMessages.length;
let found = 0;
let search = 0;
Expand Down Expand Up @@ -64,7 +70,8 @@ const missingVaas: { [id: string]: string | undefined } = {};
tooNew++;
}
} else {
missingVaas[id] = observedMessage.data.info.txHash?.[0].value;
// TODO: txHash is no longer returned, do a bulk lookup at the end
missingVaas[id] = observedMessage.data.info.txHash?.[0].value || '';
}
}
log.succeed();
Expand Down
22 changes: 16 additions & 6 deletions watcher/src/databases/BigtableDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,25 @@ export class BigtableDatabase extends Database {
}
}

/**
* Returns message table rows where `hasSignedVAA === 0`. Note, this does not return all columns.
*/
async fetchMissingVaaMessages(): Promise<BigtableMessagesResultRow[]> {
const instance = this.bigtable.instance(this.instanceId);
const messageTable = instance.table(this.msgTableId);
// TODO: how to filter to only messages with hasSignedVaa === 0
const observedMessages = (await messageTable.getRows())[0] as BigtableMessagesResultRow[];
const missingVaaMessages = observedMessages.filter(
(x) => x.data.info.hasSignedVaa?.[0].value === 0
);
return missingVaaMessages;
const observedMessages = (
await messageTable.getRows({
filter: [
{
column: /^hasSignedVaa$/,
},
{
value: { start: { value: 0, inclusive: true }, end: { value: 1, inclusive: false } },
},
],
})
)[0] as BigtableMessagesResultRow[];
return observedMessages;
}

async watchMissing(): Promise<void> {
Expand Down

0 comments on commit 4d244a1

Please sign in to comment.