Skip to content

Commit

Permalink
Changing NIC functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyudmil Danailov authored and Lyudmil Danailov committed Mar 16, 2024
1 parent 13e3d3b commit 124766e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
5 changes: 4 additions & 1 deletion blockchains/erc20/erc20_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand Down
21 changes: 4 additions & 17 deletions blockchains/eth/lib/next_interval_calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
}

Expand All @@ -67,6 +55,5 @@ module.exports = {
WORK_NO_SLEEP,
setWorkerSleepTime,
analyzeWorkerContext,
nextIntervalCalculator,
nextIntervalCalculatorV2
nextIntervalCalculator
};
5 changes: 4 additions & 1 deletion blockchains/matic/matic_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Expand Down
5 changes: 4 additions & 1 deletion blockchains/receipts/receipts_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 124766e

Please sign in to comment.