From a8a094f3d9bc9535d4651d87cccbf3bb1e01b157 Mon Sep 17 00:00:00 2001 From: Will Meister Date: Tue, 1 Sep 2020 15:04:04 -0500 Subject: [PATCH] Making block processing exit if it fails within a promise and throwing an exception would not be caught --- .../app/ethereum/ethereum-block-processor.ts | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/core-db/src/app/ethereum/ethereum-block-processor.ts b/packages/core-db/src/app/ethereum/ethereum-block-processor.ts index 77ba3b0b74fb..8d64fda36390 100644 --- a/packages/core-db/src/app/ethereum/ethereum-block-processor.ts +++ b/packages/core-db/src/app/ethereum/ethereum-block-processor.ts @@ -50,20 +50,29 @@ export class EthereumBlockProcessor { this.subscriptions.add(handler) provider.on('block', async (blockNumber) => { - if (blockNumber < this.earliestBlock) { - log.debug( - `Received block [${blockNumber}] which is before earliest block [${this.earliestBlock}]. Ignoring...` - ) - return - } + try { + if (blockNumber < this.earliestBlock) { + log.debug( + `Received block [${blockNumber}] which is before earliest block [${this.earliestBlock}]. Ignoring...` + ) + return + } - log.debug(`Block [${blockNumber}] was mined!`) + log.debug(`Block [${blockNumber}] was mined!`) - await this.fetchAndDisseminateBlock(provider, blockNumber) - this.currentBlockNumber = blockNumber + await this.fetchAndDisseminateBlock(provider, blockNumber) + this.currentBlockNumber = blockNumber - if (!syncPastBlocks || this.syncCompleted) { - await this.storeLastProcessedBlockNumber(this.currentBlockNumber) + if (!syncPastBlocks || this.syncCompleted) { + await this.storeLastProcessedBlockNumber(this.currentBlockNumber) + } + } catch (e) { + logError( + log, + `Error thrown processing block ${blockNumber}. Exiting since throwing will not be caught.`, + e + ) + process.exit(1) } })