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

fix(dashmate): imported node is not starting #2009

Merged
merged 9 commits into from
Jul 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default function reindexNodeTaskFactory(
await waitForCoreSync(ctx.coreService, (verificationProgress) => {
const { percent, blocks, headers } = verificationProgress;

observer.next(`${(percent * 100).toFixed(4)}%, ${blocks} / ${headers}`);
observer.next(`${(percent * 100).toFixed(1)}%, ${blocks} / ${headers}`);
});

await new Promise((res) => { setTimeout(res, 2000); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,19 @@ function validateCoreDataDirectoryPathFactory(config) {
* @param {Docker} docker
* @param {dockerPull} dockerPull
* @param {generateEnvs} generateEnvs
* @param {reindexNodeTask} reindexNodeTask
* @param {stopNodeTask} stopNodeTask
* @param {writeConfigTemplates} writeConfigTemplates
* @return {importCoreDataTask}
*/
export default function importCoreDataTaskFactory(docker, dockerPull, generateEnvs) {
export default function importCoreDataTaskFactory(
docker,
dockerPull,
generateEnvs,
reindexNodeTask,
stopNodeTask,
writeConfigTemplates,
) {
/**
* @typedef {function} importCoreDataTask
* @returns {Listr}
Expand Down Expand Up @@ -135,6 +145,12 @@ export default function importCoreDataTaskFactory(docker, dockerPull, generateEn
// eslint-disable-next-line prefer-destructuring
ctx.importedExternalIp = configFileContent.match(/^externalip=([^ \n]+)/m)?.[1];

// We need to reindex Core if there weren't all required indexed enabled before
ctx.isIndexed = configFileContent.match(/^txindex=1/)
&& configFileContent.match(/^addressindex=1/)
&& configFileContent.match(/^timestampindex=1/)
&& configFileContent.match(/^spentindex=1/);

// Copy data directory to docker a volume

// Create a volume
Expand Down Expand Up @@ -193,11 +209,20 @@ export default function importCoreDataTaskFactory(docker, dockerPull, generateEn
throw new Error('Cannot copy data dir to volume');
}

// TODO: Wording needs to be updated
let header;
if (ctx.isIndexed) {
header = ` Please stop your existing Dash Core node before starting the new dashmate-based
node ("dashmate start"). Also, disable any automatic startup services (e.g., cron, systemd) for the existing Dash Core installation.\n`;
} else {
header = ` You existing Core node doesn't have indexes required to run ${ctx.nodeTypeName}.

Please stop your existing Dash Core node and I will reindex your Core data.
Also, disable any automatic startup services (e.g., cron, systemd) for the existing Dash Core installation.\n`;
}

await task.prompt({
type: 'confirm',
header: ` Please stop your existing Dash Core node before starting the new dashmate-based
node ("dashmate start"). Also, disable any automatic startup services (e.g., cron, systemd) for the existing Dash Core installation.\n`,
header,
message: 'Press any key to continue...',
default: ' ',
separator: () => '',
Expand All @@ -213,6 +238,33 @@ export default function importCoreDataTaskFactory(docker, dockerPull, generateEn
persistentOutput: true,
},
},
{
enabled: (ctx) => !ctx.isIndexed,
task: async (ctx) => {
// Skip checking if node is already running for reindex task
ctx.isForce = true;
// Disable platform while we reindexing
ctx.config.set('platform.enable', false);

// TODO: We don't need to run dashmate helper with reindexing node

writeConfigTemplates(ctx.config);
},
},
{
enabled: (ctx) => !ctx.isIndexed,
task: (ctx) => reindexNodeTask(ctx.config),
},
{
enabled: (ctx) => !ctx.isIndexed,
task: (ctx) => stopNodeTask(ctx.config),
},
{
enabled: (ctx) => !ctx.isIndexed,
task: async (ctx) => {
ctx.config.set('platform.enable', ctx.isHP);
},
},
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export default function verifySystemRequirementsTaskFactory(docker, dockerCompos

if (!proceed) {
throw new Error('System requirements have not been met');
} else {
// eslint-disable-next-line no-param-reassign
task.output = chalk`{yellow System requirements have not been met.}`;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import chalk from 'chalk';
import {
NODE_TYPE_MASTERNODE,
NODE_TYPE_FULLNODE,
PRESET_MAINNET,
} from '../../../constants.js';

import {
Expand Down Expand Up @@ -52,7 +51,7 @@ export default function setupRegularPresetTaskFactory(
let nodeTypeName;

if (!ctx.nodeType) {
nodeTypeName = await task.prompt([
ctx.nodeTypeName = await task.prompt([
{
type: 'select',
// Keep this order, because each item references the text in the previous item
Expand All @@ -75,16 +74,15 @@ export default function setupRegularPresetTaskFactory(
},
]);

ctx.nodeType = getNodeTypeByName(nodeTypeName);
ctx.nodeType = getNodeTypeByName(ctx.nodeTypeName);
ctx.isHP = isNodeTypeNameHighPerformance(nodeTypeName);
} else {
nodeTypeName = getNodeTypeNameByType(ctx.nodeType);
ctx.nodeTypeName = getNodeTypeNameByType(ctx.nodeType);
}

ctx.config = defaultConfigs.get(ctx.preset);

// TODO: We need to change this and enable platform on mainnet
ctx.config.set('platform.enable', ctx.isHP && ctx.config.get('network') !== PRESET_MAINNET);
ctx.config.set('platform.enable', ctx.isHP);
ctx.config.set('core.masternode.enable', ctx.nodeType === NODE_TYPE_MASTERNODE);

if (ctx.config.get('core.masternode.enable')) {
Expand All @@ -99,7 +97,7 @@ export default function setupRegularPresetTaskFactory(
});

// eslint-disable-next-line no-param-reassign
task.output = ctx.nodeType ? ctx.nodeType : nodeTypeName;
task.output = ctx.nodeTypeName;
},
options: {
persistentOutput: true,
Expand Down
5 changes: 0 additions & 5 deletions packages/dashmate/src/listr/tasks/startNodeTaskFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ export default function startNodeTaskFactory(
* @return {Object}
*/
function startNodeTask(config) {
// Check external IP is set
if (config.get('core.masternode.enable')) {
config.get('externalIp', true);
}

const isMinerEnabled = config.get('core.miner.enable');

if (isMinerEnabled === true && config.get('network') !== NETWORK_LOCAL) {
Expand Down
Loading