Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #172 from LiskHQ/166-specifying-config-when-runnin…
Browse files Browse the repository at this point in the history
…g-migrator-throws-error

Specifying config when running migrator throws error
  • Loading branch information
sameersubudhi authored Sep 25, 2023
2 parents bc8a45a + c892aa9 commit beffc7c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 92 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lisk-migrator",
"version": "2.0.0-rc.1",
"version": "2.0.0-rc.2",
"description": "A command-line tool for migrating the blockchain state to the latest protocol after a hard fork",
"author": "Lisk Foundation <[email protected]>, lightcurve GmbH <[email protected]>",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/pos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const createGenesisDataObj = async (
);

if (!voteWeightR2 || voteWeightR2.delegates.length === 0) {
throw new Error(`Top delegates for round ${r - 2}(r-2) unavailable, cannot proceed.`);
throw new Error(`Top delegates for round ${r - 2} (r-2) unavailable, cannot proceed.`);
}

const topValidators = voteWeightR2.delegates;
Expand Down
21 changes: 12 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LiskMigrator extends Command {
char: 'o',
required: false,
description:
'File path to write the genesis block. If not provided, it will default to cwd/output/{v3_networkIdentifier}/genesis_block.blob.',
"File path to write the genesis block. If not provided, it will default to cwd/output/{v3_networkIdentifier}/genesis_block.blob. Do not use any value starting with the default data path reserved for Lisk Core: '~/.lisk/lisk-core'.",
}),
'lisk-core-v3-data-path': flagsParser.string({
char: 'd',
Expand Down Expand Up @@ -141,7 +141,7 @@ class LiskMigrator extends Command {
const outputDir = flags.output ? outputPath : `${outputPath}/${networkIdentifier}`;

// Ensure the output directory is present
if (fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });

// Asynchronously capture the node's Forging Status information at the snapshot height
// This information is necessary for the node operators to enable generator post-migration without getting PoM'd
Expand All @@ -156,15 +156,18 @@ class LiskMigrator extends Command {
}

cli.action.start('Verifying Lisk Core version');
const liskCoreVersion = semver.coerce(appVersion);
if (!liskCoreVersion) {
const isLiskCoreVersionValid = semver.valid(appVersion);
if (isLiskCoreVersionValid === null) {
this.error(
`Unsupported lisk-core version detected. Supported version range ${MIN_SUPPORTED_LISK_CORE_VERSION}.`,
`Invalid Lisk Core version detected: ${appVersion}. Minimum supported version is ${MIN_SUPPORTED_LISK_CORE_VERSION}.`,
);
}
if (!semver.gte(MIN_SUPPORTED_LISK_CORE_VERSION, liskCoreVersion)) {

// Using 'gt' instead of 'gte' because the behavior is swapped
// i.e. 'gt' acts as 'gte' and vice-versa
if (semver.gt(`${MIN_SUPPORTED_LISK_CORE_VERSION}-rc.0`, appVersion)) {
this.error(
`Lisk Migrator utility is not compatible for lisk-core version ${liskCoreVersion.version}. The minimum compatible version is: ${MIN_SUPPORTED_LISK_CORE_VERSION}.`,
`Lisk Migrator is not compatible with Lisk Core version ${appVersion}. Minimum supported version is ${MIN_SUPPORTED_LISK_CORE_VERSION}.`,
);
}
cli.action.stop(`${appVersion} detected`);
Expand Down Expand Up @@ -233,7 +236,7 @@ class LiskMigrator extends Command {
configCoreV4 = migratedConfigV4 as PartialApplicationConfig;
}

cli.action.start('Installing lisk-core v4');
cli.action.start('Installing Lisk Core v4');
await installLiskCore();
cli.action.stop();

Expand Down Expand Up @@ -285,7 +288,7 @@ class LiskMigrator extends Command {
);

if (isUserConfirmed) {
cli.action.start('Starting lisk-core v4');
cli.action.start('Starting Lisk Core v4');
const network = networkConstant.name as string;
await startLiskCore(this, liskCoreV3DataPath, configCoreV4, network, outputDir);
this.log('Started Lisk Core v4 at default data directory.');
Expand Down
38 changes: 8 additions & 30 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
* Removal or modification of this copyright notice is prohibited.
*/
/* eslint-disable no-param-reassign */
import debugInit from 'debug';
import * as fs from 'fs-extra';
import cli from 'cli-ux';
import { existsSync, readdirSync, mkdirSync, writeFileSync } from 'fs';
import { execSync } from 'child_process';
import { join, resolve } from 'path';
import { validator } from '@liskhq/lisk-validator';

import { ApplicationConfig, applicationConfigSchema } from 'lisk-framework';
import { objects } from '@liskhq/lisk-utils';
import { ApplicationConfigV3, LoggerConfig } from '../types';
Expand All @@ -30,8 +28,7 @@ import {
NUMBER_STANDBY_VALIDATORS,
POS_INIT_ROUNDS,
} from '../constants';

const debug = debugInit('lisk:migrator');
import { resolveAbsolutePath } from './fs';

const LOG_LEVEL_PRIORITY = Object.freeze({
FATAL: 0,
Expand Down Expand Up @@ -61,36 +58,17 @@ export const getConfig = async (
corePath: string,
customConfigPath?: string,
): Promise<ApplicationConfigV3> => {
const command = [];

const [network] = readdirSync(`${corePath}/config`);

let compiledConfigPath = `${corePath}/config/${network}/config.json`;
const dataDirConfigPath = `${corePath}/config/${network}/config.json`;
const dataDirConfig = await fs.readJSON(dataDirConfigPath);

command.push(`cd ${corePath}`);

if (isBinaryBuild(corePath)) {
command.push('&& source env.sh');
}

if (customConfigPath) {
command.push(`--config ${customConfigPath}`);
compiledConfigPath = customConfigPath;
}

const fullCommand = command.join(' ');

debug(`Core path: ${corePath}`);
debug(`Cmd: ${fullCommand}`);
const customConfig = customConfigPath
? await fs.readJSON(resolveAbsolutePath(customConfigPath))
: {};

cli.action.start('Compiling Lisk Core configuration');
// Executing command to compile the configuration
// to use the "source" command on Linux we have to explicity set shell to bash
execSync(fullCommand, { shell: '/bin/bash' });
cli.action.stop();

cli.action.start('Loading Lisk Core configuration');
const config = await import(compiledConfigPath);
const config = objects.mergeDeep({}, dataDirConfig, customConfig) as ApplicationConfigV3;
cli.action.stop();

return config;
Expand Down
107 changes: 56 additions & 51 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,32 @@
integrity sha512-BQYjKbpXjoXwFW5jGqiizJQQT/aC7pFm9Ok1OWssonuguICi264lbgMzRp2ZMmRSlfkX6DsWDDcsrctK8Rwfiw==

"@babel/core@^7.1.0", "@babel/core@^7.12.3", "@babel/core@^7.7.2", "@babel/core@^7.8.0":
version "7.22.20"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.22.20.tgz#e3d0eed84c049e2a2ae0a64d27b6a37edec385b7"
integrity sha512-Y6jd1ahLubuYweD/zJH+vvOY141v4f9igNQAQ+MBgq9JlHS2iTsZKn1aMsb3vGccZsXI16VzTBw52Xx0DWmtnA==
version "7.23.0"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.23.0.tgz#f8259ae0e52a123eb40f552551e647b506a94d83"
integrity sha512-97z/ju/Jy1rZmDxybphrBuI+jtJjFVoz7Mr9yUQVVVi+DNZE333uFQeMOqcCIy1x3WYBIbWftUSLmbNXNT7qFQ==
dependencies:
"@ampproject/remapping" "^2.2.0"
"@babel/code-frame" "^7.22.13"
"@babel/generator" "^7.22.15"
"@babel/generator" "^7.23.0"
"@babel/helper-compilation-targets" "^7.22.15"
"@babel/helper-module-transforms" "^7.22.20"
"@babel/helpers" "^7.22.15"
"@babel/parser" "^7.22.16"
"@babel/helper-module-transforms" "^7.23.0"
"@babel/helpers" "^7.23.0"
"@babel/parser" "^7.23.0"
"@babel/template" "^7.22.15"
"@babel/traverse" "^7.22.20"
"@babel/types" "^7.22.19"
convert-source-map "^1.7.0"
"@babel/traverse" "^7.23.0"
"@babel/types" "^7.23.0"
convert-source-map "^2.0.0"
debug "^4.1.0"
gensync "^1.0.0-beta.2"
json5 "^2.2.3"
semver "^6.3.1"

"@babel/generator@^7.22.15", "@babel/generator@^7.7.2":
version "7.22.15"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.22.15.tgz#1564189c7ec94cb8f77b5e8a90c4d200d21b2339"
integrity sha512-Zu9oWARBqeVOW0dZOjXc3JObrzuqothQ3y/n1kUtrjCoCPLkXUwMvOo/F/TCfoHMbWIFlWwpZtkZVb9ga4U2pA==
"@babel/generator@^7.23.0", "@babel/generator@^7.7.2":
version "7.23.0"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.23.0.tgz#df5c386e2218be505b34837acbcb874d7a983420"
integrity sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==
dependencies:
"@babel/types" "^7.22.15"
"@babel/types" "^7.23.0"
"@jridgewell/gen-mapping" "^0.3.2"
"@jridgewell/trace-mapping" "^0.3.17"
jsesc "^2.5.1"
Expand All @@ -82,13 +82,13 @@
resolved "https://registry.yarnpkg.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz#96159db61d34a29dba454c959f5ae4a649ba9167"
integrity sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==

"@babel/helper-function-name@^7.22.5":
version "7.22.5"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.22.5.tgz#ede300828905bb15e582c037162f99d5183af1be"
integrity sha512-wtHSq6jMRE3uF2otvfuD3DIvVhOsSNshQl0Qrd7qC9oQJzHvOL4qQXlQn2916+CXGywIjpGuIkoyZRRxHPiNQQ==
"@babel/helper-function-name@^7.23.0":
version "7.23.0"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz#1f9a3cdbd5b2698a670c30d2735f9af95ed52759"
integrity sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==
dependencies:
"@babel/template" "^7.22.5"
"@babel/types" "^7.22.5"
"@babel/template" "^7.22.15"
"@babel/types" "^7.23.0"

"@babel/helper-hoist-variables@^7.22.5":
version "7.22.5"
Expand All @@ -104,10 +104,10 @@
dependencies:
"@babel/types" "^7.22.15"

"@babel/helper-module-transforms@^7.22.20":
version "7.22.20"
resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.22.20.tgz#da9edc14794babbe7386df438f3768067132f59e"
integrity sha512-dLT7JVWIUUxKOs1UnJUBR3S70YK+pKX6AbJgB2vMIvEkZkrfJDbYDJesnPshtKV4LhDOR3Oc5YULeDizRek+5A==
"@babel/helper-module-transforms@^7.23.0":
version "7.23.0"
resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.23.0.tgz#3ec246457f6c842c0aee62a01f60739906f7047e"
integrity sha512-WhDWw1tdrlT0gMgUJSlX0IQvoO1eN279zrAUbVB+KpV2c3Tylz8+GnKOLllCS6Z/iZQEyVYxhZVUdPTqs2YYPw==
dependencies:
"@babel/helper-environment-visitor" "^7.22.20"
"@babel/helper-module-imports" "^7.22.15"
Expand Down Expand Up @@ -139,7 +139,7 @@
resolved "https://registry.yarnpkg.com/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz#533f36457a25814cf1df6488523ad547d784a99f"
integrity sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==

"@babel/helper-validator-identifier@^7.22.19", "@babel/helper-validator-identifier@^7.22.20":
"@babel/helper-validator-identifier@^7.22.20":
version "7.22.20"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz#c4ae002c61d2879e724581d96665583dbc1dc0e0"
integrity sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==
Expand All @@ -149,14 +149,14 @@
resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.22.15.tgz#694c30dfa1d09a6534cdfcafbe56789d36aba040"
integrity sha512-bMn7RmyFjY/mdECUbgn9eoSY4vqvacUnS9i9vGAGttgFWesO6B4CYWA7XlpbWgBt71iv/hfbPlynohStqnu5hA==

"@babel/helpers@^7.22.15":
version "7.22.15"
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.22.15.tgz#f09c3df31e86e3ea0b7ff7556d85cdebd47ea6f1"
integrity sha512-7pAjK0aSdxOwR+CcYAqgWOGy5dcfvzsTIfFTb2odQqW47MDfv14UaJDY6eng8ylM2EaeKXdxaSWESbkmaQHTmw==
"@babel/helpers@^7.23.0":
version "7.23.1"
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.23.1.tgz#44e981e8ce2b9e99f8f0b703f3326a4636c16d15"
integrity sha512-chNpneuK18yW5Oxsr+t553UZzzAs3aZnFm4bxhebsNTeshrC95yA7l5yl7GBAG+JG1rF0F7zzD2EixK9mWSDoA==
dependencies:
"@babel/template" "^7.22.15"
"@babel/traverse" "^7.22.15"
"@babel/types" "^7.22.15"
"@babel/traverse" "^7.23.0"
"@babel/types" "^7.23.0"

"@babel/highlight@^7.10.4", "@babel/highlight@^7.22.13":
version "7.22.20"
Expand All @@ -167,10 +167,10 @@
chalk "^2.4.2"
js-tokens "^4.0.0"

"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.22.15", "@babel/parser@^7.22.16":
version "7.22.16"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.22.16.tgz#180aead7f247305cce6551bea2720934e2fa2c95"
integrity sha512-+gPfKv8UWeKKeJTUxe59+OobVcrYHETCsORl61EmSkmgymguYk/X5bp7GuUIXaFsc6y++v8ZxPsLSSuujqDphA==
"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.22.15", "@babel/parser@^7.23.0":
version "7.23.0"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.23.0.tgz#da950e622420bf96ca0d0f2909cdddac3acd8719"
integrity sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==

"@babel/plugin-syntax-async-generators@^7.8.4":
version "7.8.4"
Expand Down Expand Up @@ -263,7 +263,7 @@
dependencies:
"@babel/helper-plugin-utils" "^7.22.5"

"@babel/template@^7.22.15", "@babel/template@^7.22.5", "@babel/template@^7.3.3":
"@babel/template@^7.22.15", "@babel/template@^7.3.3":
version "7.22.15"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38"
integrity sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==
Expand All @@ -272,29 +272,29 @@
"@babel/parser" "^7.22.15"
"@babel/types" "^7.22.15"

"@babel/traverse@^7.22.15", "@babel/traverse@^7.22.20", "@babel/traverse@^7.7.2":
version "7.22.20"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.20.tgz#db572d9cb5c79e02d83e5618b82f6991c07584c9"
integrity sha512-eU260mPZbU7mZ0N+X10pxXhQFMGTeLb9eFS0mxehS8HZp9o1uSnFeWQuG1UPrlxgA7QoUzFhOnilHDp0AXCyHw==
"@babel/traverse@^7.23.0", "@babel/traverse@^7.7.2":
version "7.23.0"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.0.tgz#18196ddfbcf4ccea324b7f6d3ada00d8c5a99c53"
integrity sha512-t/QaEvyIoIkwzpiZ7aoSKK8kObQYeF7T2v+dazAYCb8SXtp58zEVkWW7zAnju8FNKNdr4ScAOEDmMItbyOmEYw==
dependencies:
"@babel/code-frame" "^7.22.13"
"@babel/generator" "^7.22.15"
"@babel/generator" "^7.23.0"
"@babel/helper-environment-visitor" "^7.22.20"
"@babel/helper-function-name" "^7.22.5"
"@babel/helper-function-name" "^7.23.0"
"@babel/helper-hoist-variables" "^7.22.5"
"@babel/helper-split-export-declaration" "^7.22.6"
"@babel/parser" "^7.22.16"
"@babel/types" "^7.22.19"
"@babel/parser" "^7.23.0"
"@babel/types" "^7.23.0"
debug "^4.1.0"
globals "^11.1.0"

"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.22.15", "@babel/types@^7.22.19", "@babel/types@^7.22.5", "@babel/types@^7.3.3":
version "7.22.19"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.22.19.tgz#7425343253556916e440e662bb221a93ddb75684"
integrity sha512-P7LAw/LbojPzkgp5oznjE6tQEIWbp4PkkfrZDINTro9zgBRtI324/EYsiSI7lhPbpIQ+DCeR2NNmMWANGGfZsg==
"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.22.15", "@babel/types@^7.22.5", "@babel/types@^7.23.0", "@babel/types@^7.3.3":
version "7.23.0"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.23.0.tgz#8c1f020c9df0e737e4e247c0619f58c68458aaeb"
integrity sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==
dependencies:
"@babel/helper-string-parser" "^7.22.5"
"@babel/helper-validator-identifier" "^7.22.19"
"@babel/helper-validator-identifier" "^7.22.20"
to-fast-properties "^2.0.0"

"@bcoe/v8-coverage@^0.2.3":
Expand Down Expand Up @@ -2355,11 +2355,16 @@ content-type@^1.0.4:
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.5.tgz#8b773162656d1d1086784c8f23a54ce6d73d7918"
integrity sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==

convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
convert-source-map@^1.4.0, convert-source-map@^1.6.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.9.0.tgz#7faae62353fb4213366d0ca98358d22e8368b05f"
integrity sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==

convert-source-map@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-2.0.0.tgz#4b560f649fc4e918dd0ab75cf4961e8bc882d82a"
integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==

[email protected]:
version "2.2.0"
resolved "https://registry.yarnpkg.com/copyfiles/-/copyfiles-2.2.0.tgz#d9fc6c06f299337fb7eeb7ea5887e9d7188d9d47"
Expand Down

0 comments on commit beffc7c

Please sign in to comment.