From 124766ed16a980e7024f739d5b9d5e3ecb004a2d Mon Sep 17 00:00:00 2001 From: Lyudmil Danailov Date: Sat, 16 Mar 2024 15:46:56 +0200 Subject: [PATCH] Changing NIC functionality --- blockchains/erc20/erc20_worker.js | 5 ++++- .../eth/lib/next_interval_calculator.js | 21 ++++--------------- blockchains/matic/matic_worker.js | 5 ++++- blockchains/receipts/receipts_worker.js | 5 ++++- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/blockchains/erc20/erc20_worker.js b/blockchains/erc20/erc20_worker.js index 2d778608..b62ad75a 100644 --- a/blockchains/erc20/erc20_worker.js +++ b/blockchains/erc20/erc20_worker.js @@ -104,7 +104,10 @@ class ERC20Worker extends BaseWorker { const interval = this.settings.EXPORT_BLOCKS_LIST ? this.getBlocksListInterval() : - nextIntervalCalculator(this); + nextIntervalCalculator( + this.lastExportedBlock, + this.lastConfirmedBlock, + this.settings.BLOCK_INTERVAL); logger.info(`Fetching transfer events for interval ${interval.fromBlock}:${interval.toBlock}`); diff --git a/blockchains/eth/lib/next_interval_calculator.js b/blockchains/eth/lib/next_interval_calculator.js index 5a2d355e..590c5807 100644 --- a/blockchains/eth/lib/next_interval_calculator.js +++ b/blockchains/eth/lib/next_interval_calculator.js @@ -42,22 +42,10 @@ function setWorkerSleepTime(worker, context) { * @param {BaseWorker} worker A worker instance, inherriting the BaseWorker class. * @returns {object} The interval, derived from the progress of the worker */ -function nextIntervalCalculator(worker) { +function nextIntervalCalculator(lastExportedBlock, lastConfirmedBlock, blockInterval) { return { - fromBlock: worker.lastExportedBlock + 1, - toBlock: Math.min(worker.lastExportedBlock + worker.settings.BLOCK_INTERVAL, worker.lastConfirmedBlock) - }; -} - -/** - * Function for calculating the next interval to be used in the worker's methods for querying the node. - * @param {BaseWorker} worker A worker instance, inherriting the BaseWorker class. - * @returns {object} The interval, derived from the progress of the worker - */ -function nextIntervalCalculatorV2(worker) { - return { - fromBlock: worker.lastQueuedBlock + 1, - toBlock: Math.min(worker.lastQueuedBlock + worker.settings.BLOCK_INTERVAL, worker.lastConfirmedBlock) + fromBlock: lastExportedBlock + 1, + toBlock: Math.min(lastExportedBlock + blockInterval, lastConfirmedBlock) }; } @@ -67,6 +55,5 @@ module.exports = { WORK_NO_SLEEP, setWorkerSleepTime, analyzeWorkerContext, - nextIntervalCalculator, - nextIntervalCalculatorV2 + nextIntervalCalculator }; diff --git a/blockchains/matic/matic_worker.js b/blockchains/matic/matic_worker.js index c368eea9..1e8acbee 100644 --- a/blockchains/matic/matic_worker.js +++ b/blockchains/matic/matic_worker.js @@ -26,7 +26,10 @@ class MaticWorker extends BaseWorker { setWorkerSleepTime(this, workerContext); if (workerContext === NO_WORK_SLEEP) return []; - const result = nextIntervalCalculator(this); + const result = nextIntervalCalculator( + this.lastExportedBlock, + this.lastConfirmedBlock, + this.settings.BLOCK_INTERVAL); logger.info(`Fetching transfer events for interval ${result.fromBlock}:${result.toBlock}`); diff --git a/blockchains/receipts/receipts_worker.js b/blockchains/receipts/receipts_worker.js index 61371871..2119ee25 100644 --- a/blockchains/receipts/receipts_worker.js +++ b/blockchains/receipts/receipts_worker.js @@ -100,7 +100,10 @@ class ReceiptsWorker extends BaseWorker { setWorkerSleepTime(this, workerContext); if (workerContext === NO_WORK_SLEEP) return []; - const { fromBlock, toBlock } = nextIntervalCalculator(this); + const { fromBlock, toBlock } = nextIntervalCalculator( + this.lastExportedBlock, + this.lastConfirmedBlock, + this.settings.BLOCK_INTERVAL); logger.info(`Fetching receipts for interval ${fromBlock}:${toBlock}`); const receipts = await this.getReceiptsForBlocks(fromBlock, toBlock);