Skip to content

Commit 79059f6

Browse files
authored
fix(dashmate): status command shows tenderdash error before activation (#2028)
1 parent 46260df commit 79059f6

File tree

7 files changed

+130
-37
lines changed

7 files changed

+130
-37
lines changed

packages/dashmate/README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ In some cases, you must also additionally reset platform data:
8888
```bash
8989
$ dashmate stop
9090
$ npm install -g dashmate
91-
$ dashmate reset --platform-only --hard
91+
$ dashmate reset --platform --hard
9292
$ dashmate update
9393
$ dashmate setup
9494
$ dashmate start
@@ -283,14 +283,18 @@ The `reset` command removes all data corresponding to the specified config and a
283283

284284
```
285285
USAGE
286-
$ dashmate reset [-v] [--config <value>] [-h] [-f] [-p]
286+
$ dashmate reset [--config <value>] [-v] [-h] [-f] [-p] [--keep-data]
287287
288288
FLAGS
289-
-f, --force skip running services check
290-
-h, --hard reset config as well as data
291-
-p, --platform-only reset platform data only
292-
-v, --verbose use verbose mode for output
293-
--config=<value> configuration name to use
289+
-f, --force skip running services check
290+
-h, --hard reset config as well as services and data
291+
-p, --platform reset platform services and data only
292+
-v, --verbose use verbose mode for output
293+
--config=<value> configuration name to use
294+
--keep-data keep data
295+
296+
DESCRIPTION
297+
Reset node data
294298
```
295299

296300
To reset a node:
@@ -446,7 +450,7 @@ USAGE
446450
447451
FLAGS
448452
-f, --force reset even running node
449-
-p, --platform-only reset platform data only
453+
-p, --platform reset platform data only
450454
-v, --verbose use verbose mode for output
451455
--group=<value> group name to use
452456
--hard reset config as well as data

packages/dashmate/src/commands/status/platform.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default class PlatformStatusCommand extends ConfigBaseCommand {
3232
flags,
3333
dockerCompose,
3434
createRpcClient,
35+
getConnectionHost,
3536
config,
3637
getPlatformScope,
3738
) {
@@ -57,6 +58,7 @@ export default class PlatformStatusCommand extends ConfigBaseCommand {
5758

5859
if (flags.format === OUTPUT_FORMATS.PLAIN) {
5960
const {
61+
platformActivation,
6062
httpService,
6163
httpPort,
6264
httpPortState,
@@ -68,6 +70,8 @@ export default class PlatformStatusCommand extends ConfigBaseCommand {
6870
drive,
6971
} = scope;
7072

73+
plain['Platform Activation'] = platformActivation ? colors.platformActivation(platformActivation)(platformActivation) : 'n/a';
74+
7175
plain['HTTP service'] = httpService || 'n/a';
7276
plain['HTTP port'] = `${httpPort} ${httpPortState ? colors.portState(httpPortState)(httpPortState) : ''}`;
7377
plain['P2P service'] = p2pService || 'n/a';

packages/dashmate/src/status/colors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default {
3434
return chalk.green;
3535
case ServiceStatusEnum.syncing:
3636
case ServiceStatusEnum.wait_for_core:
37+
case ServiceStatusEnum.wait_for_activation:
3738
return chalk.yellow;
3839
default:
3940
return chalk.red;
@@ -73,4 +74,5 @@ export default {
7374
}
7475
return chalk.red;
7576
},
77+
platformActivation: (string) => (string.startsWith('Activated') ? chalk.green : chalk.yellow),
7678
};

packages/dashmate/src/status/determineStatus.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ export default {
3737
* Determine platform ServiceStatus based on DockerStatusEnum and core readiness
3838
* @param dockerStatus {DockerStatusEnum}
3939
* @param coreIsSynced {boolean}
40+
* @param mnRRSoftFork {object}
4041
* @returns {ServiceStatusEnum}
4142
*/
42-
platform: (dockerStatus, coreIsSynced) => {
43+
platform: (dockerStatus, coreIsSynced, mnRRSoftFork) => {
44+
if (coreIsSynced && !mnRRSoftFork.active) {
45+
return ServiceStatusEnum.wait_for_activation;
46+
}
47+
4348
if (dockerStatus === DockerStatusEnum.running) {
4449
return coreIsSynced ? ServiceStatusEnum.up : ServiceStatusEnum.wait_for_core;
4550
}

packages/dashmate/src/status/enums/serviceStatus.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export const ServiceStatusEnum = {
44
up: 'up',
55
syncing: 'syncing',
66
wait_for_core: 'wait_for_core',
7+
wait_for_activation: 'wait_for_activation',
78
error: 'error',
89
};

packages/dashmate/src/status/scopes/platform.js

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import prettyMs from 'pretty-ms';
12
import providers from '../providers.js';
23
import { DockerStatusEnum } from '../enums/dockerStatus.js';
34
import { ServiceStatusEnum } from '../enums/serviceStatus.js';
@@ -15,24 +16,35 @@ export default function getPlatformScopeFactory(
1516
createRpcClient,
1617
getConnectionHost,
1718
) {
18-
async function getMNSync(config) {
19+
async function getCoreInfo(config) {
1920
const rpcClient = createRpcClient({
2021
port: config.get('core.rpc.port'),
2122
user: 'dashmate',
2223
pass: config.get('core.rpc.users.dashmate.password'),
2324
host: await getConnectionHost(config, 'core', 'core.rpc.host'),
2425
});
2526

27+
const [mnSync, blockchainInfo] = await Promise.all([
28+
rpcClient.mnsync('status'),
29+
rpcClient.getBlockchainInfo(),
30+
]);
31+
32+
const {
33+
result: {
34+
softforks: { mn_rr: mnRR },
35+
},
36+
} = blockchainInfo;
37+
2638
const {
2739
result: {
2840
IsSynced: isSynced,
2941
},
30-
} = await rpcClient.mnsync('status');
42+
} = mnSync;
3143

32-
return isSynced;
44+
return { isSynced, mnRRSoftFork: mnRR };
3345
}
3446

35-
async function getTenderdashInfo(config, isCoreSynced) {
47+
async function getTenderdashInfo(config, isCoreSynced, mnRRSoftFork) {
3648
const info = {
3749
p2pPortState: null,
3850
httpPortState: null,
@@ -63,7 +75,7 @@ export default function getPlatformScopeFactory(
6375
}
6476

6577
const dockerStatus = await determineStatus.docker(dockerCompose, config, 'drive_tenderdash');
66-
const serviceStatus = determineStatus.platform(dockerStatus, isCoreSynced);
78+
const serviceStatus = determineStatus.platform(dockerStatus, isCoreSynced, mnRRSoftFork);
6779

6880
info.dockerStatus = dockerStatus;
6981
info.serviceStatus = serviceStatus;
@@ -142,15 +154,15 @@ export default function getPlatformScopeFactory(
142154
return info;
143155
}
144156

145-
const getDriveInfo = async (config, isCoreSynced) => {
157+
const getDriveInfo = async (config, isCoreSynced, mnRRSoftFork) => {
146158
const info = {
147159
dockerStatus: null,
148160
serviceStatus: null,
149161
};
150162

151163
try {
152164
info.dockerStatus = await determineStatus.docker(dockerCompose, config, 'drive_abci');
153-
info.serviceStatus = determineStatus.platform(info.dockerStatus, isCoreSynced);
165+
info.serviceStatus = determineStatus.platform(info.dockerStatus, isCoreSynced, mnRRSoftFork);
154166

155167
if (info.serviceStatus === ServiceStatusEnum.up) {
156168
const driveEchoResult = await dockerCompose.execCommand(
@@ -194,6 +206,7 @@ export default function getPlatformScopeFactory(
194206
const rpcService = `${rpcHost}:${rpcPort}`;
195207

196208
const scope = {
209+
platformActivation: null,
197210
coreIsSynced: null,
198211
httpPort,
199212
httpService,
@@ -233,11 +246,14 @@ export default function getPlatformScopeFactory(
233246
}
234247
}
235248

249+
let coreInfo;
250+
236251
try {
237-
const coreIsSynced = await getMNSync(config);
238-
scope.coreIsSynced = coreIsSynced;
252+
coreInfo = await getCoreInfo(config);
239253

240-
if (!coreIsSynced) {
254+
scope.coreIsSynced = coreInfo.isSynced;
255+
256+
if (!coreInfo.isSynced) {
241257
if (process.env.DEBUG) {
242258
// eslint-disable-next-line no-console
243259
console.error('Platform status is not available until masternode state is \'READY\'');
@@ -250,20 +266,34 @@ export default function getPlatformScopeFactory(
250266
}
251267
}
252268

253-
const [tenderdash, drive] = await Promise.all([
254-
getTenderdashInfo(config, scope.coreIsSynced),
255-
getDriveInfo(config, scope.coreIsSynced),
256-
]);
269+
if (coreInfo) {
270+
const { mnRRSoftFork } = coreInfo;
257271

258-
if (tenderdash) {
259-
scope.tenderdash = tenderdash;
272+
if (mnRRSoftFork.active) {
273+
scope.platformActivation = `Activated (at height ${mnRRSoftFork.height})`;
274+
} else {
275+
const startTime = mnRRSoftFork.bip9.start_time;
260276

261-
scope.httpPortState = tenderdash.httpPortState;
262-
scope.p2pPortState = tenderdash.p2pPortState;
263-
}
277+
const diff = (new Date().getTime() - startTime) / 1000;
278+
279+
scope.platformActivation = `Waiting for activation (approximately in ${prettyMs(diff, { compact: true })})`;
280+
}
281+
282+
const [tenderdash, drive] = await Promise.all([
283+
getTenderdashInfo(config, scope.coreIsSynced, coreInfo.mnRRSoftFork),
284+
getDriveInfo(config, scope.coreIsSynced, coreInfo.mnRRSoftFork),
285+
]);
264286

265-
if (drive) {
266-
scope.drive = drive;
287+
if (tenderdash) {
288+
scope.tenderdash = tenderdash;
289+
290+
scope.httpPortState = tenderdash.httpPortState;
291+
scope.p2pPortState = tenderdash.p2pPortState;
292+
}
293+
294+
if (drive) {
295+
scope.drive = drive;
296+
}
267297
}
268298

269299
return scope;

0 commit comments

Comments
 (0)