From 6f7d31b960dce27bc44b1dd2387890147410e34a Mon Sep 17 00:00:00 2001 From: DieMyst Date: Thu, 23 Feb 2023 14:30:49 +0400 Subject: [PATCH] add timeouts to config --- .../gateway/config.json | 4 +++- .../gateway/package.json | 2 +- .../gateway/src/index.js | 12 +++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/aqua-examples/decentralized-blockchain-gateway/gateway/config.json b/aqua-examples/decentralized-blockchain-gateway/gateway/config.json index 02ca0de..6aed2a4 100644 --- a/aqua-examples/decentralized-blockchain-gateway/gateway/config.json +++ b/aqua-examples/decentralized-blockchain-gateway/gateway/config.json @@ -11,5 +11,7 @@ "counterPeerId": null, "quorumServiceId": null, "quorumPeerId": null, - "quorumNumber": 2 + "quorumNumber": 2, + "quorumTimeout": null, + "requestTimeout": null } \ No newline at end of file diff --git a/aqua-examples/decentralized-blockchain-gateway/gateway/package.json b/aqua-examples/decentralized-blockchain-gateway/gateway/package.json index 06301fd..a5f6a51 100644 --- a/aqua-examples/decentralized-blockchain-gateway/gateway/package.json +++ b/aqua-examples/decentralized-blockchain-gateway/gateway/package.json @@ -1,6 +1,6 @@ { "name": "@fluencelabs/aqua-eth-gateway", - "version": "0.0.14", + "version": "0.0.15", "description": "", "main": "src/index.js", "type": "module", diff --git a/aqua-examples/decentralized-blockchain-gateway/gateway/src/index.js b/aqua-examples/decentralized-blockchain-gateway/gateway/src/index.js index a1afa61..ec070dc 100644 --- a/aqua-examples/decentralized-blockchain-gateway/gateway/src/index.js +++ b/aqua-examples/decentralized-blockchain-gateway/gateway/src/index.js @@ -65,7 +65,7 @@ registerCounter("counter", { }) function findSameResults(results, minNum) { - const resultCounts = results.filter((obj) => obj.success).map((obj) => obj.value).reduce(function(i, v, idx) { + const resultCounts = results.filter((obj) => obj.success).map((obj) => obj.value).reduce(function(i, v) { if (i[v] === undefined) { i[v] = 1 } else { @@ -106,19 +106,21 @@ const counterPeerId = config.counterPeerId || peerId const quorumServiceId = config.quorumServiceId || 'quorum' const quorumPeerId = config.quorumPeerId || peerId const quorumNumber = config.quorumNumber || 2 +const quorumTimeout = config.quorumTimeout || 10000 +const requestTimeoutConfig = config.requestTimeout ? {ttl: config.requestTimeout} : null async function methodHandler(req, method) { console.log(`Receiving request '${method}'`); let result; if (!config.mode || config.mode === "random") { - result = await randomLoadBalancingEth(config.providers, method, req.map((s) => JSON.stringify(s)), config.serviceId); + result = await randomLoadBalancingEth(config.providers, method, req.map((s) => JSON.stringify(s)), config.serviceId, requestTimeoutConfig); } else if (config.mode === "round-robin") { console.log("peerId: " + peerId) result = await roundRobinEth(config.providers, method, req.map((s) => JSON.stringify(s)), config.serviceId, counterServiceId, counterPeerId, - config.serviceId); + config.serviceId, requestTimeoutConfig); } else if (config.mode === "quorum") { - result = await quorumEth(config.providers, config.quorumNumber, 5000, method, req.map((s) => JSON.stringify(s)), config.serviceId, quorumServiceId, quorumPeerId, - config.serviceId); + result = await quorumEth(config.providers, quorumNumber, quorumTimeout, method, req.map((s) => JSON.stringify(s)), config.serviceId, quorumServiceId, quorumPeerId, + config.serviceId, requestTimeoutConfig); if (result.error) { return {error: result.error, results: result.results}