UNPKG

@kyve/core-beta

Version:

🚀 The base KYVE node implementation.

37 lines (36 loc) • 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.syncPoolState = void 0; const utils_1 = require("../../utils"); /** * syncPoolState fetches the state of the pool the node is running on. * The query gets called with a backoff strategy which increases by * 10 seconds with every failed call. * This method will run indefinitely if the query fails all the time * because without the newest state the node can't continue. * * @method syncPoolState * @param {Node} this * @return {Promise<void>} */ async function syncPoolState() { await (0, utils_1.callWithBackoffStrategy)(async () => { var _a, _b, _c; this.logger.debug(`this.lcd.kyve.query.v1beta1.pool({id: ${this.poolId.toString()}})`); const prevPoolConfig = (_c = (_b = (_a = this.pool) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.config) !== null && _c !== void 0 ? _c : ""; const { pool } = await this.lcd.kyve.query.v1beta1.pool({ id: this.poolId.toString(), }); this.pool = pool; this.m.query_pool_successful.inc(); // if config link has changed sync the config if (prevPoolConfig !== this.pool.data.config) { await this.syncPoolConfig(); } }, { limitTimeoutMs: 5 * 60 * 1000, increaseByMs: 10 * 1000 }, (err, ctx) => { this.logger.info(`Requesting query pool was unsuccessful. Retrying in ${(ctx.nextTimeoutInMs / 1000).toFixed(2)}s ...`); this.logger.debug((0, utils_1.standardizeJSON)(err)); this.m.query_pool_failed.inc(); }); } exports.syncPoolState = syncPoolState;