diff --git a/src/endpoints.js b/src/endpoints.js index 8cdceaa..2708cdb 100644 --- a/src/endpoints.js +++ b/src/endpoints.js @@ -63,7 +63,9 @@ const getChainData = async (registryName) => { }; const filterAliveRestRpcs = async (rpcs) => { - let alive = await Promise.allSettled(rpcs.map(async rpc => { + let aliveRestRpcs = []; + + for (let rpc of rpcs) { try { let response = await axios({ method: "GET", @@ -72,26 +74,27 @@ const filterAliveRestRpcs = async (rpcs) => { }); if (!response || response.status !== 200) - return; + continue; - let blockTime = Date.parse(response?.data?.block?.header?.time); + let blockTime = Date.parse(response.data.block.header.time); let now = Date.now(); if (Math.abs(now - blockTime) < oldBlockMs) { - //console.log(`${rpc.address} is alive, sync block ${response?.data?.block?.header?.height}`); - return rpc; + aliveRestRpcs.push(rpc); + continue; } - //console.log(`${rpc.address} is alive, but not synced`); + } catch (err) { - //console.log(`${rpc.address} is dead. Error ${err?.message}`) } - })) + } - return alive.map(x => x.value).filter(x => !!x); + return aliveRestRpcs; } const filterAliveRpcs = async (rpcs) => { - let alive = await Promise.allSettled(rpcs.map(async rpc => { + let aliveRpcs = []; + + for (let rpc of rpcs) { try { let response = await axios({ method: "GET", @@ -100,22 +103,23 @@ const filterAliveRpcs = async (rpcs) => { }); if (!response || response.status !== 200) - return; + continue; let blockTime = Date.parse(response?.data?.result?.sync_info?.latest_block_time); let now = Date.now(); if (Math.abs(now - blockTime) < oldBlockMs) { //console.log(`${rpc.address} is alive, sync block ${response.data.result.sync_info.latest_block_height}`); - return rpc; + aliveRpcs.push(rpc); + continue; } //console.log(`${rpc.address} is alive, but not synced`); } catch (err) { - //console.log(`${rpc.address} is dead. Error ${err?.message}`) + //console.log(`${rpc.address} is dead. Error ${err?.message}`) } - })); + } - return alive.map(x => x.value).filter(x => !!x); + return aliveRpcs; } const reportStats = (networkName, rpcAddress, rpcType, result) => { diff --git a/src/helpers.js b/src/helpers.js index d7d7852..54c01a5 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -3,7 +3,7 @@ const { Registry } = require("@cosmjs/proto-signing"); const { defaultRegistryTypes } = require("@cosmjs/stargate"); const big = require("big.js"); const osmojs = require("osmojs"); -const { getValidatorInfo } = require("./requests"); +const { getValidatorProfiles, getValidatorInfo } = require("./requests"); const sifchainDecoder = require("../chain-specific/sifchain/tx"); const { getValidatorByAddress, saveValidator } = require("./db"); diff --git a/src/requests.js b/src/requests.js index 16781e4..21af2b6 100644 --- a/src/requests.js +++ b/src/requests.js @@ -84,7 +84,7 @@ const getTxsInBlock = async (networkName, height) => { const pollForLatestHeight = async (networkName) => { let endpoints = getEndpoints(networkName, "rpc"); - let results = await Promise.allSettled(endpoints.map(async (e) => { + let results = await Promise.all(endpoints.map(async (e) => { let url = `${e.address}/status` let { data } = await axios({ method: "GET",