Skip to content

Commit

Permalink
Merge pull request #1081 from edenia/fix/bpjsons-load
Browse files Browse the repository at this point in the history
Fix/bpjsons load
  • Loading branch information
xavier506 authored Nov 30, 2022
2 parents 7cb5c8a + a6e1362 commit ee2472a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
6 changes: 3 additions & 3 deletions docs/producers-API-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Also, in the Antelope Tools backend, each API endpoint is requested through HTTP

## How is the data obtained?

Through the eosjs API, the system queries the `producers` table of the eosio account, with this table, we get the URLs of the Top 100 producers to obtain their `bp.json`. When the BP JSON is not obtained the producer is not consider in the results.That information is updated every 4 hours.
Through the eosjs API, the system queries the `producers` table of the eosio account, with this table, we get the URLs of the Top 150 producers to obtain their `bp.json`. When the BP JSON is not obtained the producer is not consider in the results.That information is updated every 4 hours.
**Note:** if the BP JSON is not from the current network, the nodes are removed.

You can check the [producer's table](https://eos.antelope.tools/accounts?account=eosio&table=producers) of eosio account of the EOS Network in the section of Contract Tables.
Expand Down Expand Up @@ -319,7 +319,7 @@ The `owners` array is too long.
```json
{
"path": "$",
"error": "\"input.bpParams.owners\" must contain less than or equal to 100 items",
"error": "\"input.bpParams.owners\" must contain less than or equal to 150 items",
"code": "unexpected"
}
```
```
2 changes: 1 addition & 1 deletion hapi/src/config/eos.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
process.env.HAPI_EOS_STATE_HISTORY_PLUGIN_ENDPOINT,
chainId: process.env.HAPI_EOS_API_CHAIN_ID,
eosChainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
eosTopLimit: 100,
eosTopLimit: 150,
baseAccount: process.env.HAPI_EOS_BASE_ACCOUNT,
baseAccountPassword: process.env.HAPI_EOS_BASE_ACCOUNT_PASSWORD,
faucet: {
Expand Down
3 changes: 2 additions & 1 deletion hapi/src/routes/get-producers-info.route.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Boom = require('@hapi/boom')
const Joi = require('joi')

const { eosConfig } = require('../config')
const { producerService } = require('../services')

module.exports = {
Expand All @@ -25,7 +26,7 @@ module.exports = {
input: Joi.object({
bpParams: Joi.object({
type: Joi.string().valid('api', 'ssl', 'p2p').optional(),
owners: Joi.array().items(Joi.string().required()).max(100).optional()
owners: Joi.array().items(Joi.string().required()).max(eosConfig.eosTopLimit).optional()
}).required()
}).required()
}).options({ stripUnknown: true })
Expand Down
32 changes: 25 additions & 7 deletions hapi/src/services/producer.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ const eosioService = require('./eosio.service')
const nodeService = require('./node.service')
const statsService = require('./stats.service')

const updateBPJSONs = async (producers = []) => {
const upsertMutation = `
mutation ($producers: [producer_insert_input!]!) {
insert_producer(objects: $producers, on_conflict: {constraint: producer_owner_key, update_columns: [ bp_json ]}) {
affected_rows,
}
}
`

await hasuraUtil.request(upsertMutation, { producers })
}

const updateProducers = async (producers = []) => {
const upsertMutation = `
mutation ($producers: [producer_insert_input!]!) {
insert_producer(objects: $producers, on_conflict: {constraint: producer_owner_key, update_columns: [ producer_key, unpaid_blocks,last_claim_time, url, location, producer_authority,bp_json, is_active, total_votes, total_votes_percent, total_votes_eos, vote_rewards,block_rewards, total_rewards, health_status, endpoints, rank]}) {
insert_producer(objects: $producers, on_conflict: {constraint: producer_owner_key, update_columns: [ producer_key, unpaid_blocks,last_claim_time, url, location, producer_authority, is_active, total_votes, total_votes_percent, total_votes_eos, vote_rewards,block_rewards, total_rewards, health_status, endpoints, rank]}) {
affected_rows,
returning {
id,
Expand All @@ -26,10 +38,18 @@ const updateProducers = async (producers = []) => {
}
`

let topProducers = producers.slice(0, eosConfig.eosTopLimit)

topProducers = topProducers.filter(
producer => producer?.bp_json && Object.keys(producer.bp_json).length > 0
)
await nodeService.clearNodes()
await updateBPJSONs(topProducers)

const insertedRows = await hasuraUtil.request(upsertMutation, { producers })

await hasuraUtil.request(clearMutation, {
owners: producers.map((producer) => producer.owner)
owners: producers.map(producer => producer.owner)
})

return insertedRows.insert_producer.returning
Expand All @@ -48,15 +68,13 @@ const syncProducers = async () => {
}

if (producers?.length) {
await nodeService.clearNodes()
producers = await updateProducers(producers)
await syncNodes(producers)
await syncNodes(producers.slice(0, eosConfig.eosTopLimit))
await syncEndpoints()

if (!eosConfig.stateHistoryPluginEndpoint) {
await statsService.sync()
}

}
}

Expand All @@ -78,8 +96,8 @@ const getProducersSummary = async () => {
const syncNodes = async producers => {
if (!producers?.length) return

let nodes = producers.flatMap((producer) => {
return (producer.bp_json?.nodes || []).map((node) => {
let nodes = producers.flatMap(producer => {
return (producer.bp_json?.nodes || []).map(node => {
node.producer_id = producer.id

return nodeService.getFormatNode(node)
Expand Down
2 changes: 1 addition & 1 deletion hapi/src/utils/axios.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const http = require('http')
const https = require('https')

const instance = axios.create({
timeout: 30000,
timeout: 100000,
httpAgent: new http.Agent({ timeout: 300000 }),
httpsAgent: new https.Agent({
rejectUnauthorized: false,
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/hooks/customHooks/useBlockProducerState.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const useBlockProducerState = () => {
...prev,
page: 1,
...filter,
where: { ...where, owner: prev.where?.owner },
where: { ...where, owner: prev.where?.owner, bp_json: { _is_null: false } },
}))
}, [filters, setPagination])

Expand Down

0 comments on commit ee2472a

Please sign in to comment.