From bd74e0045c9146e2e5972850c7443e9838389ce1 Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Sun, 23 Oct 2022 22:54:23 +0100 Subject: [PATCH 1/4] Improve usage of last resort rate limited nodes --- chains/chainApis.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chains/chainApis.js b/chains/chainApis.js index 398b06e..226a4ca 100644 --- a/chains/chainApis.js +++ b/chains/chainApis.js @@ -52,7 +52,9 @@ function ChainApis(health) { }) } - function filterUrls(urls){ + function filterUrls(originalUrls, includeRateLimited){ + let urls = [...originalUrls] + if(!includeRateLimited) urls = urls.filter(el => !el.rateLimited) const bestHeight = Math.max(...urls.map(el => el.blockHeight).filter(Number.isFinite)) urls = urls.filter(el => { if (!el.blockHeight) @@ -74,10 +76,8 @@ function ChainApis(health) { return el.lastErrorAt <= (bestErrors + BEST_ERROR_DIFF * 1000) }) - const withoutRateLimit = urls.filter(el => !el.rateLimited) - if(withoutRateLimit.length){ - urls = withoutRateLimit - } + if(!urls.length && !includeRateLimited) return filterUrls(originalUrls, true) + return urls.sort((a, b) => { return a.responseTime - b.responseTime }) From 8c3ddbfa169a993061afdb63e6c4d1d64d0513ca Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Tue, 25 Oct 2022 11:26:58 +0100 Subject: [PATCH 2/4] Improve public node matcher --- validators/validator.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/validators/validator.js b/validators/validator.js index e6f846c..645b161 100644 --- a/validators/validator.js +++ b/validators/validator.js @@ -121,14 +121,15 @@ export class Validator { } publicNodes(){ - if(!this.path) return - const apis = this.chain.chain.apis + const matchers = [this.moniker.trim().toLowerCase(), this.moniker.toLowerCase().replace(/\s+/g, '')] + if(this.path) matchers.push(this.path.trim().toLowerCase(), this.path.trim().toLowerCase().replace(/\s+/g, '')) + if(this.name) matchers.push(this.name.trim().toLowerCase(), this.name.trim().toLowerCase().replace(/\s+/g, '')) return Object.keys(apis).reduce((sum, type) => { const owned = apis[type].filter(api => { if(!api.provider) return false - return [this.path, _.startCase(this.path), this.name.trim()].includes(api.provider) + return matchers.includes(api.provider.trim().toLowerCase()) || matchers.includes(api.provider.trim().toLowerCase().replace(/\s+/g, '')) }) if (owned.length) { sum[type] = owned From 630858634bdbf7130f6146a0157748cb3efb0d86 Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Tue, 25 Oct 2022 13:00:30 +0100 Subject: [PATCH 3/4] Handle not found validators --- validators/validator.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/validators/validator.js b/validators/validator.js index 645b161..eabffca 100644 --- a/validators/validator.js +++ b/validators/validator.js @@ -122,7 +122,8 @@ export class Validator { publicNodes(){ const apis = this.chain.chain.apis - const matchers = [this.moniker.trim().toLowerCase(), this.moniker.toLowerCase().replace(/\s+/g, '')] + const matchers = [] + if(this.moniker) matchers.push(this.moniker.trim().toLowerCase(), this.moniker.toLowerCase().replace(/\s+/g, '')) if(this.path) matchers.push(this.path.trim().toLowerCase(), this.path.trim().toLowerCase().replace(/\s+/g, '')) if(this.name) matchers.push(this.name.trim().toLowerCase(), this.name.trim().toLowerCase().replace(/\s+/g, '')) return Object.keys(apis).reduce((sum, type) => { From 2acf7d4fe6a5abb9feb6670ac81f6f2818552100 Mon Sep 17 00:00:00 2001 From: Tom Beynon Date: Sun, 30 Oct 2022 15:09:19 +0000 Subject: [PATCH 4/4] Fix config merging --- chains/chain.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chains/chain.js b/chains/chain.js index 1db8a44..7a35886 100644 --- a/chains/chain.js +++ b/chains/chain.js @@ -1,16 +1,16 @@ +import _ from 'lodash' import ChainApis from "./chainApis.js"; import ChainAsset from './chainAsset.js' function Chain(client, data, paramsData, opts) { - const config = { + const config = _.merge({ consensusPrefix: `${data.chain.bech32_prefix}valcons`, monitor: { delegations: true, slashes: true, signing_info: true - }, - ...opts - } + } + }, opts) const { path, chain, assetlist } = data; const { params, versions, services, prices } = paramsData