Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8f1321d
fix(dashmate): update v18 for the mainnet nodes
pshenmic Aug 30, 2022
a9527a6
Merge remote-tracking branch 'origin/master'
pshenmic Sep 1, 2022
278e656
Merge remote-tracking branch 'origin/master'
pshenmic Sep 13, 2022
1ddd2e6
feat(dashmate): add reindex command (wip)
pshenmic Sep 17, 2022
06c8079
chore(dashmate): bump migration version
pshenmic Sep 19, 2022
4916283
chore(dashmate): bump migration version
pshenmic Sep 19, 2022
c4e620b
fix(dashmate): start only core nodes during reindex
pshenmic Sep 20, 2022
ba785e2
feat(dashmate): change running core strategy
pshenmic Sep 20, 2022
06816e3
chore(dashmate): wip
pshenmic Sep 20, 2022
c217e46
fix(dashmate): fix naming
pshenmic Sep 22, 2022
5ebf64e
feat(dashmate): migrate wait job to observer
pshenmic Sep 22, 2022
071aca8
feat(dashmate): add healthcheck in the waitForCoreSync.js
pshenmic Sep 22, 2022
1da2f0d
feat(dashmate): move out upper
pshenmic Sep 22, 2022
63fa8c2
docs(dashmate): add reindex documentation
pshenmic Sep 22, 2022
397a456
chore(dashmate): lower dashcore
pshenmic Sep 22, 2022
0ca2433
chore(dashmate): code review fix
pshenmic Sep 23, 2022
4d1043a
chore(dashmate): remove outdated const
pshenmic Sep 23, 2022
6c33916
chore(dashmate): fix
pshenmic Sep 23, 2022
2fcc431
chore(dashmate): migrate to v23-dev
pshenmic Sep 28, 2022
9af5109
chore(dashmate): migrate to v23-dev
pshenmic Sep 28, 2022
20b97b4
Merge branch 'v0.23-dev' into feat/dashmate-reindex
pshenmic Sep 28, 2022
0e59322
docs(dashmate): fix code review fixes
pshenmic Sep 28, 2022
8ec03ef
chore(dashmate): update docs
pshenmic Sep 29, 2022
ba6b9d2
fix(dashmate): code review fixes
pshenmic Sep 29, 2022
975d33d
Merge branch 'v0.23-dev' into feat/dashmate-reindex
pshenmic Sep 29, 2022
a4f0586
fix(dashmate): fix typo
pshenmic Sep 29, 2022
e25207a
fix(dashmate): fix typo
pshenmic Sep 29, 2022
6d9df64
chore(dashmate): remove healthcheck
pshenmic Sep 29, 2022
7a1534e
chore(dashmate): typo fix
pshenmic Sep 29, 2022
3916d94
chore(dashmate): fix lint
pshenmic Sep 29, 2022
2df92b5
chore(dashmate): fix eslint
pshenmic Sep 29, 2022
754ee98
chore(dashmate): code review fixes
pshenmic Sep 29, 2022
1a27d86
feat(dashmate): make reindex as a core subscommand
pshenmic Sep 30, 2022
fcc6e42
fix(dashmate): Remove -masternodeblsprivkey from docker arguments (#538)
pshenmic Sep 29, 2022
3ccabdc
feat(dashmate): check for docker container existence
pshenmic Sep 30, 2022
47e46f7
Merge branch 'master' into feat/dashmate-reindex
pshenmic Sep 30, 2022
7fa29dd
chore(dashmate): code review text fixes
pshenmic Sep 30, 2022
60edd37
fix(dashmate): code review fix
pshenmic Sep 30, 2022
a7edbfc
chore(dashmate): fix code review
pshenmic Sep 30, 2022
c4d855a
fix(dashmate): reuse container info
pshenmic Sep 30, 2022
9430c87
chore(dashmate): some minor imprvmnts
pshenmic Oct 3, 2022
149d9cb
chore(dashmate): fix missing semicolon
pshenmic Oct 3, 2022
1f3e9b1
chore(dashmate): fix linting and some bugs
pshenmic Oct 3, 2022
d7a5d20
chore: combine migrations
shumkov Oct 3, 2022
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
32 changes: 32 additions & 0 deletions packages/dashmate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,38 @@ To reset a node:
$ dashmate reset
```

### Reindex dashcore chain data

Comment thread
pshenmic marked this conversation as resolved.
The `reindex` command rebuilds the block chain index using the downloaded block data.

It modifies the configuration, runs the core container in `reindex=1` mode, waits until it fully resynces, and returns it to the normal mode.

The process is interactive (shows progress) and can be interrupted any time, but you cannot start your configuration until the resync is fully complete.

The `reindex` command works for regular and local configurations.

```
Reindex Core

USAGE
$ dashmate core reindex [-v] [--config <value>]

FLAGS
-v, --verbose use verbose mode for output
--config=<value> configuration name to use

DESCRIPTION
Reindex Core

Reindex Core data
```

With the hard reset mode enabled, the corresponding config will be reset as well. To proceed, running the node [setup](#setup-node) is required.

To reset a node:
```bash
$ dashmate reset
=======
#### Hard reset

``dashmate reset --hard``
Expand Down
5 changes: 5 additions & 0 deletions packages/dashmate/configs/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ module.exports = {
'0.23.0-alpha.1': (configFile) => {
Object.entries(configFile.configs)
.forEach(([, config]) => {
config.core.reindex = {
enable: false,
containerId: null,
};

if (config.platform) {
// Update images
config.platform.dpns = systemConfigs.base.platform.dpns;
Expand Down
17 changes: 16 additions & 1 deletion packages/dashmate/configs/schema/configJsonSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,23 @@ module.exports = {
type: 'integer',
enum: [0, 1],
},
reindex: {
Comment thread
shumkov marked this conversation as resolved.
Comment thread
shumkov marked this conversation as resolved.
type: 'object',
properties: {
enable: {
type: 'boolean',
},
containerId: {
Comment thread
shumkov marked this conversation as resolved.
type: ['string', 'null'],
minLength: 1,
},
additionalProperties: false,
},
required: ['enable', 'containerId'],
additionalProperties: false,
},
},
required: ['docker', 'p2p', 'rpc', 'spork', 'masternode', 'miner', 'devnetName', 'debug'],
required: ['docker', 'p2p', 'rpc', 'spork', 'masternode', 'miner', 'devnetName', 'debug', 'reindex'],
additionalProperties: false,
},
platform: {
Expand Down
4 changes: 4 additions & 0 deletions packages/dashmate/configs/system/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ module.exports = {
},
},
debug: 0,
reindex: {
enable: false,
containerId: null,
},
devnetName: null,
},
platform: {
Expand Down
2 changes: 2 additions & 0 deletions packages/dashmate/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ services:
volumes:
- core_data:/dash
- ${DASHMATE_HOME_DIR:?err}/${CONFIG_NAME:?err}/core/dash.conf:/dash/.dashcore/dash.conf
command:
- dashd
stop_grace_period: 30s

volumes:
Expand Down
64 changes: 64 additions & 0 deletions packages/dashmate/src/commands/core/reindex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const { Listr } = require('listr2');

const { Flags } = require('@oclif/core');

const ConfigBaseCommand = require('../../oclif/command/ConfigBaseCommand');

const MuteOneLineError = require('../../oclif/errors/MuteOneLineError');

class ReindexCommand extends ConfigBaseCommand {
/**
* @param {Object} args
* @param {Object} flags
* @param {isSystemConfig} isSystemConfig
* @param {Config} config
* @param {reindexNodeTask} reindexNodeTask
*
* @return {Promise<void>}
*/
async runWithDependencies(
args,
{
verbose: isVerbose,
},
isSystemConfig,
config,
reindexNodeTask,
) {
const tasks = new Listr([
{
title: `Reindex ${config.getName()} node`,
task: () => reindexNodeTask(config),
},
],
{
renderer: isVerbose ? 'verbose' : 'default',
rendererOptions: {
showTimer: isVerbose,
clearOutput: false,
collapse: false,
showSubtasks: true,
},
});

try {
await tasks.run({
isVerbose,
});
} catch (e) {
throw new MuteOneLineError(e);
}
}
}

ReindexCommand.description = `Reindex Core

Reindex Core data
`;

ReindexCommand.flags = {
...ConfigBaseCommand.flags,
verbose: Flags.boolean({ char: 'v', description: 'use verbose mode for output', default: false }),
};

module.exports = ReindexCommand;
77 changes: 77 additions & 0 deletions packages/dashmate/src/commands/group/core/reindex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const { Listr } = require('listr2');

const { Flags } = require('@oclif/core');

const MuteOneLineError = require('../../../oclif/errors/MuteOneLineError');
const GroupBaseCommand = require('../../../oclif/command/GroupBaseCommand');

class GroupReindexCommand extends GroupBaseCommand {
/**
* @param {Object} args
* @param {Object} flags
* @param {isSystemConfig} isSystemConfig
* @param {reindexNodeTask} reindexNodeTask
* @param {createRpcClient} createRpcClient
* @param {dockerCompose} dockerCompose
* @param {Config[]} configGroup
* @return {Promise<void>}
*/
async runWithDependencies(
args,
{
verbose: isVerbose,
},
isSystemConfig,
reindexNodeTask,
createRpcClient,
dockerCompose,
configGroup,
) {
const groupName = configGroup[0].get('group');

const tasks = new Listr({
title: `Reindex ${groupName} nodes`,
task: async () => (
new Listr([
{
title: 'Reindex core nodes',
task: () => (
new Listr(configGroup.map((config) => ({
task: () => reindexNodeTask(config),
})))
),
},
])
),
},
{
renderer: isVerbose ? 'verbose' : 'default',
rendererOptions: {
showTimer: isVerbose,
clearOutput: false,
collapse: false,
showSubtasks: true,
},
});

try {
await tasks.run({
isVerbose,
});
} catch (e) {
throw new MuteOneLineError(e);
}
}
}

GroupReindexCommand.description = `Reindex group of Core services

Reindex group Core data
`;

GroupReindexCommand.flags = {
...GroupBaseCommand.flags,
verbose: Flags.boolean({ char: 'v', description: 'use verbose mode for output', default: false }),
};

module.exports = GroupReindexCommand;
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class ConfigFileJsonRepository {
* Save configs to file
*
* @param {ConfigFile} configFile
* @returns {Promise<void>}
* @returns {void}
*/
async write(configFile) {
write(configFile) {
const configFileJSON = JSON.stringify(configFile.toObject(), undefined, 2);

fs.writeFileSync(CONFIG_FILE_PATH, configFileJSON, 'utf8');
Expand Down
2 changes: 1 addition & 1 deletion packages/dashmate/src/core/startCoreFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function startCoreFactory(

if (options.wallet) {
if (isMasternode) {
throw new Error('You cannot run masternode with wallet mode on')
throw new Error('You cannot run masternode with wallet mode on');
}

coreCommand.push('--disablewallet=0');
Expand Down
17 changes: 10 additions & 7 deletions packages/dashmate/src/core/waitForCoreSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ const wait = require('../util/wait');
* Wait Core to be synced
*
* @typedef {waitForCoreSync}
* @param {RpcClient} rpcClient
* @param {function(progress: number)} [progressCallback]
* @param {CoreService} coreService
* @param {function(progress: {percent: number, blocks: number, headers: number})} progressCallback
* @return {Promise<void>}
*/
async function waitForCoreSync(rpcClient, progressCallback = () => {}) {
async function waitForCoreSync(coreService, progressCallback = () => {}) {
let isSynced = false;
let isBlockchainSynced = false;
let verificationProgress = 0.0;
let headers = 0;
let blocks = 0;

do {
({
result: { IsSynced: isSynced, IsBlockchainSynced: isBlockchainSynced },
} = await rpcClient.mnsync('status'));
} = await coreService.getRpcClient().mnsync('status'));

({
result: { verificationprogress: verificationProgress },
} = await rpcClient.getBlockchainInfo());
result: { verificationprogress: verificationProgress, headers, blocks },
} = await coreService.getRpcClient().getBlockchainInfo());
Comment thread
shumkov marked this conversation as resolved.

if (!isSynced || !isBlockchainSynced) {
await wait(10000);
progressCallback(verificationProgress);
progressCallback({ percent: verificationProgress, headers, blocks });
}
} while (!isSynced || !isBlockchainSynced);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/dashmate/src/createDIContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const waitForNodeToBeReadyTaskFactory = require('./listr/tasks/platform/waitForN
const enableCoreQuorumsTaskFactory = require('./listr/tasks/setup/local/enableCoreQuorumsTaskFactory');
const startGroupNodesTaskFactory = require('./listr/tasks/startGroupNodesTaskFactory');
const buildServicesTaskFactory = require('./listr/tasks/buildServicesTaskFactory');
const reindexNodeTaskFactory = require('./listr/tasks/reindexNodeTaskFactory');

const generateHDPrivateKeys = require('./util/generateHDPrivateKeys');

Expand Down Expand Up @@ -175,6 +176,7 @@ async function createDIContainer() {
outputStatusOverview: asFunction(outputStatusOverviewFactory),
waitForNodeToBeReadyTask: asFunction(waitForNodeToBeReadyTaskFactory).singleton(),
enableCoreQuorumsTask: asFunction(enableCoreQuorumsTaskFactory).singleton(),
reindexNodeTask: asFunction(reindexNodeTaskFactory).singleton(),
});

return container;
Expand Down
1 change: 1 addition & 0 deletions packages/dashmate/src/ensureHomeDirFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function ensureHomeDirFactory() {
function ensureHomeDir() {
if (fs.existsSync(HOME_DIR_PATH)) {
try {
// eslint-disable-next-line no-bitwise
fs.accessSync(HOME_DIR_PATH, fs.constants.R_OK | fs.constants.W_OK);
} catch (e) {
throw new HomeDirIsNotWritableError(HOME_DIR_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ function registerMasternodeTaskFactory(
task: async (ctx) => (
new Observable(async (observer) => {
await waitForCoreSync(
ctx.coreService.getRpcClient(),
ctx.coreService,
(verificationProgress) => {
observer.next(`${(verificationProgress * 100).toFixed(2)}% complete`);
const { percent, headers, blocks } = verificationProgress;
observer.next(`${(percent * 100).toFixed(2)}% complete (${blocks} / ${headers})`);
},
);

Expand Down
Loading