Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
45 changes: 43 additions & 2 deletions packages/dashmate/src/status/scopes/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ import determineStatus from '../determineStatus.js';
import ContainerIsNotPresentError from '../../docker/errors/ContainerIsNotPresentError.js';
import ServiceIsNotRunningError from '../../docker/errors/ServiceIsNotRunningError.js';

function parseProtocolVersion(protocolVersion) {
if (protocolVersion === null || typeof protocolVersion === 'undefined') {
return null;
}

const protocolVersionString = protocolVersion.toString().trim();

if (!/^\d+$/.test(protocolVersionString)) {
return null;
}

const parsedProtocolVersion = Number(protocolVersionString);

if (!Number.isSafeInteger(parsedProtocolVersion) || parsedProtocolVersion < 0) {
return null;
}

return parsedProtocolVersion;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}

function getConsensusParamsAppVersion(tenderdashConsensusParams) {
return tenderdashConsensusParams?.result?.consensus_params?.version?.app_version
?? tenderdashConsensusParams?.consensus_params?.version?.app_version;
}
Comment thread
thepastaclaw marked this conversation as resolved.

/**
* @returns {getPlatformScopeFactory}
* @param {DockerCompose} dockerCompose
Expand Down Expand Up @@ -116,13 +141,21 @@ export default function getPlatformScopeFactory(
tenderdashStatusResponse,
tenderdashNetInfoResponse,
tenderdashAbciInfoResponse,
tenderdashConsensusParams,
] = await Promise.all([
fetch(`http://${tenderdashHost}:${port}/status`),
fetch(`http://${tenderdashHost}:${port}/net_info`),
fetch(`http://${tenderdashHost}:${port}/abci_info`),
fetch(`http://${tenderdashHost}:${port}/consensus_params`)
.then((response) => response.json())
.catch(() => null),
Comment thread
thepastaclaw marked this conversation as resolved.
]);

const [tenderdashStatus, tenderdashNetInfo, tenderdashAbciInfo] = await Promise.all([
const [
tenderdashStatus,
tenderdashNetInfo,
tenderdashAbciInfo,
] = await Promise.all([
tenderdashStatusResponse.json(),
tenderdashNetInfoResponse.json(),
tenderdashAbciInfoResponse.json(),
Expand All @@ -144,7 +177,15 @@ export default function getPlatformScopeFactory(
}

info.version = version;
info.protocolVersion = parseInt(tenderdashStatus.node_info.protocol_version.app, 10);
const activeProtocolVersion = parseProtocolVersion(
getConsensusParamsAppVersion(tenderdashConsensusParams),
);
const nodeInfoProtocolVersion = parseProtocolVersion(
tenderdashStatus.node_info.protocol_version.app,
);

info.protocolVersion = activeProtocolVersion ?? nodeInfoProtocolVersion;
// abci_info app_version reflects the installed software's desired/supported version.
info.desiredProtocolVersion = tenderdashAbciInfo.response.app_version;
info.listening = listening;
info.latestBlockHeight = latestBlockHeight;
Expand Down
Loading
Loading