Skip to content

Commit

Permalink
Revert "check rpcs in parallel"
Browse files Browse the repository at this point in the history
This reverts commit ed77104.
  • Loading branch information
seleniumforest committed Nov 21, 2022
1 parent ed77104 commit f2d755f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
34 changes: 19 additions & 15 deletions src/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
2 changes: 1 addition & 1 deletion src/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f2d755f

Please sign in to comment.