Skip to content

Commit

Permalink
Merge pull request #241 from zelcash/development
Browse files Browse the repository at this point in the history
v1.13.0
  • Loading branch information
TheTrunk authored Mar 21, 2021
2 parents 540685b + 52509d1 commit 7e418cc
Show file tree
Hide file tree
Showing 26 changed files with 683 additions and 530 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/ZelFront/dist/
/config/userconfig.js
/lib/
/lib/zelcashrpc/
/lib/daemonrpc/
/tests/
/ZelApps/
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: |
npm i
npm run ciconfig
npm run zelfrontbuild
npm run homebuild
npm run test:zelback
env:
CI: true
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ npm start
To run this as Development: Start both solutions with

```bash
npm run zelbackdev
npm run zelfrontdev
npm run fluxdev
npm run homedev
```

THE SETUP ENDS HERE...
Expand All @@ -213,13 +213,13 @@ The following information below provided for brief usage guidelines and/or examp

```bash
# serve with hot reload at localhost:16126
npm run zelfrontdev
npm run homedev

# build for production with minification
npm run zelfrontbuild
npm run homebuild

# build for production and view the bundle analyzer report
npm run zelfrontbuild --report
npm run homebuild --report
```

## Flux Information
Expand All @@ -231,7 +231,7 @@ npm run zelfrontbuild --report

```bash
# serve with hot reload at localhost:16126
npm run zelbackdev
npm run fluxdev
```

Made with ❤️ by the Flux Team
1 change: 1 addition & 0 deletions ZelBack/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
addressTransactionIndex: 'addresstransactionindex',
fluxTransactions: 'zelnodetransactions',
appsHashes: 'zelappshashes',
coinbaseFusionIndex: 'coinbasefusionindex',
},
},
appslocal: {
Expand Down
14 changes: 5 additions & 9 deletions ZelBack/src/lib/log.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const path = require('path');

const homeDirPath = path.join(__dirname, '../../../../');
const homeDirPath = path.join(__dirname, '../../../');

function getFilesizeInBytes(filename) {
try {
Expand Down Expand Up @@ -36,8 +36,7 @@ function error(args) {
try {
console.error(args);
// write to file
const datadir = `${homeDirPath}zelflux`;
const filepath = `${datadir}/error.log`;
const filepath = `${homeDirPath}error.log`;
writeToFile(filepath, args);
} catch (err) {
console.error('This shall not have happened');
Expand All @@ -49,8 +48,7 @@ function warn(args) {
try {
console.warn(args);
// write to file
const datadir = `${homeDirPath}zelflux`;
const filepath = `${datadir}/warn.log`;
const filepath = `${homeDirPath}warn.log`;
writeToFile(filepath, args);
} catch (err) {
console.error('This shall not have happened');
Expand All @@ -62,8 +60,7 @@ function info(args) {
try {
console.log(args);
// write to file
const datadir = `${homeDirPath}zelflux`;
const filepath = `${datadir}/info.log`;
const filepath = `${homeDirPath}info.log`;
writeToFile(filepath, args);
} catch (err) {
console.error('This shall not have happened');
Expand All @@ -75,8 +72,7 @@ function debug(args) {
try {
console.log(args);
// write to file
const datadir = `${homeDirPath}zelflux`;
const filepath = `${datadir}/debug.log`;
const filepath = `${homeDirPath}debug.log`;
writeToFile(filepath, args);
} catch (err) {
console.error('This shall not have happened');
Expand Down
27 changes: 21 additions & 6 deletions ZelBack/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const fluxCommunication = require('./services/fluxCommunication');
const appsService = require('./services/appsService');
const explorerService = require('./services/explorerService');

function isLocal(req, res, next) {
const remote = req.ip || req.connection.remoteAddress || req.socket.remoteAddress || req.headers['x-forwarded-for'];
if (remote === 'localhost' || remote === '127.0.0.1' || remote === '::ffff:127.0.0.1' || remote === '::1') return next();
return res.status(401).send('Access denied');
}

const cache = apicache.middleware;

module.exports = (app, expressWs) => {
Expand Down Expand Up @@ -1175,6 +1181,12 @@ module.exports = (app, expressWs) => {
app.get('/explorer/scannedheight', cache('30 seconds'), (req, res) => {
explorerService.getScannedHeight(req, res);
});
// app.get('/explorer/fusion/coinbase/all', cache('30 seconds'), (req, res) => {
// explorerService.getAllFusionCoinbase(req, res);
// });
app.get('/explorer/fusion/coinbase/:address?', cache('30 seconds'), (req, res) => {
explorerService.getAddressFusionCoinbase(req, res);
});

// GET PROTECTED API - User level
app.get('/daemon/prioritisetransaction/:txid?/:prioritydelta?/:feedelta?', cache('30 seconds'), (req, res) => {
Expand Down Expand Up @@ -1460,19 +1472,19 @@ module.exports = (app, expressWs) => {
app.get('/flux/restartdaemon', (req, res) => {
fluxService.restartDaemon(req, res);
});
app.get('/flux/updateflux', (req, res) => { // method shall be called only if zelflux version is obsolete.
app.get('/flux/updateflux', (req, res) => { // method shall be called only if flux version is obsolete.
fluxService.updateFlux(req, res);
});
app.get('/flux/hardupdateflux', (req, res) => { // method shall be called only if zelflux version is obsolete and updatezeflux is not working correctly
app.get('/flux/hardupdateflux', (req, res) => { // method shall be called only if flux version is obsolete and updatezeflux is not working correctly
fluxService.hardUpdateFlux(req, res);
});
app.get('/flux/rebuildhome', (req, res) => {
fluxService.rebuildHome(req, res);
});
app.get('/flux/updatedaemon', (req, res) => { // method shall be called only if zelcash version is obsolete
app.get('/flux/updatedaemon', (req, res) => { // method shall be called only if daemon version is obsolete
fluxService.updateDaemon(req, res);
});
app.get('/flux/updatebenchmark', (req, res) => { // method shall be called only if zelbench version is obsolete
app.get('/flux/updatebenchmark', (req, res) => { // method shall be called only if benchamrk version is obsolete
fluxService.updateBenchmark(req, res);
});
app.get('/flux/daemondebug', (req, res) => {
Expand Down Expand Up @@ -1536,6 +1548,9 @@ module.exports = (app, expressWs) => {
app.get('/flux/checkcommunication', (req, res) => {
fluxCommunication.isCommunicationEstablished(req, res);
});
app.get('/flux/backendfolder', isLocal, (req, res) => {
fluxService.fluxBackendFolder(req, res);
});

app.get('/benchmark/start', (req, res) => {
fluxService.startBenchmark(req, res);
Expand Down Expand Up @@ -1602,7 +1617,7 @@ module.exports = (app, expressWs) => {
app.get('/apps/installtemporarylocalapp/KadenaChainWebNode', (req, res) => {
appsService.installTemporaryLocalApplication(req, res, 'KadenaChainWebNode');
});
app.get('/apps/createzelfluxnetwork', (req, res) => {
app.get('/apps/createfluxnetwork', (req, res) => {
appsService.createFluxNetworkAPI(req, res);
});
app.get('/apps/rescanglobalappsinformation/:blockheight?/:removelastinformation?', (req, res) => {
Expand Down Expand Up @@ -1722,7 +1737,7 @@ module.exports = (app, expressWs) => {
idService.wsRespondSignature(ws, req);
});

// communication between multiple zelflux solution is on this:
// communication between multiple flux solution is on this:
app.ws('/ws/flux', (ws, req) => {
fluxCommunication.handleIncomingConnection(ws, req, expressWs.getWss('/ws/flux'));
});
Expand Down
44 changes: 23 additions & 21 deletions ZelBack/src/services/appsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,9 @@ async function appsResources(req, res) {
appsHddLocked += serviceHelper.ensureNumber(app.hdd) || 0;
});
const appsUsage = {
zelAppsCpusLocked: appsCpusLocked,
zelAppsRamLocked: appsRamLocked,
zelAppsHddLocked: appsHddLocked,
appsCpusLocked,
appsRamLocked,
appsHddLocked,
};
const response = serviceHelper.createDataMessage(appsUsage);
return res ? res.json(response) : response;
Expand Down Expand Up @@ -1186,7 +1186,7 @@ async function createAppVolume(appSpecifications, res) {
if (resourcesLocked.status !== 'success') {
throw new Error('Unable to obtain locked system resources by Flux App. Aborting.');
}
const hddLockedByApps = resourcesLocked.data.zelAppsHddLocked;
const hddLockedByApps = resourcesLocked.data.appsHddLocked;
const availableSpaceForApps = useableSpaceOnNode - hddLockedByApps + appSpecifications.hdd; // because our application is already accounted in locked resources
// bigger or equal so we have the 1 gb free...
if (appSpecifications.hdd >= availableSpaceForApps) {
Expand Down Expand Up @@ -1971,7 +1971,7 @@ async function checkAppRequirements(appSpecs) {

const totalSpaceOnNode = config.fluxSpecifics.hdd[tier];
const useableSpaceOnNode = totalSpaceOnNode - config.lockedSystemResources.hdd;
const hddLockedByApps = resourcesLocked.data.zelAppsHddLocked;
const hddLockedByApps = resourcesLocked.data.apsHddLocked;
const availableSpaceForApps = useableSpaceOnNode - hddLockedByApps;
// bigger or equal so we have the 1 gb free...
if (appSpecs.hdd >= availableSpaceForApps) {
Expand All @@ -1980,7 +1980,7 @@ async function checkAppRequirements(appSpecs) {

const totalCpuOnNode = config.fluxSpecifics.cpu[tier];
const useableCpuOnNode = totalCpuOnNode - config.lockedSystemResources.cpu;
const cpuLockedByApps = resourcesLocked.data.zelAppsCpusLocked * 10;
const cpuLockedByApps = resourcesLocked.data.appsCpusLocked * 10;
const adjustedAppCpu = appSpecs.cpu * 10;
const availableCpuForApps = useableCpuOnNode - cpuLockedByApps;
// bigger or equal so we have the 1 gb free...
Expand All @@ -1990,7 +1990,7 @@ async function checkAppRequirements(appSpecs) {

const totalRamOnNode = config.fluxSpecifics.ram[tier];
const useableRamOnNode = totalRamOnNode - config.lockedSystemResources.ram;
const ramLockedByApps = resourcesLocked.data.zelAppsRamLocked;
const ramLockedByApps = resourcesLocked.data.appsRamLocked;
const availableRamForApps = useableRamOnNode - ramLockedByApps;
// bigger or equal so we have the 1 gb free...
if (appSpecs.ram >= availableRamForApps) {
Expand Down Expand Up @@ -2567,31 +2567,31 @@ function checkHWParameters(appSpecs) {
}
if (appSpecs.tiered) {
if ((appSpecs.cpubasic * 10) % 1 !== 0 || (appSpecs.cpubasic * 10) > (config.fluxSpecifics.cpu.basic - config.lockedSystemResources.cpu) || appSpecs.cpubasic < 0.1) {
return new Error('CPU for BASIC badly assigned');
return new Error('CPU for Cumulus badly assigned');
}
if (appSpecs.rambasic % 100 !== 0 || appSpecs.rambasic > (config.fluxSpecifics.ram.basic - config.lockedSystemResources.ram) || appSpecs.rambasic < 100) {
return new Error('RAM for BASIC badly assigned');
return new Error('RAM for Cumulus badly assigned');
}
if (appSpecs.hddbasic % 1 !== 0 || appSpecs.hddbasic > (config.fluxSpecifics.hdd.basic - config.lockedSystemResources.hdd) || appSpecs.hddbasic < 1) {
return new Error('SSD for BASIC badly assigned');
return new Error('SSD for Cumulus badly assigned');
}
if ((appSpecs.cpusuper * 10) % 1 !== 0 || (appSpecs.cpusuper * 10) > (config.fluxSpecifics.cpu.super - config.lockedSystemResources.cpu) || appSpecs.cpusuper < 0.1) {
return new Error('CPU for SUPER badly assigned');
return new Error('CPU for Nimbus badly assigned');
}
if (appSpecs.ramsuper % 100 !== 0 || appSpecs.ramsuper > (config.fluxSpecifics.ram.super - config.lockedSystemResources.ram) || appSpecs.ramsuper < 100) {
return new Error('RAM for SUPER badly assigned');
return new Error('RAM for Nimbus badly assigned');
}
if (appSpecs.hddsuper % 1 !== 0 || appSpecs.hddsuper > (config.fluxSpecifics.hdd.super - config.lockedSystemResources.hdd) || appSpecs.hddsuper < 1) {
return new Error('SSD for SUPER badly assigned');
return new Error('SSD for Nimbus badly assigned');
}
if ((appSpecs.cpubamf * 10) % 1 !== 0 || (appSpecs.cpubamf * 10) > (config.fluxSpecifics.cpu.bamf - config.lockedSystemResources.cpu) || appSpecs.cpubamf < 0.1) {
return new Error('CPU for BAMF badly assigned');
return new Error('CPU for Stratus badly assigned');
}
if (appSpecs.rambamf % 100 !== 0 || appSpecs.rambamf > (config.fluxSpecifics.ram.bamf - config.lockedSystemResources.ram) || appSpecs.rambamf < 100) {
return new Error('RAM for BAMF badly assigned');
return new Error('RAM for Stratus badly assigned');
}
if (appSpecs.hddbamf % 1 !== 0 || appSpecs.hddbamf > (config.fluxSpecifics.hdd.bamf - config.lockedSystemResources.hdd) || appSpecs.hddbamf < 1) {
return new Error('SSD for BAMF badly assigned');
return new Error('SSD for Stratus badly assigned');
}
}
return true;
Expand Down Expand Up @@ -2696,7 +2696,7 @@ async function availableApps(req, res) {
+ 'Chainweb is a braided, parallelized Proof Of Work consensus mechanism that improves throughput and scalability in executing transactions on the blockchain while maintaining the security and integrity found in Bitcoin. '
+ 'The healthy information tells you if your node is running and synced. If you just installed the docker it can say unhealthy for long time because on first run a bootstrap is downloaded and extracted to make your node sync faster before the node is started. '
+ 'Do not stop or restart the docker in the first hour after installation. You can also check if your kadena node is synced, by going to running apps and press visit button on kadena and compare your node height with Kadena explorer. Thank you.',
repotag: 'zelcash/kadena-chainweb-node:2.5',
repotag: 'zelcash/kadena-chainweb-node:2.6',
owner: '1hjy4bCYBJr4mny4zCE85J94RXa8W6q37',
ports: [30004, 30005],
containerPorts: [30004, 30005],
Expand All @@ -2708,7 +2708,7 @@ async function availableApps(req, res) {
enviromentParameters: ['CHAINWEB_P2P_PORT=30004', 'CHAINWEB_SERVICE_PORT=30005', 'LOGLEVEL=warn'],
commands: ['/bin/bash', '-c', '(test -d /data/chainweb-db/0 && ./run-chainweb-node.sh) || (/chainweb/initialize-db.sh && ./run-chainweb-node.sh)'],
containerData: '/data', // cannot be root todo in verification
hash: 'localSpecificationsVersion6', // hash of app message
hash: 'localSpecificationsVersion7', // hash of app message
height: 680000, // height of tx on which it was
},
];
Expand Down Expand Up @@ -4560,6 +4560,10 @@ async function trySpawningGlobalApplication() {
// how do we continue with this function function?
// we have globalapplication specifics list
// check if we are synced
const tier = await nodeTier();
if (tier === 'basic') {
log.info('Basic node detected. Global applications will not be installed');
}
const synced = await checkSynced();
if (synced !== true) {
log.info('Flux not yet synced');
Expand Down Expand Up @@ -4626,7 +4630,6 @@ async function trySpawningGlobalApplication() {
}
// run the verification
// get tier and adjust specifications
const tier = await nodeTier();
if (appSpecifications.tiered) {
const hddTier = `hdd${tier}`;
const ramTier = `ram${tier}`;
Expand Down Expand Up @@ -4726,7 +4729,7 @@ async function checkAndNotifyPeersOfRunningApps() {
// we can distinguish pure local apps from global with hash and height
const broadcastedAt = new Date().getTime();
const newAppRunningMessage = {
type: 'zelapprunning', // todo rename to fluxapprunning
type: 'fluxapprunning',
version: 1,
name: application.name,
hash: application.hash, // hash of application specifics that are running
Expand Down Expand Up @@ -5313,7 +5316,6 @@ async function fluxShareDatabaseShareFile(file) {
name: file,
token: crypto.createHash('sha256').update(string).digest('hex'),
};
// put the utxo to our mongoDB utxoIndex collection.
await serviceHelper.insertOneToDatabase(databaseFluxShare, sharedCollection, fileDetail);
return fileDetail;
} catch (error) {
Expand Down
Loading

0 comments on commit 7e418cc

Please sign in to comment.