Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(dashmate)!: disable config auto render #1499

Merged
merged 20 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function getTestnetConfigFactory(homeDir, getBaseConfig) {
},
core: {
docker: {
image: 'dashpay/dashd:20.0.0-beta.2',
image: 'dashpay/dashd:20.0.0-beta.4',
shumkov marked this conversation as resolved.
Show resolved Hide resolved
},
p2p: {
port: 19999,
Expand Down
11 changes: 11 additions & 0 deletions packages/dashmate/src/commands/config/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class ConfigCreateCommand extends BaseCommand {
/**
* @param {Object} args
* @param {Object} flags
* @param {renderServiceTemplates} renderServiceTemplates
* @param {writeServiceConfigs} writeServiceConfigs
* @param {ConfigFileJsonRepository} configFileRepository
* @param {ConfigFile} configFile
* @return {Promise<void>}
*/
Expand All @@ -13,10 +16,18 @@ class ConfigCreateCommand extends BaseCommand {
from: fromConfigName,
},
flags,
renderServiceTemplates,
writeServiceConfigs,
configFileRepository,
configFile,
) {
configFile.createConfig(configName, fromConfigName);

configFileRepository.write(configFile);

const serviceConfigs = renderServiceTemplates(configFile.getConfig(configName));
writeServiceConfigs(configName, serviceConfigs);

// eslint-disable-next-line no-console
console.log(`${configName} created`);
}
Expand Down
7 changes: 7 additions & 0 deletions packages/dashmate/src/commands/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ class ConfigCommand extends ConfigBaseCommand {
* @param {Object} args
* @param {Object} flags
* @param {Config} config
* @param {renderServiceTemplates} renderServiceTemplates
* @param {writeServiceConfigs} writeServiceConfigs
* @return {Promise<void>}
*/
async runWithDependencies(
args,
flags,
config,
renderServiceTemplates,
writeServiceConfigs,
) {
const output = `${config.getName()} config:\n\n${inspect(
config.getOptions(),
{ colors: true, depth: null, maxArrayLength: 2 },
)}`;

const serviceConfigs = renderServiceTemplates(config);
writeServiceConfigs(config.getName(), serviceConfigs);

// eslint-disable-next-line no-console
console.log(output);
}
Expand Down
11 changes: 11 additions & 0 deletions packages/dashmate/src/commands/config/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class ConfigRemoveCommand extends BaseCommand {
* @param {Object} flags
* @param {ConfigFile} configFile
* @param {DefaultConfigs} defaultConfigs
* @param {renderServiceTemplates} renderServiceTemplates
* @param {writeServiceConfigs} writeServiceConfigs
* @param {ConfigFileJsonRepository} configFileRepository
* @return {Promise<void>}
*/
async runWithDependencies(
Expand All @@ -15,13 +18,21 @@ class ConfigRemoveCommand extends BaseCommand {
flags,
configFile,
defaultConfigs,
renderServiceTemplates,
writeServiceConfigs,
configFileRepository,
) {
if (defaultConfigs.has(configName)) {
throw new Error(`system config ${configName} can't be removed.\nPlease use 'dashmate reset --hard --config=${configName}' command to reset the configuration`);
}

configFile.removeConfig(configName);

configFileRepository.write(configFile);

const serviceConfigs = renderServiceTemplates(configFile.getConfig(configName));
writeServiceConfigs(configName, serviceConfigs);

// eslint-disable-next-line no-console
console.log(`${configName} removed`);
}
Expand Down
13 changes: 13 additions & 0 deletions packages/dashmate/src/commands/config/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class ConfigSetCommand extends ConfigBaseCommand {
* @param args
* @param flags
* @param {Config} config
* @param {renderServiceTemplates} renderServiceTemplates
* @param {writeServiceConfigs} writeServiceConfigs
* @param {ConfigFileJsonRepository} configFileRepository
* @param {ConfigFile} configFile
* @return {Promise<void>}
*/
async runWithDependencies(
Expand All @@ -14,6 +18,10 @@ class ConfigSetCommand extends ConfigBaseCommand {
},
flags,
config,
renderServiceTemplates,
writeServiceConfigs,
configFileRepository,
configFile,
) {
// check for existence
config.get(optionPath);
Expand All @@ -28,6 +36,11 @@ class ConfigSetCommand extends ConfigBaseCommand {

config.set(optionPath, value);

configFileRepository.write(configFile);

const serviceConfigs = renderServiceTemplates(config);
writeServiceConfigs(config.getName(), serviceConfigs);

// eslint-disable-next-line no-console
console.log(`${optionPath} set to ${optionValue}`);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/dashmate/src/commands/status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,17 @@ class StatusCommand extends ConfigBaseCommand {

if (masternode.state === MasternodeStateEnum.READY) {
const {
enabledCount,
poSePenalty,
lastPaidHeight,
lastPaidTime,
paymentQueuePosition,
nextPaymentTime,
} = masternode.nodeState;
const { evonodeEnabled, masternodeEnabled } = masternode;

plain['Masternode ProTX'] = masternode.proTxHash || 'n/a';
plain['PoSe Penalty'] = colors.poSePenalty(poSePenalty, enabledCount)(`${poSePenalty}`) || 'n/a';
plain['PoSe Penalty'] = colors.poSePenalty(poSePenalty,
masternodeEnabled, evonodeEnabled)(`${poSePenalty}`) || 'n/a';
plain['Last paid block'] = lastPaidHeight || 'n/a';
plain['Last paid time'] = lastPaidHeight === 0 ? 'Never' : (lastPaidTime || 'n/a');
plain['Payment queue position'] = paymentQueuePosition || 'n/a';
Expand Down
15 changes: 10 additions & 5 deletions packages/dashmate/src/commands/status/masternode.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,25 @@ class MasternodeStatusCommand extends ConfigBaseCommand {
plain['Masternode Sync Status'] = scope.syncAsset ? chalk.yellow(scope.syncAsset) : 'n/a';
}

plain['Total Masternodes'] = scope.masternodeTotal ?? 'n/a';
plain['Enabled Masternodes'] = scope.masternodeEnabled ?? 'n/a';
plain['Total Evonodes'] = scope.evonodeTotal ?? 'n/a';
plain['Enabled Evonodes'] = scope.evonodeEnabled ?? 'n/a';

if (scope.state === MasternodeStateEnum.READY) {
const {
lastPaidHeight, lastPaidTime,
paymentQueuePosition, nextPaymentTime,
poSePenalty, enabledCount,
poSePenalty,
} = scope.nodeState;

plain['ProTx Hash'] = scope.proTxHash || 'n/a';
plain['PoSe Penalty'] = colors.poSePenalty(poSePenalty, enabledCount)(`${poSePenalty}`) || 'n/a';
plain['Last paid block'] = lastPaidHeight || 'n/a';
plain['PoSe Penalty'] = colors.poSePenalty(poSePenalty,
scope.masternodeEnabled, scope.evonodeEnabled)(`${poSePenalty}`) || 'n/a';
plain['Last paid block'] = lastPaidHeight ?? 'n/a';
plain['Last paid time'] = lastPaidHeight === 0 ? 'Never' : (lastPaidTime || 'n/a');
plain['Payment queue position'] = paymentQueuePosition || 'n/a';
plain['Payment queue position'] = paymentQueuePosition ?? 'n/a';
plain['Next payment time'] = `in ${nextPaymentTime}` || 'n/a';
plain['Enabled count'] = enabledCount || 'n/a';
}

return printObject(plain, flags.format);
Expand Down
18 changes: 14 additions & 4 deletions packages/dashmate/src/core/calculatePaymentQueuePosition.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
function calculatePaymentQueuePosition(dmnState, masternodeEnabledCount, coreBlocks) {
/**
*
* @param dmnState {dmnState}
* @param enabledMasternodes {number}
* @param enabledEvonodes {number}
* @param coreBlocks {number} current block height
* @return {number}
*/
function calculatePaymentQueuePosition(dmnState, enabledMasternodes, enabledEvonodes, coreBlocks) {
const enabledCount = enabledMasternodes + enabledEvonodes * 4;

let paymentQueuePosition;
// Masternode has been unbanned recently
if (dmnState.PoSeRevivedHeight > dmnState.lastPaidHeight) {
paymentQueuePosition = dmnState.PoSeRevivedHeight
+ masternodeEnabledCount
+ enabledCount
- coreBlocks;
// Masternode has never been paid
} else if (dmnState.lastPaidHeight === 0) {
paymentQueuePosition = dmnState.registeredHeight
+ masternodeEnabledCount
+ enabledCount
- coreBlocks;
// Masternode was previously paid and is in normal queue
} else {
paymentQueuePosition = dmnState.lastPaidHeight
+ masternodeEnabledCount
+ enabledCount
- coreBlocks;
}
return paymentQueuePosition;
Expand Down
4 changes: 4 additions & 0 deletions packages/dashmate/src/listr/tasks/resetNodeTaskFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const wait = require('../../util/wait');
* @param {ConfigFile} configFile
* @param {HomeDir} homeDir
* @param {generateEnvs} generateEnvs
* @param {ConfigFileJsonRepository} configFileRepository
* @return {resetNodeTask}
*/
function resetNodeTaskFactory(
Expand All @@ -23,6 +24,7 @@ function resetNodeTaskFactory(
configFile,
homeDir,
generateEnvs,
configFileRepository,
) {
/**
* @typedef {resetNodeTask}
Expand Down Expand Up @@ -131,6 +133,8 @@ function resetNodeTaskFactory(
configFile.removeConfig(config.getName());
}

configFileRepository.write(configFile);

// Remove service configs
let serviceConfigsPath = homeDir.joinPath(baseConfigName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const generateRandomString = require('../../../util/generateRandomString');
* @param {configFileRepository} configFileRepository
* @param {generateHDPrivateKeys} generateHDPrivateKeys
* @param {HomeDir} homeDir
* @param {writeServiceConfigs} writeServiceConfigs
* @param {renderServiceTemplates} renderServiceTemplates
*/
function setupLocalPresetTaskFactory(
configFile,
Expand All @@ -28,6 +30,8 @@ function setupLocalPresetTaskFactory(
configFileRepository,
generateHDPrivateKeys,
homeDir,
writeServiceConfigs,
renderServiceTemplates,
) {
/**
* @typedef {setupLocalPresetTask}
Expand Down Expand Up @@ -273,7 +277,11 @@ function setupLocalPresetTaskFactory(
task: async () => {
configFile.setDefaultGroupName(PRESET_LOCAL);

// Persist configs
for (const config of ctx.configGroup) {
const serviceConfigFiles = renderServiceTemplates(config);
writeServiceConfigs(config.getName(), serviceConfigFiles);
}

configFileRepository.write(configFile);
},
});
Expand All @@ -300,6 +308,8 @@ function setupLocalPresetTaskFactory(
const subTasks = platformConfigs.map((config) => {
config.set('platform.dapi.envoy.ssl.provider', SSL_PROVIDERS.SELF_SIGNED);
shumkov marked this conversation as resolved.
Show resolved Hide resolved

configFileRepository.write(configFile);

return {
title: `Generate certificate for ${config.getName()}`,
task: async () => obtainSelfSignedCertificateTask(config),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const generateRandomString = require('../../../util/generateRandomString');
* @param {ConfigFile} configFile
* @param {generateBlsKeys} generateBlsKeys
* @param {registerMasternodeTask} registerMasternodeTask
* @param {ConfigFileJsonRepository} configFileRepository
* @param {renderServiceTemplates} renderServiceTemplates
* @param {writeServiceConfigs} writeServiceConfigs
* @param {obtainZeroSSLCertificateTask} obtainZeroSSLCertificateTask
Expand All @@ -34,6 +35,7 @@ function setupRegularPresetTaskFactory(
configFile,
generateBlsKeys,
registerMasternodeTask,
configFileRepository,
renderServiceTemplates,
writeServiceConfigs,
obtainZeroSSLCertificateTask,
Expand Down Expand Up @@ -150,6 +152,11 @@ function setupRegularPresetTaskFactory(
configFile.setConfig(ctx.config);
configFile.setDefaultConfigName(ctx.preset);

configFileRepository.write(configFile);

const serviceConfigFiles = renderServiceTemplates(ctx.config);
writeServiceConfigs(ctx.config.getName(), serviceConfigFiles);

// eslint-disable-next-line no-param-reassign
task.output = chalk`Node configuration completed successfully!

Expand Down
8 changes: 0 additions & 8 deletions packages/dashmate/src/oclif/command/BaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ class BaseCommand extends Command {
async finally(err) {
// Save configs collection
if (this.container) {
const configFileRepository = this.container.resolve('configFileRepository');

if (this.container.has('configFile')) {
const configFile = this.container.resolve('configFile');

configFileRepository.write(configFile);
}

// Stop all running containers
const stopAllContainers = this.container.resolve('stopAllContainers');
const startedContainers = this.container.resolve('startedContainers');
Expand Down
8 changes: 1 addition & 7 deletions packages/dashmate/src/oclif/command/ConfigBaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ConfigBaseCommand extends BaseCommand {

if (defaultConfigName === null) {
throw new Error(`Default config is not set.

You probably need to set up a node with the 'dashmate setup' command first.

You can also use the '--config' option, or set the default config with 'dashmate config default'`);
Expand All @@ -43,12 +43,6 @@ You can also use the '--config' option, or set the default config with 'dashmate
config: asValue(config),
});

const renderServiceTemplates = this.container.resolve('renderServiceTemplates');
const writeServiceConfigs = this.container.resolve('writeServiceConfigs');

const serviceConfigFiles = renderServiceTemplates(config);
writeServiceConfigs(config.getName(), serviceConfigFiles);

return super.run();
}
}
Expand Down
8 changes: 0 additions & 8 deletions packages/dashmate/src/oclif/command/GroupBaseCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ class GroupBaseCommand extends BaseCommand {
configGroup: asValue(group),
});

const renderServiceTemplates = this.container.resolve('renderServiceTemplates');
const writeServiceConfigs = this.container.resolve('writeServiceConfigs');

for (const config of group) {
const serviceConfigFiles = renderServiceTemplates(config);
writeServiceConfigs(config.getName(), serviceConfigFiles);
}

return super.run();
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dashmate/src/status/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ module.exports = {
}
return chalk.red;
},
poSePenalty: (poSePenalty, enabledCount) => {
poSePenalty: (poSePenalty, masternodeEnabled, evonodeEnabled) => {
if (poSePenalty === 0) {
return chalk.green;
}
if (poSePenalty < enabledCount) {
if (poSePenalty < masternodeEnabled + evonodeEnabled * 4) {
return chalk.yellow;
}
return chalk.red;
Expand Down
Loading
Loading