From 1a39426a0a8a6ce904c57c4799c1e932c31346e0 Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Fri, 7 Oct 2022 00:28:38 +0100 Subject: [PATCH 1/2] Fix final address when using callback path --- status/healthMonitor.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/status/healthMonitor.js b/status/healthMonitor.js index 0f8d0c9..a7526d3 100644 --- a/status/healthMonitor.js +++ b/status/healthMonitor.js @@ -38,10 +38,10 @@ function HealthMonitor() { const request = async () => { try { let address = new URL(url.address).href.replace(/\/$|$/, '/') - const response = await getLatestBlock(address, type, urlPath(type)) - return buildUrl(type, chain, url, urlHealth, response); + const { path, response } = await getLatestBlock(address, type, urlPath(type)) + return buildUrl({ type, chain, url, urlHealth, path, response }); } catch (error) { - return buildUrl(type, chain, url, urlHealth, undefined, error); + return buildUrl({ type, chain, url, urlHealth, error }); } }; return queue.add(request, { identifier: url.address }); @@ -49,11 +49,14 @@ function HealthMonitor() { async function getLatestBlock(url, type, path){ try { - return await got.get(url + path, { - timeout: { request: HEALTH_TIMEOUT }, - retry: { limit: 1 }, - agent: agent - }); + return { + path, + response: await got.get(url + path, { + timeout: { request: HEALTH_TIMEOUT }, + retry: { limit: 1 }, + agent: agent + }) + } } catch (error) { const fallback = fallbackPath(type) if (fallback && fallback !== path && error.response?.statusCode === 501) { @@ -84,7 +87,7 @@ function HealthMonitor() { } } - function buildUrl(type, chain, url, urlHealth, response, error) { + function buildUrl({ type, chain, url, urlHealth, path, response, error }) { let timings, body, data let blockTime = urlHealth?.blockTime let blockHeight = urlHealth?.blockHeight || 0; @@ -92,7 +95,7 @@ function HealthMonitor() { if (!error) { ({ timings, body } = response) data = JSON.parse(body); - const regex = new RegExp(`${urlPath(type)}/?$`) + const regex = new RegExp(`${path}/?$`) finalAddress = new URL(response.url).href.replace(regex, '').replace(/\/$|$/, '/'); ({ error, blockTime, blockHeight } = checkHeader(type, data, chain.chainId)); }else{ From dc545148562f51c3c95e70be189f5af9f825fb92 Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Fri, 7 Oct 2022 00:28:44 +0100 Subject: [PATCH 2/2] Handle missing chain --- validators/validatorsController.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/validators/validatorsController.js b/validators/validatorsController.js index 2f9613e..4f95a49 100644 --- a/validators/validatorsController.js +++ b/validators/validatorsController.js @@ -51,9 +51,12 @@ function ValidatorsController(chainRegistry, validatorRegistry) { router.get('/chains/:chain/:validatorAddress', async (ctx, next) => { const chain = await chainRegistry.getChain(ctx.params.chain); - let validatorAddress = ctx.params.validatorAddress - let registryValidator = await validatorRegistry.getRegistryValidatorFromAddress(validatorAddress) - let validator = await validatorRegistry.getChainValidator(chain, validatorAddress, registryValidator) + let validator + if(chain){ + let validatorAddress = ctx.params.validatorAddress + let registryValidator = await validatorRegistry.getRegistryValidatorFromAddress(validatorAddress) + validator = await validatorRegistry.getChainValidator(chain, validatorAddress, registryValidator) + } renderJson(ctx, validator && { name: chain.path, validator: validator