@kyve/core-beta
Version:
🚀 The base KYVE node implementation.
47 lines (46 loc) • 2.04 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitForUploadInterval = void 0;
const bignumber_js_1 = __importDefault(require("bignumber.js"));
const utils_1 = require("../../utils");
/**
* waitForUploadInterval waits until the upload interval of the current
* round has passed. The node waits, because during this time no new round
* will start. Only after the upload interval the next uploader can start
* the next round.
*
* @method waitForUploadInterval
* @param {Node} this
* @return {Promise<void>}
*/
async function waitForUploadInterval() {
try {
// determine how long the upload interval is still taking
let timeRemaining = new bignumber_js_1.default(0);
const unixNow = new bignumber_js_1.default(Date.now());
const unixIntervalEnd = new bignumber_js_1.default(this.pool.bundle_proposal.updated_at)
.plus(this.pool.data.upload_interval)
.multipliedBy(1000);
// if upload interval has already passed just wait zero seconds
if (unixNow.lt(unixIntervalEnd)) {
timeRemaining = unixIntervalEnd.minus(unixNow);
}
this.logger.info(`Waiting for remaining upload interval = ${timeRemaining
.dividedBy(1000)
.toFixed(2)}s ...`);
// further track remaining upload interval time for metrics
const endTimeRemaining = this.m.bundles_remaining_upload_interval_time.startTimer();
// wait for the remaining time
await (0, utils_1.sleep)(timeRemaining.toNumber());
endTimeRemaining();
this.logger.info(`Reached upload interval of current bundle proposal`);
}
catch (err) {
this.logger.error(`Failed to wait for upload interval. Continuing ...`);
this.logger.error((0, utils_1.standardizeJSON)(err));
}
}
exports.waitForUploadInterval = waitForUploadInterval;