From ad56628b265fd6f7f5d8502d90f9c0b8ecbf4052 Mon Sep 17 00:00:00 2001 From: Tadeas Kmenta Date: Wed, 8 Sep 2021 15:36:10 +0200 Subject: [PATCH 1/4] adjust hardware check --- ZelBack/src/services/fluxCommunication.js | 56 ----------------------- ZelBack/src/services/idService.js | 46 ++++++++++++++++++- ZelBack/src/services/serviceManager.js | 4 -- package.json | 2 +- 4 files changed, 46 insertions(+), 62 deletions(-) diff --git a/ZelBack/src/services/fluxCommunication.js b/ZelBack/src/services/fluxCommunication.js index eae67a2fa..e150d0c2f 100644 --- a/ZelBack/src/services/fluxCommunication.js +++ b/ZelBack/src/services/fluxCommunication.js @@ -4,7 +4,6 @@ const bitcoinjs = require('bitcoinjs-lib'); const config = require('config'); const cmd = require('node-cmd'); const LRU = require('lru-cache'); -const os = require('os'); const fs = require('fs').promises; const path = require('path'); // eslint-disable-next-line import/no-extraneous-dependencies @@ -23,7 +22,6 @@ const incomingPeers = []; // array of objects containing ip let dosState = 0; // we can start at bigger number later let dosMessage = null; -let nodeHardwareSpecsGood = true; const minimumFluxBenchAllowedVersion = 223; @@ -1251,7 +1249,6 @@ async function checkDeterministicNodesCollisions() { async function getDOSState(req, res) { const data = { dosState, - nodeHardwareSpecsGood, dosMessage, }; response = serviceHelper.createDataMessage(data); @@ -1437,58 +1434,6 @@ async function adjustGitRepository() { } } -async function confirmNodeTierHardware() { - try { - // eslint-disable-next-line global-require - const appsService = require('./appsService'); - const tier = await appsService.nodeTier(); - const nodeRam = os.totalmem() / 1024 / 1024 / 1024; - const nodeCpuCores = os.cpus().length; - log.info(`Node Tier: ${tier}`); - log.info(`Node Total Ram: ${nodeRam}`); - log.info(`Node Cpu Cores: ${nodeCpuCores}`); - if (tier === 'bamf') { - if (nodeRam < 31) { - log.error(`Node Total Ram (${nodeRam}) below Stratus requirements`); - nodeHardwareSpecsGood = false; - return; - } - if (nodeCpuCores < 8) { - log.error(`Node Cpu Cores (${nodeCpuCores}) below Stratus requirements`); - nodeHardwareSpecsGood = false; - return; - } - } else if (tier === 'super') { - if (nodeRam < 7) { - log.error(`Node Total Ram (${nodeRam}) below Nimbus requirements`); - nodeHardwareSpecsGood = false; - return; - } - if (nodeCpuCores < 4) { - log.error(`Node Cpu Cores (${nodeCpuCores}) below Nimbus requirements`); - nodeHardwareSpecsGood = false; - return; - } - } else { - if (nodeRam < 3) { - log.error(`Node Total Ram (${nodeRam}) below Cumulus requirements`); - nodeHardwareSpecsGood = false; - return; - } - if (nodeCpuCores < 2) { - log.error(`Node Cpu Cores (${nodeCpuCores}) below Cumulus requirements`); - nodeHardwareSpecsGood = false; - return; - } - } - log.info('Hardware specs check result ok'); - nodeHardwareSpecsGood = true; - } catch (error) { - log.error(error); - nodeHardwareSpecsGood = false; - } -} - module.exports = { getFluxMessageSignature, verifyOriginalFluxBroadcast, @@ -1526,5 +1471,4 @@ module.exports = { adjustFirewall, checkDeterministicNodesCollisions, adjustGitRepository, - confirmNodeTierHardware, }; diff --git a/ZelBack/src/services/idService.js b/ZelBack/src/services/idService.js index 8adfef29d..ca64762bd 100644 --- a/ZelBack/src/services/idService.js +++ b/ZelBack/src/services/idService.js @@ -1,6 +1,7 @@ const config = require('config'); const bitcoinMessage = require('bitcoinjs-message'); const qs = require('qs'); +const os = require('os'); const userconfig = require('../../../config/userconfig'); const log = require('../lib/log'); @@ -10,12 +11,55 @@ const fluxCommunication = require('./fluxCommunication'); const goodchars = /^[1-9a-km-zA-HJ-NP-Z]+$/; +async function confirmNodeTierHardware() { + try { + // eslint-disable-next-line global-require + const tier = await appsService.nodeTier().catch((error) => { + log.error(error); + }); + const nodeRam = os.totalmem() / 1024 / 1024 / 1024; + const nodeCpuCores = os.cpus().length; + log.info(`Node Tier: ${tier}`); + log.info(`Node Total Ram: ${nodeRam}`); + log.info(`Node Cpu Cores: ${nodeCpuCores}`); + if (tier === 'bamf') { + if (nodeRam < 31) { + throw new Error(`Node Total Ram (${nodeRam}) below Stratus requirements`); + } + if (nodeCpuCores < 8) { + throw new Error(`Node Cpu Cores (${nodeCpuCores}) below Stratus requirements`); + } + } else if (tier === 'super') { + if (nodeRam < 7) { + throw new Error(`Node Total Ram (${nodeRam}) below Nimbus requirements`); + } + if (nodeCpuCores < 4) { + throw new Error(`Node Cpu Cores (${nodeCpuCores}) below Nimbus requirements`); + } + } else if (tier === 'basic') { + if (nodeRam < 3) { + throw new Error(`Node Total Ram (${nodeRam}) below Cumulus requirements`); + } + if (nodeCpuCores < 2) { + throw new Error(`Node Cpu Cores (${nodeCpuCores}) below Cumulus requirements`); + } + } + return true; + } catch (error) { + log.error(error); + return false; + } +} + async function loginPhrase(req, res) { try { // check docker availablility await appsService.dockerListContainers(false); // check Node Hardware Requirements are ok. - await fluxCommunication.confirmNodeTierHardware(); + const hwPassed = await confirmNodeTierHardware(); + if (hwPassed === false) { + throw new Error('Node hardware requirements not met'); + } // check DOS state (contains daemon checks) const dosState = await fluxCommunication.getDOSState(); if (dosState.status === 'error') { diff --git a/ZelBack/src/services/serviceManager.js b/ZelBack/src/services/serviceManager.js index c76b28576..8965d8a6c 100644 --- a/ZelBack/src/services/serviceManager.js +++ b/ZelBack/src/services/serviceManager.js @@ -63,10 +63,6 @@ async function startFluxFunctions() { log.info('Starting to spawn applications'); appsService.trySpawningGlobalApplication(); }, 14 * 60 * 1000); - setInterval(() => { - log.info('Checking node Hardware according to Tier'); - fluxCommunication.confirmNodeTierHardware(); - }, 5 * 60 * 1000); fluxCommunication.adjustGitRepository(); // temporary function to be removed after couple of versions } catch (e) { log.error(e); diff --git a/package.json b/package.json index 77b937d71..29fdf3d5d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flux", - "version": "2.0.1", + "version": "2.0.2", "description": "Flux, Your Gateway to a Decentralized World", "repository": { "type": "git", From c9ee4dea26b26ee6cbe5e47470d15b9b3b6d5957 Mon Sep 17 00:00:00 2001 From: Tadeas Kmenta Date: Wed, 8 Sep 2021 15:37:53 +0200 Subject: [PATCH 2/4] remove comment --- ZelBack/src/services/idService.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ZelBack/src/services/idService.js b/ZelBack/src/services/idService.js index ca64762bd..07b77fc96 100644 --- a/ZelBack/src/services/idService.js +++ b/ZelBack/src/services/idService.js @@ -13,7 +13,6 @@ const goodchars = /^[1-9a-km-zA-HJ-NP-Z]+$/; async function confirmNodeTierHardware() { try { - // eslint-disable-next-line global-require const tier = await appsService.nodeTier().catch((error) => { log.error(error); }); From 189e9d27807b66a7a080b61eb372ea93e20a1702 Mon Sep 17 00:00:00 2001 From: Tadeas Kmenta Date: Wed, 8 Sep 2021 15:39:33 +0200 Subject: [PATCH 3/4] revert test --- tests/ZelBack/apiTests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ZelBack/apiTests.js b/tests/ZelBack/apiTests.js index f4b7f9394..dcdd32bd3 100644 --- a/tests/ZelBack/apiTests.js +++ b/tests/ZelBack/apiTests.js @@ -40,9 +40,9 @@ describe('loading express', function () { .get('/foo/bar') .expect(404, done); }); - it('/id/emergencyphrase', function testSlash(done) { + it('/id/loginphrase', function testSlash(done) { request(server) - .get('/id/emergencyphrase') + .get('/id/loginphrase') .expect(200) .end((err, res) => { if (err) { From 1fb7ef2475da36c0e1fd054e6de06911fb7affca Mon Sep 17 00:00:00 2001 From: Tadeas Kmenta Date: Wed, 8 Sep 2021 15:56:57 +0200 Subject: [PATCH 4/4] remove check --- ZelBack/src/services/idService.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ZelBack/src/services/idService.js b/ZelBack/src/services/idService.js index 07b77fc96..ab600872f 100644 --- a/ZelBack/src/services/idService.js +++ b/ZelBack/src/services/idService.js @@ -55,10 +55,10 @@ async function loginPhrase(req, res) { // check docker availablility await appsService.dockerListContainers(false); // check Node Hardware Requirements are ok. - const hwPassed = await confirmNodeTierHardware(); - if (hwPassed === false) { - throw new Error('Node hardware requirements not met'); - } + // const hwPassed = await confirmNodeTierHardware(); + // if (hwPassed === false) { + // throw new Error('Node hardware requirements not met'); + // } // check DOS state (contains daemon checks) const dosState = await fluxCommunication.getDOSState(); if (dosState.status === 'error') { @@ -712,4 +712,5 @@ module.exports = { wsRespondLoginPhrase, wsRespondSignature, checkLoggedUser, + confirmNodeTierHardware, };