From 4c4d9251d05fba61d6fbc6cfb1742ac0cce93402 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 16 Oct 2024 23:23:05 +0700 Subject: [PATCH 1/4] fix(dashmate): invalid platform version in the status command --- packages/dashmate/src/commands/group/status.js | 2 +- packages/dashmate/src/commands/status/index.js | 2 +- packages/dashmate/src/commands/status/platform.js | 1 - packages/dashmate/src/status/scopes/overview.js | 3 ++- packages/dashmate/src/status/scopes/platform.js | 12 ++++++++++++ packages/rs-drive-abci/src/main.rs | 10 ++++++++++ 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/dashmate/src/commands/group/status.js b/packages/dashmate/src/commands/group/status.js index d3edbd8800..f9c20f800f 100644 --- a/packages/dashmate/src/commands/group/status.js +++ b/packages/dashmate/src/commands/group/status.js @@ -86,7 +86,7 @@ export default class GroupStatusCommand extends GroupBaseCommand { plain['Platform Status'] = colors.status(scope.platform.tenderdash.serviceStatus)(scope.platform.tenderdash.serviceStatus) || 'n/a'; } else { plain['Platform Status'] = colors.status(scope.platform.tenderdash.serviceStatus)(scope.platform.tenderdash.serviceStatus) || 'n/a'; - plain['Platform Version'] = scope.platform.tenderdash.version || 'n/a'; + plain['Platform Version'] = scope.platform.drive.version || 'n/a'; plain['Platform Block Height'] = scope.platform.tenderdash.latestBlockHeight || 'n/a'; plain['Platform Peers'] = scope.platform.tenderdash.peers || 'n/a'; plain['Platform Network'] = scope.platform.tenderdash.network || 'n/a'; diff --git a/packages/dashmate/src/commands/status/index.js b/packages/dashmate/src/commands/status/index.js index 6276bb9796..dff8849d3a 100644 --- a/packages/dashmate/src/commands/status/index.js +++ b/packages/dashmate/src/commands/status/index.js @@ -112,7 +112,7 @@ export default class StatusCommand extends ConfigBaseCommand { plain['Platform Status'] = colors.status(platform.tenderdash.serviceStatus)(platform.tenderdash.serviceStatus) || 'n/a'; if (platform.tenderdash.serviceStatus === ServiceStatusEnum.up) { - plain['Platform Version'] = platform.tenderdash.version || 'n/a'; + plain['Platform Version'] = platform.drive.version || 'n/a'; plain['Platform Block Height'] = platform.tenderdash.latestBlockHeight || 'n/a'; plain['Platform Peers'] = platform.tenderdash.peers || 'n/a'; plain['Platform Network'] = platform.tenderdash.network || 'n/a'; diff --git a/packages/dashmate/src/commands/status/platform.js b/packages/dashmate/src/commands/status/platform.js index 2c0e401f18..4f6eba5fbb 100644 --- a/packages/dashmate/src/commands/status/platform.js +++ b/packages/dashmate/src/commands/status/platform.js @@ -32,7 +32,6 @@ export default class PlatformStatusCommand extends ConfigBaseCommand { flags, dockerCompose, createRpcClient, - getConnectionHost, config, getPlatformScope, ) { diff --git a/packages/dashmate/src/status/scopes/overview.js b/packages/dashmate/src/status/scopes/overview.js index a38d9ffb5e..2a56bd3678 100644 --- a/packages/dashmate/src/status/scopes/overview.js +++ b/packages/dashmate/src/status/scopes/overview.js @@ -57,8 +57,9 @@ export default function getOverviewScopeFactory( } if (config.get('platform.enable')) { - const { tenderdash } = await getPlatformScope(config); + const { drive, tenderdash } = await getPlatformScope(config); + platform.drive = drive; platform.tenderdash = tenderdash; } diff --git a/packages/dashmate/src/status/scopes/platform.js b/packages/dashmate/src/status/scopes/platform.js index 7605104ecb..56860d5056 100644 --- a/packages/dashmate/src/status/scopes/platform.js +++ b/packages/dashmate/src/status/scopes/platform.js @@ -174,6 +174,18 @@ export default function getPlatformScopeFactory( if (driveEchoResult.exitCode !== 0) { info.serviceStatus = ServiceStatusEnum.error; } + + const driveVersionResult = await dockerCompose.execCommand( + config, + 'drive_abci', + 'drive-abci version', + ); + + console.dir(driveVersionResult); + + if (driveVersionResult.exitCode === 0) { + info.version = driveVersionResult.stdout; + } } return info; diff --git a/packages/rs-drive-abci/src/main.rs b/packages/rs-drive-abci/src/main.rs index aab50e3e06..ad82c770c1 100644 --- a/packages/rs-drive-abci/src/main.rs +++ b/packages/rs-drive-abci/src/main.rs @@ -54,6 +54,10 @@ enum Commands { /// by creating `.fsck` file in database directory (`DB_PATH`). #[command()] Verify, + + /// Print current software version + #[command()] + Version, } /// Server that accepts connections from Tenderdash, and @@ -134,6 +138,7 @@ impl Cli { Commands::Config => dump_config(&config)?, Commands::Status => check_status(&config)?, Commands::Verify => verify_grovedb(&config.db_path, true)?, + Commands::Version => print_version(), }; Ok(()) @@ -386,6 +391,11 @@ fn verify_grovedb(db_path: &PathBuf, force: bool) -> Result<(), String> { } } +/// Print current software version. +fn print_version() { + println!("{}", env!("CARGO_PKG_VERSION")); +} + fn load_config(path: &Option) -> PlatformConfig { if let Some(path) = path { if let Err(e) = dotenvy::from_path(path) { From f088a3c5e3350c29fb575b3e150576be8adb36ab Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 18 Oct 2024 18:23:12 +0700 Subject: [PATCH 2/4] fix: getting version from drive --- packages/dashmate/src/status/scopes/platform.js | 14 ++++++++++---- packages/rs-drive-abci/src/main.rs | 15 +++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/dashmate/src/status/scopes/platform.js b/packages/dashmate/src/status/scopes/platform.js index 8f537508f3..cb53d89788 100644 --- a/packages/dashmate/src/status/scopes/platform.js +++ b/packages/dashmate/src/status/scopes/platform.js @@ -159,6 +159,7 @@ export default function getPlatformScopeFactory( const info = { dockerStatus: null, serviceStatus: null, + version: null, }; try { @@ -189,17 +190,22 @@ export default function getPlatformScopeFactory( } else { throw e; } + } + try { const driveVersionResult = await dockerCompose.execCommand( config, 'drive_abci', 'drive-abci version', ); - console.dir(driveVersionResult); - - if (driveVersionResult.exitCode === 0) { - info.version = driveVersionResult.stdout; + info.version = driveVersionResult.out.trim(); + } catch (e) { + // Throw an error if it's not a Drive issue + if (!(e instanceof DockerComposeError + && e.dockerComposeExecutionResult + && e.dockerComposeExecutionResult.exitCode !== 0)) { + throw e; } } } diff --git a/packages/rs-drive-abci/src/main.rs b/packages/rs-drive-abci/src/main.rs index e6c702e3dc..a8ae1adccd 100644 --- a/packages/rs-drive-abci/src/main.rs +++ b/packages/rs-drive-abci/src/main.rs @@ -225,16 +225,11 @@ fn main() -> Result<(), ExitCode> { runtime.spawn(handle_signals(cancel.clone(), loggers)); - let result = match cli.run(&runtime, config, cancel) { - Ok(()) => { - tracing::debug!("shutdown complete"); - Ok(()) - } - Err(e) => { - tracing::error!(error = e, "drive-abci failed: {e}"); - Err(ExitCode::FAILURE) - } - }; + let result = cli.run(&runtime, config, cancel).map_err(|e| { + tracing::error!(error = e, "drive-abci failed: {e}"); + + ExitCode::FAILURE + }); drop(runtime_guard); runtime.shutdown_timeout(Duration::from_millis(SHUTDOWN_TIMEOUT_MILIS)); From ca0c22324d0b680cfe91a04ad83ba7294e7e64b6 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 18 Oct 2024 18:36:26 +0700 Subject: [PATCH 3/4] chore: temporary ignore elliptic audit --- .yarnrc.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.yarnrc.yml b/.yarnrc.yml index dd002648b0..c59f803d7d 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -16,6 +16,7 @@ npmAuditExcludePackages: - "@humanwhocodes/object-schema" # TODO: Update eslint - micromatch # TODO: remove when new micromatch will be released https://github.com/advisories/GHSA-952p-6rrq-rcjv - eslint # TODO: Update eslint https://github.com/dashpay/platform/issues/2212 + - elliptic # TODO: Remove when elliptic >6.5.7 released packageExtensions: "@dashevo/protobufjs@*": From bd518c94731cb35f24e675e3e0664ad805fe6c56 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 18 Oct 2024 22:22:21 +0700 Subject: [PATCH 4/4] fix: version is available only when Drive is up --- .../dashmate/src/status/scopes/platform.js | 28 +++++++++---------- .../test/unit/status/scopes/platform.spec.js | 25 ++++++++++++----- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/packages/dashmate/src/status/scopes/platform.js b/packages/dashmate/src/status/scopes/platform.js index cb53d89788..04daa6070f 100644 --- a/packages/dashmate/src/status/scopes/platform.js +++ b/packages/dashmate/src/status/scopes/platform.js @@ -191,22 +191,22 @@ export default function getPlatformScopeFactory( throw e; } } + } - try { - const driveVersionResult = await dockerCompose.execCommand( - config, - 'drive_abci', - 'drive-abci version', - ); + try { + const driveVersionResult = await dockerCompose.execCommand( + config, + 'drive_abci', + 'drive-abci version', + ); - info.version = driveVersionResult.out.trim(); - } catch (e) { - // Throw an error if it's not a Drive issue - if (!(e instanceof DockerComposeError - && e.dockerComposeExecutionResult - && e.dockerComposeExecutionResult.exitCode !== 0)) { - throw e; - } + info.version = driveVersionResult.out.trim(); + } catch (e) { + // Throw an error if it's not a Drive issue + if (!(e instanceof DockerComposeError + && e.dockerComposeExecutionResult + && e.dockerComposeExecutionResult.exitCode !== 0)) { + throw e; } } diff --git a/packages/dashmate/test/unit/status/scopes/platform.spec.js b/packages/dashmate/test/unit/status/scopes/platform.spec.js index b94f0da636..fc8bc8bf1c 100644 --- a/packages/dashmate/test/unit/status/scopes/platform.spec.js +++ b/packages/dashmate/test/unit/status/scopes/platform.spec.js @@ -1,5 +1,6 @@ import ContainerIsNotPresentError from '../../../../src/docker/errors/ContainerIsNotPresentError.js'; +import DockerComposeError from '../../../../src/docker/errors/DockerComposeError.js'; import providers from '../../../../src/status/providers.js'; import determineStatus from '../../../../src/status/determineStatus.js'; import getConfigMock from '../../../../src/test/mock/getConfigMock.js'; @@ -73,7 +74,8 @@ describe('getPlatformScopeFactory', () => { }, }); mockDockerCompose.isServiceRunning.returns(true); - mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' }); + mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci status').resolves({ exitCode: 0, out: '' }); + mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' }); mockMNOWatchProvider.returns(Promise.resolve('OPEN')); const mockStatus = { @@ -121,6 +123,7 @@ describe('getPlatformScopeFactory', () => { drive: { dockerStatus: DockerStatusEnum.running, serviceStatus: ServiceStatusEnum.up, + version: '1.4.1', }, }; @@ -147,7 +150,7 @@ describe('getPlatformScopeFactory', () => { }, }); mockDockerCompose.isServiceRunning.returns(true); - mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' }); + mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' }); mockMNOWatchProvider.returns(Promise.resolve('OPEN')); const mockStatus = { @@ -195,6 +198,7 @@ describe('getPlatformScopeFactory', () => { drive: { dockerStatus: DockerStatusEnum.running, serviceStatus: ServiceStatusEnum.up, + version: '1.4.1', }, }; @@ -212,7 +216,6 @@ describe('getPlatformScopeFactory', () => { it('should return empty scope if error during request to core', async () => { mockRpcClient.mnsync.withArgs('status').throws(new Error()); - mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' }); mockDockerCompose.isServiceRunning.returns(true); mockDetermineDockerStatus.withArgs(mockDockerCompose, config, 'drive_tenderdash') .returns(DockerStatusEnum.running); @@ -268,7 +271,7 @@ describe('getPlatformScopeFactory', () => { }, }, }); - mockDockerCompose.execCommand.returns({ exitCode: 1, out: '' }); + mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' }); mockMNOWatchProvider.returns(Promise.resolve('OPEN')); const expectedScope = { @@ -300,6 +303,7 @@ describe('getPlatformScopeFactory', () => { drive: { dockerStatus: DockerStatusEnum.running, serviceStatus: ServiceStatusEnum.wait_for_core, + version: '1.4.1', }, }; @@ -324,7 +328,7 @@ describe('getPlatformScopeFactory', () => { .returns(DockerStatusEnum.running); mockDetermineDockerStatus.withArgs(mockDockerCompose, config, 'drive_abci') .returns(DockerStatusEnum.running); - mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' }); + mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' }); mockMNOWatchProvider.returns(Promise.resolve('OPEN')); const expectedScope = { @@ -356,6 +360,7 @@ describe('getPlatformScopeFactory', () => { drive: { dockerStatus: DockerStatusEnum.running, serviceStatus: ServiceStatusEnum.up, + version: '1.4.1', }, }; @@ -380,8 +385,11 @@ describe('getPlatformScopeFactory', () => { .returns(DockerStatusEnum.running); mockDetermineDockerStatus.withArgs(mockDockerCompose, config, 'drive_abci') .throws(new ContainerIsNotPresentError('drive_abci')); - mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' }); mockMNOWatchProvider.returns(Promise.resolve('OPEN')); + const error = new DockerComposeError({ + exitCode: 1, + }); + mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').rejects(error); const mockStatus = { node_info: { @@ -434,6 +442,7 @@ describe('getPlatformScopeFactory', () => { drive: { dockerStatus: DockerStatusEnum.not_started, serviceStatus: ServiceStatusEnum.stopped, + version: null, }, }; @@ -454,7 +463,8 @@ describe('getPlatformScopeFactory', () => { mockDockerCompose.isServiceRunning .withArgs(config, 'drive_tenderdash') .returns(true); - mockDockerCompose.execCommand.returns({ exitCode: 0, out: '' }); + mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci status').resolves({ exitCode: 0, out: '' }); + mockDockerCompose.execCommand.withArgs(config, 'drive_abci', 'drive-abci version').resolves({ exitCode: 0, out: '1.4.1' }); mockDetermineDockerStatus.returns(DockerStatusEnum.running); mockMNOWatchProvider.returns(Promise.resolve('OPEN')); mockFetch.returns(Promise.reject(new Error('FetchError'))); @@ -488,6 +498,7 @@ describe('getPlatformScopeFactory', () => { drive: { dockerStatus: DockerStatusEnum.running, serviceStatus: ServiceStatusEnum.up, + version: '1.4.1', }, };