-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lyudmil Danailov
authored and
Lyudmil Danailov
committed
Jan 28, 2024
1 parent
fbdbaf3
commit 1980390
Showing
22 changed files
with
106 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,40 @@ | ||
/** | ||
* A function that returns the appropriate interval, | ||
* depending on the progress that the worker's made. | ||
* If the exporter's caught up, we check for a new block. We then check whether the Node | ||
* returns a valid block (sometimes the Node returns an early block, like 3 for example). | ||
* We don't want to get the new blocks right away, so we set a sleep variable. On the next iteration | ||
* the function will return the appropriate array of intervals. | ||
* @param {BaseWorker} worker A worker instance, inherriting the BaseWorker class. | ||
* @returns {Array} The corresponding interval | ||
* @param {BaseWorker} worker A worker instance, inherriting the BaseWorker class. | ||
* @returns {boolean} Boolean variable set to true or false, depending on whether there's a new block or not | ||
*/ | ||
async function nextIntervalCalculator(worker) { | ||
if (worker.lastBufferedBlock >= worker.lastConfirmedBlock) { | ||
async function isNewBlockAvailable(worker) { | ||
if (worker.lastExportedBlock >= worker.lastConfirmedBlock) { | ||
const newConfirmedBlock = await worker.web3Wrapper.getBlockNumber() - worker.settings.CONFIRMATIONS; | ||
if (worker.lastConfirmedBlock < newConfirmedBlock) { | ||
worker.lastConfirmedBlock = newConfirmedBlock; | ||
} | ||
worker.sleepTimeMsec = worker.settings.LOOP_INTERVAL_CURRENT_MODE_SEC * 1000; | ||
return { success: false }; | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* A function that returns the appropriate interval, | ||
* depending on the progress that the worker's made. | ||
* @param {BaseWorker} worker A worker instance, inherriting the BaseWorker class. | ||
* @returns {object} The corresponding interval | ||
*/ | ||
function nextIntervalCalculator(worker) { | ||
worker.sleepTimeMsec = 0; | ||
return { | ||
success: true, | ||
fromBlock: worker.lastBufferedBlock + 1, | ||
toBlock: Math.min(worker.lastBufferedBlock + worker.settings.BLOCK_INTERVAL, worker.lastConfirmedBlock) | ||
fromBlock: worker.lastExportedBlock + 1, | ||
toBlock: Math.min(worker.lastExportedBlock + worker.settings.BLOCK_INTERVAL, worker.lastConfirmedBlock) | ||
}; | ||
} | ||
|
||
module.exports = { | ||
isNewBlockAvailable, | ||
nextIntervalCalculator | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.