Skip to content

Commit

Permalink
troubleshooting
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Jul 26, 2023
1 parent 84652e4 commit e9c4929
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 7 additions & 1 deletion watcher/src/watchers/AlgorandWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class AlgorandWatcher extends Watcher {
if (!ALGORAND_INFO.algodServer) {
throw new Error('ALGORAND_INFO.algodServer is not defined!');
}

this.algodClient = new algosdk.Algodv2(
ALGORAND_INFO.algodToken,
ALGORAND_INFO.algodServer,
Expand All @@ -39,6 +38,7 @@ export class AlgorandWatcher extends Watcher {
this.logger.info(`fetching final block for ${this.chain}`);

let status = await this.algodClient.status().do();
this.logger.info(`got final block for ${this.chain} = ${status['last-round']}`);
return status['last-round'];
}

Expand Down Expand Up @@ -97,10 +97,14 @@ export class AlgorandWatcher extends Watcher {
}

async getMessagesForBlocks(fromBlock: number, toBlock: number): Promise<VaasByBlock> {
this.logger.info('getMessagesForBlocks', fromBlock, toBlock);
const txIds = await this.getApplicationLogTransactionIds(fromBlock, toBlock);
this.logger.info('txIds', txIds);
const transactions = [];
for (const txId of txIds) {
this.logger.info('txId', txId);
const response = await this.indexerClient.searchForTransactions().txid(txId).do();
this.logger.info('response', response);
if (response?.transactions?.[0]) {
transactions.push(response.transactions[0]);
}
Expand All @@ -116,7 +120,9 @@ export class AlgorandWatcher extends Watcher {
vaasByBlock[message.blockKey].push(message.vaaKey);
return vaasByBlock;
}, {} as VaasByBlock);
this.logger.info('attempting to call lookupBlock...');
const toBlockInfo = await this.indexerClient.lookupBlock(toBlock).do();
this.logger.info('toBlockInfo', toBlockInfo);
const toBlockTimestamp = new Date(toBlockInfo.timestamp * 1000).toISOString();
const toBlockKey = makeBlockKey(toBlock.toString(), toBlockTimestamp);
if (!vaasByBlock[toBlockKey]) {
Expand Down
15 changes: 11 additions & 4 deletions watcher/src/watchers/SolanaWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class SolanaWatcher extends Watcher {
}

async getMessagesForBlocks(fromSlot: number, toSlot: number): Promise<VaasByBlock> {
this.logger.info('getMessagesForBlocks in');
const connection = new Connection(this.rpc, COMMITMENT);
// in the rare case of maximumBatchSize skipped blocks in a row,
// you might hit this error due to the recursion below
Expand All @@ -53,34 +54,39 @@ export class SolanaWatcher extends Watcher {
// getSignaturesForAddress walks backwards so fromSignature occurs after toSignature
let toBlock: VersionedBlockResponse | null = null;
try {
this.logger.info(`fetching block ${toSlot} (toSlot)`);
toBlock = await connection.getBlock(toSlot, { maxSupportedTransactionVersion: 0 });
} catch (e) {
if (e instanceof SolanaJSONRPCError && (e.code === -32007 || e.code === -32009)) {
// failed to get confirmed block: slot was skipped or missing in long-term storage
return this.getMessagesForBlocks(fromSlot, toSlot - 1);
return await this.getMessagesForBlocks(fromSlot, toSlot - 1);
} else {
throw e;
}
}
if (!toBlock || !toBlock.blockTime || toBlock.transactions.length === 0) {
return this.getMessagesForBlocks(fromSlot, toSlot - 1);
this.logger.info(`block ${toSlot} is empty, recursing...(toSlot)`);
return await this.getMessagesForBlocks(fromSlot, toSlot - 1);
}
const fromSignature =
toBlock.transactions[toBlock.transactions.length - 1].transaction.signatures[0];

let fromBlock: VersionedBlockResponse | null = null;
try {
this.logger.info(`fetching block ${fromSlot} (fromSlot)`);
fromBlock = await connection.getBlock(fromSlot, { maxSupportedTransactionVersion: 0 });
} catch (e) {
if (e instanceof SolanaJSONRPCError && (e.code === -32007 || e.code === -32009)) {
// failed to get confirmed block: slot was skipped or missing in long-term storage
return this.getMessagesForBlocks(fromSlot + 1, toSlot);
this.logger.info(`block ${fromSlot} is empty, recursing...(fromSlot)`);
return await this.getMessagesForBlocks(fromSlot + 1, toSlot);
} else {
throw e;
}
}
if (!fromBlock || !fromBlock.blockTime || fromBlock.transactions.length === 0) {
return this.getMessagesForBlocks(fromSlot + 1, toSlot);
this.logger.info(`block ${fromSlot} is empty, recursing...(fromSlot2)`);
return await this.getMessagesForBlocks(fromSlot + 1, toSlot);
}
const toSignature = fromBlock.transactions[0].transaction.signatures[0];

Expand Down Expand Up @@ -167,6 +173,7 @@ export class SolanaWatcher extends Watcher {
numSignatures = signatures.length;
currSignature = signatures.at(-1)?.signature;
}
this.logger.info('getMessagesForBlocks out');

// add last block for storeVaasByBlock
const lastBlockKey = makeBlockKey(
Expand Down

0 comments on commit e9c4929

Please sign in to comment.