From 3dd02ab85b3b1f73fef298896f2b1757d5b87e39 Mon Sep 17 00:00:00 2001 From: TheTrunk Date: Thu, 13 Jul 2023 08:50:48 +0700 Subject: [PATCH 1/9] fix inconsistent getAddressTransactions --- ZelBack/src/services/explorerService.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ZelBack/src/services/explorerService.js b/ZelBack/src/services/explorerService.js index 57a285d9e..789d6b207 100644 --- a/ZelBack/src/services/explorerService.js +++ b/ZelBack/src/services/explorerService.js @@ -441,7 +441,7 @@ async function processInsight(blockDataVerbose, database) { }; // Unique hash - If we already have a hash of this app in our database, do not insert it! try { - // 5501c7dd6516c3fc2e68dee8d4fdd20d92f57f8cfcdc7b4fcbad46499e43ed6f + // 5501c7dd6516c3fc2e68dee8d4fdd20d92f57f8cfcdc7b4fcbad46499e43ed6f const querySearch = { hash: message, }; @@ -574,7 +574,7 @@ async function processStandard(blockDataVerbose, database) { }; // Unique hash - If we already have a hash of this app in our database, do not insert it! try { - // 5501c7dd6516c3fc2e68dee8d4fdd20d92f57f8cfcdc7b4fcbad46499e43ed6f + // 5501c7dd6516c3fc2e68dee8d4fdd20d92f57f8cfcdc7b4fcbad46499e43ed6f const querySearch = { hash: message, }; @@ -1401,7 +1401,7 @@ async function getAddressTransactions(req, res) { query: {}, }; const insightResult = await daemonServiceAddressRpcs.getSingleAddresssTxids(daemonRequest); - const txids = insightResult.data.reverse(); + const txids = insightResult.data.reverse(); // from newest txid to lastest [{txid:'abc'}, {txid: 'efg'}] const txidsOK = []; txids.forEach((txid) => { txidsOK.push({ @@ -1416,8 +1416,17 @@ async function getAddressTransactions(req, res) { const query = { address }; const distinct = 'transactions'; const results = await dbHelper.distinctDatabase(database, addressTransactionIndexCollection, distinct, query); - // TODO FIX documentation. UPDATE for an amount of last txs needed. - // now we have array of transactions [{txid, height}, {}...] + // sort by height, newest first + // only return txids + results.sort((a, b) => { + if (a.height > b.height) return -1; + if (a.height < b.height) return 1; + return 0; + }); + // eslint-disable-next-line no-param-reassign + results.map((tx) => delete tx.height); + // TODO FIX documentation. + // now we have array of transactions txids only sorted from newest to latest [{txid}, {}...] const resMessage = messageHelper.createDataMessage(results); res.json(resMessage); } From 71893989826b36fe140f9b3e2847a9eb351398d4 Mon Sep 17 00:00:00 2001 From: Cabecinha84 Date: Sat, 15 Jul 2023 19:58:05 +0100 Subject: [PATCH 2/9] skip watchtower from forceAppRemovals --- ZelBack/src/services/appsService.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ZelBack/src/services/appsService.js b/ZelBack/src/services/appsService.js index 66b5b94b6..7787bc691 100644 --- a/ZelBack/src/services/appsService.js +++ b/ZelBack/src/services/appsService.js @@ -9246,7 +9246,8 @@ async function forceAppRemovals() { }); // array of unique main app names - const dockerAppsTrueNameB = [...new Set(dockerAppsTrueNames)]; + let dockerAppsTrueNameB = [...new Set(dockerAppsTrueNames)]; + dockerAppsTrueNameB = dockerAppsTrueNameB.filter((appName) => appName !== 'watchtower'); // eslint-disable-next-line no-restricted-syntax for (const dApp of dockerAppsTrueNameB) { // check if app is in installedApps From 47b85d5d336d277a8d3ca56a2c36f906d0c7d5cb Mon Sep 17 00:00:00 2001 From: Cabecinha84 Date: Sat, 15 Jul 2023 20:03:57 +0100 Subject: [PATCH 3/9] Reduce logging --- ZelBack/src/services/fluxCommunication.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ZelBack/src/services/fluxCommunication.js b/ZelBack/src/services/fluxCommunication.js index 2a1042449..1b37b1439 100644 --- a/ZelBack/src/services/fluxCommunication.js +++ b/ZelBack/src/services/fluxCommunication.js @@ -592,6 +592,7 @@ async function fluxDiscovery() { log.info(`Current number of incoming connections:${incomingConnections.length}`); // always try to connect to deterministic nodes // established deterministic outgoing connections + let deterministicPeerConnections = false; for (let i = 1; i <= minDeterministicOutPeers; i += 1) { const fixedIndex = fluxNodeIndex + i < sortedNodeList.length ? fluxNodeIndex + i : fluxNodeIndex + i - sortedNodeList.length; const { ip } = sortedNodeList[fixedIndex]; @@ -599,7 +600,7 @@ async function fluxDiscovery() { const clientExists = outgoingConnections.find((client) => client._socket.remoteAddress === ip); const clientIncomingExists = incomingConnections.find((client) => client._socket.remoteAddress.replace('::ffff:', '') === ip); if (!clientExists && !clientIncomingExists) { - log.info(`Adding Flux peer: ${ip}`); + deterministicPeerConnections = true; initiateAndHandleConnection(ip); // eslint-disable-next-line no-await-in-loop await serviceHelper.delay(500); @@ -612,13 +613,16 @@ async function fluxDiscovery() { // additional precaution const clientIncomingExists = incomingConnections.find((client) => client._socket.remoteAddress.replace('::ffff:', '') === ip); if (!clientIncomingExists) { - log.info(`Asking Flux ${ip} to add us as a peer`); + deterministicPeerConnections = true; const ipInc = ip.split(':')[0]; const portInc = ip.split(':')[1] || 16127; // eslint-disable-next-line no-await-in-loop await serviceHelper.axiosGet(`http://${ipInc}:${portInc}/flux/addoutgoingpeer/${myIP}`).catch((error) => log.error(error)); } } + if (deterministicPeerConnections) { + log.info('Connections to deterministic peers established'); + } await serviceHelper.delay(500); let index = 0; From 454fb8da65584be784f9a338d3c75eb6ca18c44b Mon Sep 17 00:00:00 2001 From: Cabecinha84 Date: Mon, 17 Jul 2023 12:31:26 +0100 Subject: [PATCH 4/9] Allow node to bind privileged ports --- ZelBack/src/services/fluxNetworkHelper.js | 10 ++++++++++ ZelBack/src/services/serviceManager.js | 2 ++ 2 files changed, 12 insertions(+) diff --git a/ZelBack/src/services/fluxNetworkHelper.js b/ZelBack/src/services/fluxNetworkHelper.js index 5757196e5..087bb9dd2 100644 --- a/ZelBack/src/services/fluxNetworkHelper.js +++ b/ZelBack/src/services/fluxNetworkHelper.js @@ -1348,6 +1348,15 @@ function lruRateLimit(ip, limitPerSecond = 20) { return true; } +/** + * Allow Node to bind to privileged without sudo + */ +async function allowNodeToBindPrivilegedPorts() { + const exec = "sudo setcap 'cap_net_bind_service=+ep' `which node`"; + const cmdAsync = util.promisify(nodecmd.get); + await cmdAsync(exec); +} + module.exports = { minVersionSatisfy, isFluxAvailable, @@ -1391,4 +1400,5 @@ module.exports = { isPortEnterprise, isPortBanned, isPortUserBlocked, + allowNodeToBindPrivilegedPorts, }; diff --git a/ZelBack/src/services/serviceManager.js b/ZelBack/src/services/serviceManager.js index 23e986e2b..71458f492 100644 --- a/ZelBack/src/services/serviceManager.js +++ b/ZelBack/src/services/serviceManager.js @@ -76,6 +76,8 @@ async function startFluxFunctions() { log.info('Flux Apps locations prepared'); fluxNetworkHelper.adjustFirewall(); log.info('Firewalls checked'); + fluxNetworkHelper.allowNodeToBindPrivilegedPorts(); + log.info('Node allowed to bind privileged ports'); fluxCommunication.keepConnectionsAlive(); log.info('Connections polling prepared'); daemonServiceMiscRpcs.daemonBlockchainInfoService(); From b4e1d9453af28357f0315ffcac130d642e449e85 Mon Sep 17 00:00:00 2001 From: Cabecinha84 Date: Mon, 17 Jul 2023 12:35:22 +0100 Subject: [PATCH 5/9] test --- ZelBack/config/default.js | 2 +- ZelBack/src/services/appsService.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ZelBack/config/default.js b/ZelBack/config/default.js index 22fea6ef4..ee8bb0850 100644 --- a/ZelBack/config/default.js +++ b/ZelBack/config/default.js @@ -137,7 +137,7 @@ module.exports = { portMax: 39999, portBlockheightChange: isDevelopment ? 1390000 : 1420000, portMinNew: 1, - portMaxNew: 65535, + portMaxNew: 1024, bannedPorts: ['16100-16299', '26100-26299', '30000-30099', 8384, 27017, 22, 23, 25, 3389, 5900, 5800, 161, 512, 513, 5901, 3388, 4444, 123], enterprisePorts: ['0-1023', 8080, 8081, 8443, 25565, 6667], maxImageSize: 2000000000, // 2000mb diff --git a/ZelBack/src/services/appsService.js b/ZelBack/src/services/appsService.js index 7787bc691..2c44b116f 100644 --- a/ZelBack/src/services/appsService.js +++ b/ZelBack/src/services/appsService.js @@ -9598,6 +9598,7 @@ async function checkMyAppsAvailability() { const min = minPort; const max = maxPort; testingPort = failedPort || Math.floor(Math.random() * (max - min) + min); + log.info(`checkMyAppsAvailability testing port ${testingPort}.`); const iBP = fluxNetworkHelper.isPortBanned(testingPort); if (iBP) { failedPort = null; From bc9a81f443edf8812082a719085c72bbe0d86af7 Mon Sep 17 00:00:00 2001 From: Cabecinha84 Date: Mon, 17 Jul 2023 12:47:01 +0100 Subject: [PATCH 6/9] fix portMaxNew --- ZelBack/config/default.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZelBack/config/default.js b/ZelBack/config/default.js index ee8bb0850..22fea6ef4 100644 --- a/ZelBack/config/default.js +++ b/ZelBack/config/default.js @@ -137,7 +137,7 @@ module.exports = { portMax: 39999, portBlockheightChange: isDevelopment ? 1390000 : 1420000, portMinNew: 1, - portMaxNew: 1024, + portMaxNew: 65535, bannedPorts: ['16100-16299', '26100-26299', '30000-30099', 8384, 27017, 22, 23, 25, 3389, 5900, 5800, 161, 512, 513, 5901, 3388, 4444, 123], enterprisePorts: ['0-1023', 8080, 8081, 8443, 25565, 6667], maxImageSize: 2000000000, // 2000mb From f4516121d9b45a45be7036e1e9e1e9f689dd8816 Mon Sep 17 00:00:00 2001 From: Cabecinha84 Date: Mon, 17 Jul 2023 17:04:52 +0100 Subject: [PATCH 7/9] add try catch --- ZelBack/src/services/fluxNetworkHelper.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ZelBack/src/services/fluxNetworkHelper.js b/ZelBack/src/services/fluxNetworkHelper.js index 087bb9dd2..ddfffef3b 100644 --- a/ZelBack/src/services/fluxNetworkHelper.js +++ b/ZelBack/src/services/fluxNetworkHelper.js @@ -1352,9 +1352,13 @@ function lruRateLimit(ip, limitPerSecond = 20) { * Allow Node to bind to privileged without sudo */ async function allowNodeToBindPrivilegedPorts() { - const exec = "sudo setcap 'cap_net_bind_service=+ep' `which node`"; - const cmdAsync = util.promisify(nodecmd.get); - await cmdAsync(exec); + try { + const exec = "sudo setcap 'cap_net_bind_service=+ep' `which node`"; + const cmdAsync = util.promisify(nodecmd.get); + await cmdAsync(exec); + } catch (error) { + log.error(error); + } } module.exports = { From 5b9a4e463dd458c98efedd1275518836d35a7732 Mon Sep 17 00:00:00 2001 From: TheTrunk Date: Tue, 18 Jul 2023 11:00:22 +0700 Subject: [PATCH 8/9] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 689194448..17619e5d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "flux", - "version": "4.3.0", + "version": "4.4.0", "description": "Flux, Your Gateway to a Decentralized World", "repository": { "type": "git", From ba226abc94c7801db5e40a01d948445d94c132be Mon Sep 17 00:00:00 2001 From: TheTrunk Date: Tue, 18 Jul 2023 19:07:31 +0700 Subject: [PATCH 9/9] remove duplicate --- ZelBack/src/routes.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/ZelBack/src/routes.js b/ZelBack/src/routes.js index 84e8daa2b..e0de711ed 100644 --- a/ZelBack/src/routes.js +++ b/ZelBack/src/routes.js @@ -444,9 +444,6 @@ module.exports = (app, expressWs) => { app.get('/syncthing/system/error/:message?', cache('30 seconds'), (req, res) => { syncthingService.systemError(req, res); }); - app.get('/syncthing/system/error/:message?', cache('30 seconds'), (req, res) => { - syncthingService.systemError(req, res); - }); app.get('/syncthing/system/log/:since?', cache('30 seconds'), (req, res) => { syncthingService.systemLog(req, res); });