Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dashmate): invalid platform version in the status command #2249

Merged
merged 5 commits into from
Oct 18, 2024
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
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@*":
Expand Down
2 changes: 1 addition & 1 deletion packages/dashmate/src/commands/group/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/dashmate/src/commands/status/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default class StatusCommand extends ConfigBaseCommand {
plain['Platform Status'] = colors.status(platformStatus)(platformStatus) || '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';
Expand Down
1 change: 0 additions & 1 deletion packages/dashmate/src/commands/status/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default class PlatformStatusCommand extends ConfigBaseCommand {
flags,
dockerCompose,
createRpcClient,
getConnectionHost,
config,
getPlatformScope,
) {
Expand Down
18 changes: 18 additions & 0 deletions packages/dashmate/src/status/scopes/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export default function getPlatformScopeFactory(
const info = {
dockerStatus: null,
serviceStatus: null,
version: null,
};

try {
Expand Down Expand Up @@ -192,6 +193,23 @@ export default function getPlatformScopeFactory(
}
}

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;
}
}

return info;
};

Expand Down
25 changes: 18 additions & 7 deletions packages/dashmate/test/unit/status/scopes/platform.spec.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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' });
shumkov marked this conversation as resolved.
Show resolved Hide resolved
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));

const mockStatus = {
Expand Down Expand Up @@ -121,6 +123,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.up,
version: '1.4.1',
},
};

Expand All @@ -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 = {
Expand Down Expand Up @@ -195,6 +198,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.up,
version: '1.4.1',
},
};

Expand All @@ -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);
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -300,6 +303,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.wait_for_core,
version: '1.4.1',
},
};

Expand All @@ -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 = {
Expand Down Expand Up @@ -356,6 +360,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.up,
version: '1.4.1',
},
};

Expand All @@ -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: {
Expand Down Expand Up @@ -434,6 +442,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.not_started,
serviceStatus: ServiceStatusEnum.stopped,
version: null,
},
};

Expand All @@ -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' });
shumkov marked this conversation as resolved.
Show resolved Hide resolved
mockDetermineDockerStatus.returns(DockerStatusEnum.running);
mockMNOWatchProvider.returns(Promise.resolve('OPEN'));
mockFetch.returns(Promise.reject(new Error('FetchError')));
Expand Down Expand Up @@ -488,6 +498,7 @@ describe('getPlatformScopeFactory', () => {
drive: {
dockerStatus: DockerStatusEnum.running,
serviceStatus: ServiceStatusEnum.up,
version: '1.4.1',
},
};

Expand Down
25 changes: 15 additions & 10 deletions packages/rs-drive-abci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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
Expand Down Expand Up @@ -148,6 +152,7 @@ impl Cli {
Commands::Config => dump_config(&config)?,
Commands::Status => runtime.block_on(check_status(&config))?,
Commands::Verify => verify_grovedb(&config.db_path, true)?,
Commands::Version => print_version(),
};

Ok(())
Expand Down Expand Up @@ -220,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));
Expand Down Expand Up @@ -387,6 +387,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<PathBuf>) -> PlatformConfig {
if let Some(path) = path {
if let Err(e) = dotenvy::from_path(path) {
Expand Down
Loading