Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve usage of rate limited nodes as a last resort #50

Merged
merged 4 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions chains/chain.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 5 additions & 5 deletions chains/chainApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
})
Expand Down
8 changes: 5 additions & 3 deletions validators/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,16 @@ export class Validator {
}

publicNodes(){
if(!this.path) return

const apis = this.chain.chain.apis
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) => {
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
Expand Down