Skip to content

Commit

Permalink
Merge pull request #329 from RunOnFlux/development
Browse files Browse the repository at this point in the history
v2.0.2
  • Loading branch information
TheTrunk authored Sep 8, 2021
2 parents 5d71b69 + 1fb7ef2 commit 3f42add
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 64 deletions.
56 changes: 0 additions & 56 deletions ZelBack/src/services/fluxCommunication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -1251,7 +1249,6 @@ async function checkDeterministicNodesCollisions() {
async function getDOSState(req, res) {
const data = {
dosState,
nodeHardwareSpecsGood,
dosMessage,
};
response = serviceHelper.createDataMessage(data);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1526,5 +1471,4 @@ module.exports = {
adjustFirewall,
checkDeterministicNodesCollisions,
adjustGitRepository,
confirmNodeTierHardware,
};
46 changes: 45 additions & 1 deletion ZelBack/src/services/idService.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -10,12 +11,54 @@ const fluxCommunication = require('./fluxCommunication');

const goodchars = /^[1-9a-km-zA-HJ-NP-Z]+$/;

async function confirmNodeTierHardware() {
try {
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') {
Expand Down Expand Up @@ -669,4 +712,5 @@ module.exports = {
wsRespondLoginPhrase,
wsRespondSignature,
checkLoggedUser,
confirmNodeTierHardware,
};
4 changes: 0 additions & 4 deletions ZelBack/src/services/serviceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/ZelBack/apiTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3f42add

Please sign in to comment.