@kyve/core-beta
Version:
🚀 The base KYVE node implementation.
56 lines (55 loc) • 2.66 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.setupValidator = void 0;
const prando_1 = __importDefault(require("prando"));
const unique_names_generator_1 = require("unique-names-generator");
const __1 = require("../..");
/**
* setupValidator ensures the node starts as a valid validator
* and logs some basic validator starting information
*
* @method setupValidator
* @param {Node} this
* @return {Promise<void>}
*/
async function setupValidator() {
try {
// generate deterministic valname based on network, pool id,
// runtime, runtime version and valaddress
const valnameSeed = `${this.network}-${this.poolId}-${this.runtime.name}-${this.runtime.version}-${this.client.account.address}`;
this.logger.debug(`Creating seed for valname generation`);
this.logger.debug(valnameSeed);
const r = new prando_1.default(valnameSeed);
this.logger.debug(`Generate valname with seed`);
this.name = (0, unique_names_generator_1.uniqueNamesGenerator)({
dictionaries: [unique_names_generator_1.adjectives, unique_names_generator_1.colors, unique_names_generator_1.animals],
separator: "-",
length: 3,
style: "lowerCase",
seed: r.nextInt(0, unique_names_generator_1.adjectives.length * unique_names_generator_1.colors.length * unique_names_generator_1.animals.length),
}).replace(" ", "-");
this.logger.debug(`Valname "${this.name}" got created`);
// check if valaccount was already authorized by a validator
await this.waitForAuthorization();
// log basic node info on startup
this.logger.info("Starting node ...\n");
this.logger.info(`Valaddress \t = ${this.client.account.address}`);
this.logger.info(`Staker \t\t = ${this.staker}`);
this.logger.info(`Valname \t\t = ${this.name}\n`);
this.logger.info(`Pool ID \t\t = ${this.poolId}`);
this.logger.info(`Runtime \t\t = ${this.runtime.name}`);
this.logger.info(`Network \t\t = ${this.network}\n`);
this.logger.info(`/core \t = v${this.coreVersion}`);
this.logger.info(`${this.runtime.name} \t = v${this.runtime.version}\n`);
this.m.cache_current_items.set(0);
}
catch (err) {
this.logger.fatal(`Failed to setup validator. Exiting ...`);
this.logger.fatal((0, __1.standardizeJSON)(err));
process.exit(1);
}
}
exports.setupValidator = setupValidator;