diff --git a/internal/block_getters/block_getter.ts b/internal/block_getters/block_getter.ts index 30b0488..610c9e5 100644 --- a/internal/block_getters/block_getter.ts +++ b/internal/block_getters/block_getter.ts @@ -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}.`, @@ -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), @@ -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}.`, @@ -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({ diff --git a/internal/block_producers/block_producer.ts b/internal/block_producers/block_producer.ts index 42b71c1..d8548e6 100644 --- a/internal/block_producers/block_producer.ts +++ b/internal/block_producers/block_producer.ts @@ -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;