Skip to content

Commit 1c35386

Browse files
authored
fix(dashmate): invalid platform version in the status command (#2249)
1 parent 00df5a6 commit 1c35386

File tree

7 files changed

+54
-20
lines changed

7 files changed

+54
-20
lines changed

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ npmAuditExcludePackages:
1616
- "@humanwhocodes/object-schema" # TODO: Update eslint
1717
- micromatch # TODO: remove when new micromatch will be released https://github.com/advisories/GHSA-952p-6rrq-rcjv
1818
- eslint # TODO: Update eslint https://github.com/dashpay/platform/issues/2212
19+
- elliptic # TODO: Remove when elliptic >6.5.7 released
1920

2021
packageExtensions:
2122
"@dashevo/protobufjs@*":

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class GroupStatusCommand extends GroupBaseCommand {
8686
plain['Platform Status'] = colors.status(scope.platform.tenderdash.serviceStatus)(scope.platform.tenderdash.serviceStatus) || 'n/a';
8787
} else {
8888
plain['Platform Status'] = colors.status(scope.platform.tenderdash.serviceStatus)(scope.platform.tenderdash.serviceStatus) || 'n/a';
89-
plain['Platform Version'] = scope.platform.tenderdash.version || 'n/a';
89+
plain['Platform Version'] = scope.platform.drive.version || 'n/a';
9090
plain['Platform Block Height'] = scope.platform.tenderdash.latestBlockHeight || 'n/a';
9191
plain['Platform Peers'] = scope.platform.tenderdash.peers || 'n/a';
9292
plain['Platform Network'] = scope.platform.tenderdash.network || 'n/a';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export default class StatusCommand extends ConfigBaseCommand {
116116
plain['Platform Status'] = colors.status(platformStatus)(platformStatus) || 'n/a';
117117

118118
if (platform.tenderdash.serviceStatus === ServiceStatusEnum.up) {
119-
plain['Platform Version'] = platform.tenderdash.version || 'n/a';
119+
plain['Platform Version'] = platform.drive.version || 'n/a';
120120
plain['Platform Block Height'] = platform.tenderdash.latestBlockHeight || 'n/a';
121121
plain['Platform Peers'] = platform.tenderdash.peers || 'n/a';
122122
plain['Platform Network'] = platform.tenderdash.network || 'n/a';

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export default class PlatformStatusCommand extends ConfigBaseCommand {
3232
flags,
3333
dockerCompose,
3434
createRpcClient,
35-
getConnectionHost,
3635
config,
3736
getPlatformScope,
3837
) {

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export default function getPlatformScopeFactory(
159159
const info = {
160160
dockerStatus: null,
161161
serviceStatus: null,
162+
version: null,
162163
};
163164

164165
try {
@@ -192,6 +193,23 @@ export default function getPlatformScopeFactory(
192193
}
193194
}
194195

196+
try {
197+
const driveVersionResult = await dockerCompose.execCommand(
198+
config,
199+
'drive_abci',
200+
'drive-abci version',
201+
);
202+
203+
info.version = driveVersionResult.out.trim();
204+
} catch (e) {
205+
// Throw an error if it's not a Drive issue
206+
if (!(e instanceof DockerComposeError
207+
&& e.dockerComposeExecutionResult
208+
&& e.dockerComposeExecutionResult.exitCode !== 0)) {
209+
throw e;
210+
}
211+
}
212+
195213
return info;
196214
};
197215

packages/dashmate/test/unit/status/scopes/platform.spec.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ContainerIsNotPresentError
22
from '../../../../src/docker/errors/ContainerIsNotPresentError.js';
3+
import DockerComposeError from '../../../../src/docker/errors/DockerComposeError.js';
34
import providers from '../../../../src/status/providers.js';
45
import determineStatus from '../../../../src/status/determineStatus.js';
56
import getConfigMock from '../../../../src/test/mock/getConfigMock.js';
@@ -73,7 +74,8 @@ describe('getPlatformScopeFactory', () => {
7374
},
7475
});
7576
mockDockerCompose.isServiceRunning.returns(true);
76-
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
77+
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci status').resolves({ exitCode: 0, out: '' });
78+
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' });
7779
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));
7880

7981
const mockStatus = {
@@ -121,6 +123,7 @@ describe('getPlatformScopeFactory', () => {
121123
drive: {
122124
dockerStatus: DockerStatusEnum.running,
123125
serviceStatus: ServiceStatusEnum.up,
126+
version: '1.4.1',
124127
},
125128
};
126129

@@ -147,7 +150,7 @@ describe('getPlatformScopeFactory', () => {
147150
},
148151
});
149152
mockDockerCompose.isServiceRunning.returns(true);
150-
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
153+
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' });
151154
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));
152155

153156
const mockStatus = {
@@ -195,6 +198,7 @@ describe('getPlatformScopeFactory', () => {
195198
drive: {
196199
dockerStatus: DockerStatusEnum.running,
197200
serviceStatus: ServiceStatusEnum.up,
201+
version: '1.4.1',
198202
},
199203
};
200204

@@ -212,7 +216,6 @@ describe('getPlatformScopeFactory', () => {
212216

213217
it('should return empty scope if error during request to core', async () => {
214218
mockRpcClient.mnsync.withArgs('status').throws(new Error());
215-
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
216219
mockDockerCompose.isServiceRunning.returns(true);
217220
mockDetermineDockerStatus.withArgs(mockDockerCompose, config, 'drive_tenderdash')
218221
.returns(DockerStatusEnum.running);
@@ -268,7 +271,7 @@ describe('getPlatformScopeFactory', () => {
268271
},
269272
},
270273
});
271-
mockDockerCompose.execCommand.returns({ exitCode: 1, out: '' });
274+
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' });
272275
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));
273276

274277
const expectedScope = {
@@ -300,6 +303,7 @@ describe('getPlatformScopeFactory', () => {
300303
drive: {
301304
dockerStatus: DockerStatusEnum.running,
302305
serviceStatus: ServiceStatusEnum.wait_for_core,
306+
version: '1.4.1',
303307
},
304308
};
305309

@@ -324,7 +328,7 @@ describe('getPlatformScopeFactory', () => {
324328
.returns(DockerStatusEnum.running);
325329
mockDetermineDockerStatus.withArgs(mockDockerCompose, config, 'drive_abci')
326330
.returns(DockerStatusEnum.running);
327-
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
331+
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' });
328332
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));
329333

330334
const expectedScope = {
@@ -356,6 +360,7 @@ describe('getPlatformScopeFactory', () => {
356360
drive: {
357361
dockerStatus: DockerStatusEnum.running,
358362
serviceStatus: ServiceStatusEnum.up,
363+
version: '1.4.1',
359364
},
360365
};
361366

@@ -380,8 +385,11 @@ describe('getPlatformScopeFactory', () => {
380385
.returns(DockerStatusEnum.running);
381386
mockDetermineDockerStatus.withArgs(mockDockerCompose, config, 'drive_abci')
382387
.throws(new ContainerIsNotPresentError('drive_abci'));
383-
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
384388
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));
389+
const error = new DockerComposeError({
390+
exitCode: 1,
391+
});
392+
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').rejects(error);
385393

386394
const mockStatus = {
387395
node_info: {
@@ -434,6 +442,7 @@ describe('getPlatformScopeFactory', () => {
434442
drive: {
435443
dockerStatus: DockerStatusEnum.not_started,
436444
serviceStatus: ServiceStatusEnum.stopped,
445+
version: null,
437446
},
438447
};
439448

@@ -454,7 +463,8 @@ describe('getPlatformScopeFactory', () => {
454463
mockDockerCompose.isServiceRunning
455464
.withArgs(config, 'drive_tenderdash')
456465
.returns(true);
457-
mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' });
466+
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci status').resolves({ exitCode: 0, out: '' });
467+
mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' });
458468
mockDetermineDockerStatus.returns(DockerStatusEnum.running);
459469
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));
460470
mockFetch.returns(Promise.reject(new Error('FetchError')));
@@ -488,6 +498,7 @@ describe('getPlatformScopeFactory', () => {
488498
drive: {
489499
dockerStatus: DockerStatusEnum.running,
490500
serviceStatus: ServiceStatusEnum.up,
501+
version: '1.4.1',
491502
},
492503
};
493504

packages/rs-drive-abci/src/main.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ enum Commands {
5959
/// by creating `.fsck` file in database directory (`DB_PATH`).
6060
#[command()]
6161
Verify,
62+
63+
/// Print current software version
64+
#[command()]
65+
Version,
6266
}
6367

6468
/// Server that accepts connections from Tenderdash, and
@@ -148,6 +152,7 @@ impl Cli {
148152
Commands::Config => dump_config(&config)?,
149153
Commands::Status => runtime.block_on(check_status(&config))?,
150154
Commands::Verify => verify_grovedb(&config.db_path, true)?,
155+
Commands::Version => print_version(),
151156
};
152157

153158
Ok(())
@@ -220,16 +225,11 @@ fn main() -> Result<(), ExitCode> {
220225

221226
runtime.spawn(handle_signals(cancel.clone(), loggers));
222227

223-
let result = match cli.run(&runtime, config, cancel) {
224-
Ok(()) => {
225-
tracing::debug!("shutdown complete");
226-
Ok(())
227-
}
228-
Err(e) => {
229-
tracing::error!(error = e, "drive-abci failed: {e}");
230-
Err(ExitCode::FAILURE)
231-
}
232-
};
228+
let result = cli.run(&runtime, config, cancel).map_err(|e| {
229+
tracing::error!(error = e, "drive-abci failed: {e}");
230+
231+
ExitCode::FAILURE
232+
});
233233

234234
drop(runtime_guard);
235235
runtime.shutdown_timeout(Duration::from_millis(SHUTDOWN_TIMEOUT_MILIS));
@@ -387,6 +387,11 @@ fn verify_grovedb(db_path: &PathBuf, force: bool) -> Result<(), String> {
387387
}
388388
}
389389

390+
/// Print current software version.
391+
fn print_version() {
392+
println!("{}", env!("CARGO_PKG_VERSION"));
393+
}
394+
390395
fn load_config(path: &Option<PathBuf>) -> PlatformConfig {
391396
if let Some(path) = path {
392397
if let Err(e) = dotenvy::from_path(path) {

0 commit comments

Comments
 (0)