Skip to content

Commit

Permalink
Merge pull request #50 from eco-stake/improve-rate-limited-usage
Browse files Browse the repository at this point in the history
Improve usage of rate limited nodes as a last resort
  • Loading branch information
tombeynon committed Nov 1, 2022
2 parents 7e173b3 + 2acf7d4 commit beabd4e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
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

0 comments on commit beabd4e

Please sign in to comment.