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

Update generator status default values to snapshot height #202

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,13 @@ class LiskMigrator extends Command {
commandsToExecute.push('\n', '-----------------------------------------------------', '\n');
}

await writeCommandsToExec(this, networkConstant, outputDir, commandsToExecute);
await writeCommandsToExec(
this,
networkConstant,
snapshotHeight,
outputDir,
commandsToExecute,
);

this.error(
`Migrator could not finish execution successfully due to: ${
Expand All @@ -535,7 +541,7 @@ class LiskMigrator extends Command {
);
}

await writeCommandsToExec(this, networkConstant, outputDir);
await writeCommandsToExec(this, networkConstant, snapshotHeight, outputDir);

this.log('Successfully finished migration. Exiting!!!');
process.exit(0);
Expand Down
9 changes: 8 additions & 1 deletion src/utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { NetworkConfigLocal } from '../types';

export const getCommandsToExecPostMigration = async (
networkConstant: NetworkConfigLocal,
snapshotHeight: number,
outputDir: string,
) => {
const commandsToExecute = [];
Expand All @@ -44,7 +45,11 @@ export const getCommandsToExecPostMigration = async (
`lisk-core keys:create --chainid ${chainID} --output ${keysFilepath} --add-legacy`,
`lisk-core keys:import --file-path ${keysFilepath}`,
`lisk-core endpoint:invoke random_setHashOnion '{ "address":"${forgingStatus.lskAddress}"}'`,
`lisk-core endpoint:invoke generator_setStatus '{ "address":"${forgingStatus.lskAddress}", "height": ${forgingStatus.height}, "maxHeightGenerated": ${forgingStatus.maxHeightPreviouslyForged}, "maxHeightPrevoted": ${forgingStatus.maxHeightPrevoted} }' --pretty`,
`lisk-core endpoint:invoke generator_setStatus '{ "address":"${
forgingStatus.lskAddress
}", "height": ${forgingStatus.height ?? snapshotHeight}, "maxHeightGenerated": ${
forgingStatus.maxHeightPreviouslyForged ?? snapshotHeight
}, "maxHeightPrevoted": ${forgingStatus.maxHeightPrevoted ?? snapshotHeight} }' --pretty`,
`lisk-core generator:enable ${forgingStatus.lskAddress} --use-status-value`,
'lisk-core transaction:create legacy registerKeys 400000 --key-derivation-path=legacy --send',
);
Expand All @@ -59,12 +64,14 @@ export const getCommandsToExecPostMigration = async (
export const writeCommandsToExec = async (
_this: Command,
networkConstant: NetworkConfigLocal,
snapshotHeight: number,
outputDir: string,
preCompletionCommands?: string[],
) => {
const commandsToExecPreCompletion = preCompletionCommands ?? [];
const commandsToExecPostMigration = await getCommandsToExecPostMigration(
networkConstant,
snapshotHeight,
outputDir,
);

Expand Down
8 changes: 4 additions & 4 deletions src/utils/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ export const validateStartCommandFlags = async (
};

const resolveLiskCoreStartCommand = async (_this: Command, network: string, configPath: string) => {
const baseStartCommand = `lisk-core start --network ${network}`;
const defaultStartCommand = `${baseStartCommand} --config ${configPath}`;

const isUserConfirmed = await cli.confirm(
'Would you like to customize the Lisk Core v4 start command? [yes/no]',
`Default start command: ${defaultStartCommand}\nWould you like to customize the Lisk Core v4 start command? [yes/no]`,
);

const baseStartCommand = `lisk-core start --network ${network}`;

if (!isUserConfirmed) {
const defaultStartCommand = `${baseStartCommand} --config ${configPath}`;
liskCoreStartCommand = defaultStartCommand;
return defaultStartCommand;
}
Expand Down
9 changes: 8 additions & 1 deletion test/unit/utils/commands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ const mockCommand = {
};

describe('Test getCommandsToExecPostMigration method', () => {
const snapshotHeight = 10815;

it('should create commandsToExecute text file', async () => {
const networkConstant =
NETWORK_CONSTANT['4c09e6a781fc4c7bdb936ee815de8f94190f8a7519becd9de2081832be309a99'];

const commandsToExecute = await getCommandsToExecPostMigration(networkConstant, outputDir);
const commandsToExecute = await getCommandsToExecPostMigration(
networkConstant,
snapshotHeight,
outputDir,
);
await writeCommandsToExec(
mockCommand as Command,
networkConstant,
snapshotHeight,
outputDir,
commandsToExecute,
);
Expand Down