Skip to content

Commit

Permalink
fix:catch rpc error on fetch start block
Browse files Browse the repository at this point in the history
  • Loading branch information
py-zoid committed Nov 5, 2024
1 parent 2893fb1 commit 599cd18
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
14 changes: 10 additions & 4 deletions internal/block_getters/block_getter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class BlockGetter extends BlockFormatter implements IBlockGetter {

if (!block) {
throw new BlockProducerError(
"Block producer error",
"Block producer error on getBlockWithTransactions",
BlockProducerError.codes.RECEIPT_NOT_FOUND,
true,
`null receipt found for block ${blockNumber}.`,
Expand All @@ -90,7 +90,7 @@ export class BlockGetter extends BlockFormatter implements IBlockGetter {
} catch (error) {
if (!(error instanceof BlockProducerError)) {
throw new BlockProducerError(
"Block producer error",
"Block producer error on getBlockWithTransactions",
BlockProducerError.codes.RPC_ERR,
true,
JSON.stringify(error),
Expand Down Expand Up @@ -148,7 +148,7 @@ export class BlockGetter extends BlockFormatter implements IBlockGetter {

if (transactionReceipt === null) {
throw new BlockProducerError(
"Block producer error",
"Block producer error on transaction receipt",
BlockProducerError.codes.RECEIPT_NOT_FOUND,
true,
`Transaction receipt not found for ${transactionHash}.`,
Expand All @@ -159,7 +159,13 @@ export class BlockGetter extends BlockFormatter implements IBlockGetter {
return this.formatTransactionReceipt(transactionReceipt);
} catch (error) {
if (!(error instanceof BlockProducerError)) {
throw error;
throw new BlockProducerError(
"Block producer error on transaction receipt",
BlockProducerError.codes.RPC_ERR,
true,
JSON.stringify(error),
"remote"
);
}
if (errorCount > this.maxRetries) {
Logger.info({
Expand Down
22 changes: 16 additions & 6 deletions internal/block_producers/block_producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,23 @@ export class BlockProducer extends AsynchronousProducer {
return this.startBlock;
}

const remoteBlock = await this.blockGetter.getBlock(block.number);

if (remoteBlock.hash === block.hash) {
return (remoteBlock.number + 1);
try {
const remoteBlock = await this.blockGetter.getBlock(block.number);

if (remoteBlock.hash === block.hash) {
return (remoteBlock.number + 1);
}

blockNumber = remoteBlock.number - 1;
} catch (error) {
this.onError(new BlockProducerError(
"Remote block fetch error",
BlockProducerError.codes.RPC_ERR,
true,
"Error fetching remote block in getStartBlock",
"remote"
));
}

blockNumber = remoteBlock.number - 1;
}

return blockNumber || this.startBlock;
Expand Down

0 comments on commit 599cd18

Please sign in to comment.