Skip to content

Commit

Permalink
Merge pull request #61 from 0xPolygon/fix-start-block-fetch-issue
Browse files Browse the repository at this point in the history
Fix start block fetch issue
  • Loading branch information
nitinmittal23 authored Nov 8, 2024
2 parents 2893fb1 + 1a8bbcc commit 36165e8
Show file tree
Hide file tree
Showing 4 changed files with 931 additions and 629 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
Loading

0 comments on commit 36165e8

Please sign in to comment.