Skip to content

Commit

Permalink
Merge pull request #123 from zelcash/development
Browse files Browse the repository at this point in the history
v0.67.0
  • Loading branch information
TheTrunk authored Jul 28, 2020
2 parents 6c95aa1 + 4e8916c commit 68163a2
Show file tree
Hide file tree
Showing 11 changed files with 829 additions and 86 deletions.
9 changes: 8 additions & 1 deletion ZelBack/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
zelappsMessages: 'zelappsmessages', // storage for all zelapps messages done on zelcash network
zelappsInformation: 'zelappsinformation', // stores actual state of zelapp configuration info - initial state and its overwrites with update messages
zelappsTemporaryMessages: 'zelappstemporarymessages', // storages for all zelapps messages that are not yet confirmed on the zelcash network
zelappsLocations: 'zelappslocation', // stores location of zelapps as documents containing name, hash, ip, obtainedAt
},
},
},
Expand All @@ -60,9 +61,15 @@ module.exports = {
},
address: 't1...', // apps registration address
epochstart: 690000, // zelapps epoch blockheight start
portMin: 30001, // originally should have been from 30000 but we got temporary folding there
portMin: 31000, // originally should have been from 30000 but we got temporary folding there
portMax: 39999,
maxImageSize: 300000000, // 300mb
installation: {
probability: 100,
delay: 120, // in seconds
},
blocksLasting: 22000, // registered app will live for 22000 of blocks 44000 minutes ~= 1 month
// every 100 blocks we run a check that deletes apps specifications and stops/removes the application from existence if it has been lastly updated more than 22k blocks ago
},
lockedSystemResources: {
cpu: 10, // 1 cpu core
Expand Down
20 changes: 19 additions & 1 deletion ZelBack/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ module.exports = (app, expressWs) => {
app.get('/zelcash/getzelnodecount', (req, res) => {
zelcashService.getZelNodeCount(req, res);
});
app.get('/zelcash/getdoslist', (req, res) => {
zelcashService.getDOSList(req, res);
});
app.get('/zelcash/getstartlist', (req, res) => {
zelcashService.getStartList(req, res);
});
app.get('/zelcash/getzelnodescores/:blocks?', (req, res) => { // defaults to 10
zelcashService.getZelNodeScores(req, res);
});
Expand Down Expand Up @@ -254,6 +260,9 @@ module.exports = (app, expressWs) => {
app.get('/zelapps/hashes', (req, res) => {
zelappsService.getZelAppHashes(req, res);
});
app.get('/zelapps/locations', (req, res) => {
zelappsService.getZelAppsLocations(req, res);
});

// app.get('/explorer/allutxos', (req, res) => {
// explorerService.getAllUtxos(req, res);
Expand Down Expand Up @@ -668,12 +677,21 @@ module.exports = (app, expressWs) => {
app.get('/zelapps/zelappimageremove/:image?', (req, res) => {
zelappsService.zelAppImageRemove(req, res);
});
app.get('/zelapps/zelapptemporarylocalregister/foldingathome', (req, res) => {
app.get('/zelapps/installtemporarylocalapp/zelFoldingAtHome', (req, res) => {
zelappsService.temporaryZelAppRegisterFunctionForFoldingAtHome(req, res);
});
app.get('/zelapps/createzelfluxnetwork', (req, res) => {
zelappsService.createZelFluxNetwork(req, res);
});
app.get('/zelapps/resacnglobalappsinformation/:blockheight?/:removelastinformation?', (req, res) => { // todo post, privileges
zelappsService.rescanGlobalAppsInformationAPI(req, res);
});
app.get('/zelapps/reindexglobalappsinformation', (req, res) => { // todo post, privileges
zelappsService.reindexGlobalAppsInformationAPI(req, res);
});
app.get('/zelapps/reindexglobalappslocation', (req, res) => { // todo post, privileges
zelappsService.reindexGlobalAppsLocationAPI(req, res);
});

// POST PUBLIC methods route
app.post('/zelid/verifylogin', (req, res) => {
Expand Down
53 changes: 34 additions & 19 deletions ZelBack/src/services/explorerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ async function processBlock(blockHeight) {
log.info('UTXO documents', result.size, result.count, result.avgObjSize);
log.info('ADDR documents', resultB.size, resultB.count, resultB.avgObjSize);
log.info('ZELNODE documents', resultC.size, resultC.count, resultC.avgObjSize);
if (blockDataVerbose.height >= config.zelapps.epochstart) {
zelappsService.expireGlobalApplications();
}
}
const scannedHeight = blockDataVerbose.height;
// update scanned Height in scannedBlockHeightCollection
Expand Down Expand Up @@ -534,7 +537,12 @@ async function initiateBlockProcessor(restoreDatabase, deepRestore, reindexOrRes
throw error;
}
});
log.info(resultE, resultF);
const resultG = await serviceHelper.dropCollection(databaseGlobal, config.database.zelappsglobal.collections.zelappsLocations).catch((error) => {
if (error.message !== 'ns not found') {
throw error;
}
});
log.info(resultE, resultF, resultG);
}
await databaseGlobal.collection(config.database.zelappsglobal.collections.zelappsMessages).createIndex({ hash: 1 }, { name: 'query for getting zelapp message based on hash' }); // , unique: true
await databaseGlobal.collection(config.database.zelappsglobal.collections.zelappsMessages).createIndex({ txid: 1 }, { name: 'query for getting zelapp message based on txid' });
Expand All @@ -547,6 +555,11 @@ async function initiateBlockProcessor(restoreDatabase, deepRestore, reindexOrRes
await databaseGlobal.collection(config.database.zelappsglobal.collections.zelappsInformation).createIndex({ repotag: 1 }, { name: 'query for getting zelapp based on image' });
await databaseGlobal.collection(config.database.zelappsglobal.collections.zelappsInformation).createIndex({ height: 1 }, { name: 'query for getting zelapp based on last height update' }); // we need to know the height of app adjustment
await databaseGlobal.collection(config.database.zelappsglobal.collections.zelappsInformation).createIndex({ hash: 1 }, { name: 'query for getting zelapp based on last hash' }); // , unique: true // we need to know the hash of the last message update which is the true identifier
await database.collection(config.database.zelappsglobal.collections.zelappsLocations).createIndex({ name: 1 }, { name: 'query for getting zelapp location based on zelapp specs name' });
await database.collection(config.database.zelappsglobal.collections.zelappsLocations).createIndex({ hash: 1 }, { name: 'query for getting zelapp location based on zelapp hash' });
await database.collection(config.database.zelappsglobal.collections.zelappsLocations).createIndex({ ip: 1 }, { name: 'query for getting zelapp location based on ip' });
await database.collection(config.database.zelappsglobal.collections.zelappsLocations).createIndex({ name: 1, ip: 1 }, { name: 'query for getting app based on ip and name' });
await database.collection(config.database.zelappsglobal.collections.zelappsLocations).createIndex({ name: 1, ip: 1, broadcastedAt: 1 }, { name: 'query for getting app to ensure we possess a message' });
// what if 2 app adjustment come in the same block?
// log.info(resultE, resultF);
log.info('Preparation done');
Expand Down Expand Up @@ -826,28 +839,27 @@ async function getAddressTransactions(req, res) {
}

async function getScannedHeight(req, res) {
const dbopen = serviceHelper.databaseConnection();
const database = dbopen.db(config.database.zelcash.database);
const query = { generalScannedHeight: { $gte: 0 } };
const projection = {
projection: {
_id: 0,
generalScannedHeight: 1,
},
};
const result = await serviceHelper.findOneInDatabase(database, scannedHeightCollection, query, projection).catch((error) => {
try {
const dbopen = serviceHelper.databaseConnection();
const database = dbopen.db(config.database.zelcash.database);
const query = { generalScannedHeight: { $gte: 0 } };
const projection = {
projection: {
_id: 0,
generalScannedHeight: 1,
},
};
const result = await serviceHelper.findOneInDatabase(database, scannedHeightCollection, query, projection);
if (!result) {
throw new Error('Scanning not initiated');
}
const resMessage = serviceHelper.createDataMessage(result);
res.json(resMessage);
} catch (error) {
log.error(error);
const errMessage = serviceHelper.createErrorMessage(error.message, error.name, error.code);
res.json(errMessage);
throw error;
});
if (!result) {
const errMessage = serviceHelper.createErrorMessage('Scanning not initiated');
res.json(errMessage);
throw new Error('Scanning not initiated');
}
const resMessage = serviceHelper.createDataMessage(result);
return res.json(resMessage);
}

async function checkBlockProcessingStopped(i, callback) {
Expand Down Expand Up @@ -971,6 +983,9 @@ async function rescanExplorer(req, res) {
if (currentHeight.generalScannedHeight <= blockheight) {
throw new Error('Block height shall be lower than currently scanned');
}
if (blockheight < 0) {
throw new Error('BlockHeight lower than 0');
}
let { rescanapps } = req.params;
rescanapps = rescanapps || req.query.rescanapps || false;
rescanapps = serviceHelper.ensureBoolean(rescanapps);
Expand Down
14 changes: 13 additions & 1 deletion ZelBack/src/services/serviceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ async function startFluxFunctions() {
const databaseTemp = db.db(config.database.zelappsglobal.database);
await databaseTemp.collection(config.database.zelappsglobal.collections.zelappsTemporaryMessages).createIndex({ receivedAt: 1 }, { expireAfterSeconds: 3600 });
log.info('Temporary database prepared');
log.info('Preparing zelapps locations');
// more than 1 hour. Meaning we have not received status message for a long time. So that node is no longer on a network or app is down.
await databaseTemp.collection(config.database.zelappsglobal.collections.zelappsLocations).createIndex({ broadcastedAt: 1 }, { expireAfterSeconds: 3900 });
log.info('ZelApps locations prepared');
zelfluxCommunication.adjustFirewall();
zelfluxCommunication.fluxDisovery();
// zelfluxCommunication.fluxDisovery();
log.info('Flux Discovery started');
zelfluxCommunication.keepConnectionsAlive();
zelfluxCommunication.keepIncomingConnectionsAlive();
Expand All @@ -46,7 +50,15 @@ async function startFluxFunctions() {
setInterval(() => { // every 8 mins (4 blocks)
zelappsService.continuousZelAppHashesCheck();
}, 8 * 60 * 1000);
setInterval(() => { // every 4 mins (2 blocks)
zelappsService.checkAndNotifyPeersOfRunningApps();
}, 4 * 60 * 1000);
log.info('Flux Block Processing Service started');
setTimeout(() => {
// after 10 minutes of running ok.
log.info('Starting to spawn applications');
zelappsService.trySpawningGlobalApplication();
}, 10 * 60 * 1000);
} catch (e) {
log.error(e);
setTimeout(() => {
Expand Down
Loading

0 comments on commit 68163a2

Please sign in to comment.