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

scripts: get solana missed message accounts #61

Merged
merged 1 commit into from
Feb 6, 2024
Merged
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
73 changes: 73 additions & 0 deletions watcher/scripts/solanaMissedMessageAccounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import * as dotenv from 'dotenv';
dotenv.config();

import { CONTRACTS } from '@certusone/wormhole-sdk/lib/cjs/utils/consts';
import { Connection } from '@solana/web3.js';
import axios from 'axios';
import ora from 'ora';
import { RPCS_BY_CHAIN } from '../src/consts';
import { isLegacyMessage, normalizeCompileInstruction } from '../src/utils/solana';

// This script finds the message accounts which correspond to solana misses

(async () => {
const now = new Date();
now.setHours(now.getHours() - 2);
const twoHoursAgo = now.toISOString();
let log = ora('Fetching Solana misses').start();
try {
const response = await axios.get(
'https://europe-west3-wormhole-message-db-mainnet.cloudfunctions.net/missing-vaas'
);
const solanaTxHashes = response.data[1].messages
.filter((m: any) => m.timestamp < twoHoursAgo)
.map((m: any) => m.txHash);
log.succeed();
log = ora('Fetching message accounts').start();
const connection = new Connection(RPCS_BY_CHAIN.mainnet.solana!, 'finalized');
const txs = await connection.getTransactions(solanaTxHashes, {
maxSupportedTransactionVersion: 0,
});
// TODO: share with Solana watcher?
const accounts = [];
let errorCount = 0;
for (const tx of txs) {
if (!tx) {
errorCount++;
} else {
const message = tx.transaction.message;
const accountKeys = isLegacyMessage(message)
? message.accountKeys
: message.staticAccountKeys;
const programIdIndex = accountKeys.findIndex(
(i) => i.toBase58() === CONTRACTS.MAINNET.solana.core
);
const instructions = message.compiledInstructions;
const innerInstructions =
tx.meta?.innerInstructions?.flatMap((i) =>
i.instructions.map(normalizeCompileInstruction)
) || [];
const whInstructions = innerInstructions
.concat(instructions)
.filter((i) => i.programIdIndex === programIdIndex);
for (const instruction of whInstructions) {
// skip if not postMessage instruction
const instructionId = instruction.data;
if (instructionId[0] !== 0x01) continue;

accounts.push(accountKeys[instruction.accountKeyIndexes[1]]);
}
}
}
log.succeed();
for (const a of accounts) {
console.log(`send-observation-request 1 ${a}`);
}
console.log(
`Fetch ${accounts.length} accounts from ${solanaTxHashes.length} transactions with ${errorCount} errors`
);
} catch (e) {
log.fail();
console.error(e);
}
})();