Skip to content

Commit

Permalink
Merge branch 'dev' into lacchain
Browse files Browse the repository at this point in the history
  • Loading branch information
xavier506 committed Apr 21, 2021
2 parents 91b3e9c + 6b88d75 commit 6114c87
Show file tree
Hide file tree
Showing 59 changed files with 770 additions and 344 deletions.
2 changes: 2 additions & 0 deletions .env.jungle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ HASURA_GRAPHQL_ENABLE_CONSOLE=true
HASURA_GRAPHQL_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HASURA_GRAPHQL_ADMIN_SECRET=myadminsecretkey
HASURA_GRAPHQL_UNAUTHORIZED_ROLE=guest
HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090

# hapi
HAPI_EOS_API_ENDPOINT=https://jungle3.cryptolions.io
Expand All @@ -38,6 +39,7 @@ HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_SYNC_EXCHANGE_RATE=86400
HAPI_SYNC_STATS_INTERVAL=60

#webapp
PORT=3000
Expand Down
2 changes: 2 additions & 0 deletions .env.lacchain
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ HASURA_GRAPHQL_ENABLE_CONSOLE=true
HASURA_GRAPHQL_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HASURA_GRAPHQL_ADMIN_SECRET=myadminsecretkey
HASURA_GRAPHQL_UNAUTHORIZED_ROLE=guest
HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090

# hapi
HAPI_EOS_API_NETWORK_NAME=lacchain
Expand All @@ -39,6 +40,7 @@ HAPI_SERVER_ADDRESS=hapi
HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_SYNC_STATS_INTERVAL=60

#webapp
PORT=3000
Expand Down
2 changes: 2 additions & 0 deletions .env.mainnet
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ HASURA_GRAPHQL_ENABLE_CONSOLE=true
HASURA_GRAPHQL_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HASURA_GRAPHQL_ADMIN_SECRET=myadminsecretkey
HASURA_GRAPHQL_UNAUTHORIZED_ROLE=guest
HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090

# hapi
HAPI_EOS_API_ENDPOINT=https://api.eosio.cr
Expand All @@ -38,6 +39,7 @@ HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=0
HAPI_SYNC_EXCHANGE_RATE=86400
HAPI_SYNC_STATS_INTERVAL=60

#webapp
PORT=3000
Expand Down
30 changes: 17 additions & 13 deletions .env.telostestnet
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ HASURA_GRAPHQL_ENABLE_CONSOLE=true
HASURA_GRAPHQL_DATABASE_URL=postgres://eoscr:password@postgres:5432/localdb
HASURA_GRAPHQL_ADMIN_SECRET=myadminsecretkey
HASURA_GRAPHQL_UNAUTHORIZED_ROLE=guest
HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090

# hapi
HAPI_TELOS_API_ENDPOINT=https://telos-testnet.eosio.cr
HAPI_TELOS_API_CHAIN_ID=2a02a0053e5a8cf73a56ba0fda11e4d92e0238a4a2aa74fccf46d5a910746840
HAPI_TELOS_BASE_ACCOUNT=eosmechatero
HAPI_TELOS_BASE_ACCOUNT_PASSWORD=PW...
HAPI_TELOS_MECHANICS_ACCOUNT=eosmechatero
HAPI_EOS_API_ENDPOINT=https://telos-testnet.eosio.cr
HAPI_EOS_API_CHAIN_ID=1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f
HAPI_EOS_BASE_ACCOUNT=eosmechatero
HAPI_EOS_BASE_ACCOUNT_PASSWORD=PW...
HAPI_EOS_MECHANICS_ACCOUNT=eosmechatero
# TODO: add value
HAPI_TELOS_MECHANICS_PASSWORD=PW...
HAPI_TELOS_WALLET_URL=http://localhost:9999
HAPI_EOS_MECHANICS_PASSWORD=PW...
HAPI_EOS_WALLET_URL=http://localhost:9999
# TODO: let's discuss this
HAPI_TELOS_EXCHANGE_RATE_API=https://api.coingecko.com/api/v3/simple/price?ids=telos&vs_currencies=usd
HAPI_TELOS_BP_JSON_ON_CHAIN=false
HAPI_TELOS_BP_JSON_ON_CHAIN_CONTRACT=producerjson
HAPI_TELOS_BP_JSON_ON_CHAIN_TABLE=producerjson
HAPI_TELOS_BP_JSON_ON_CHAIN_SCOPE=producerjson
HAPI_EOS_EXCHANGE_RATE_API=https://api.coingecko.com/api/v3/simple/price?ids=telos&vs_currencies=usd
HAPI_EOS_BP_JSON_ON_CHAIN=false
HAPI_EOS_BP_JSON_ON_CHAIN_CONTRACT=producerjson
HAPI_EOS_BP_JSON_ON_CHAIN_TABLE=producerjson
HAPI_EOS_BP_JSON_ON_CHAIN_SCOPE=producerjson
HAPI_HASURA_URL=http://hasura:8080/v1/graphql
HAPI_HASURA_ADMIN_SECRET=myadminsecretkey
HAPI_SERVER_PORT=9090
Expand All @@ -40,6 +41,8 @@ HAPI_SYNC_PRODUCERS_INTERVAL=86400
HAPI_SYNC_PRODUCER_INFO_INTERVAL=1
HAPI_SYNC_PRODUCER_CPU_INTERVAL=6
HAPI_SYNC_EXCHANGE_RATE=86400
HAPI_COINGECKO_API_TOKEN_ID=telos
HAPI_SYNC_STATS_INTERVAL=60

#webapp
PORT=3000
Expand All @@ -66,4 +69,5 @@ REACT_APP_EOS_CHAIN_ID=1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f319
REACT_APP_EOS_USE_BP_JSON_ON_CHAIN=false
REACT_APP_EOS_BP_JSON_ON_CHAIN_CONTRACT=producerjson
REACT_APP_EOS_BP_JSON_ON_CHAIN_TABLE=producerjson
REACT_APP_EOS_BP_JSON_ON_CHAIN_SCOPE=producerjson
REACT_APP_EOS_BP_JSON_ON_CHAIN_SCOPE=producerjson
REACT_APP_TOKEN_SYMBOL=TLOS
3 changes: 2 additions & 1 deletion .github/workflows/push-dev-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
HAPI_HASURA_URL: http://monitor-hasura:8080/v1/graphql
HAPI_HASURA_ADMIN_SECRET: ${{ secrets.HAPI_HASURA_ADMIN_SECRET }}
HAPI_SERVER_PORT: 9090
HAPI_SERVER_ADDRESS: 127.0.0.1
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_SYNC_PRODUCERS_INTERVAL: 86400
HAPI_SYNC_PRODUCER_INFO_INTERVAL: 1
HAPI_SYNC_PRODUCER_CPU_INTERVAL: 6
Expand All @@ -122,6 +122,7 @@ jobs:
HASURA_GRAPHQL_ADMIN_SECRET: ${{ secrets.HASURA_GRAPHQL_ADMIN_SECRET }}
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: ${{ secrets.HASURA_GRAPHQL_UNAUTHORIZED_ROLE }}
HASURA_GRAPHQL_MIGRATIONS_DIR: /hasura-migrations
HASURA_GRAPHQL_ACTION_BASE_URL: http://monitor-hapi:9090

- name: Setup and deploy kubernetes environment
uses: steebchen/kubectl@master
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/push-lacchain-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
HAPI_HASURA_ADMIN_SECRET: ${{ secrets.HAPI_HASURA_ADMIN_SECRET }}
HAPI_EOS_STATE_HISTORY_PLUGIN_ENDPOINT: 'ws://observer.eosio.cr:8888'
HAPI_HASURA_URL: 'http://monitor-hasura:8080/v1/graphql'
HAPI_SERVER_ADDRESS: '127.0.0.1'
HAPI_SERVER_ADDRESS: '0.0.0.0'
HAPI_SERVER_PORT: '9090'
HAPI_SYNC_PRODUCERS_INTERVAL: '86400'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '6'
Expand All @@ -123,6 +123,7 @@ jobs:
HASURA_GRAPHQL_ADMIN_SECRET: ${{ secrets.HASURA_GRAPHQL_ADMIN_SECRET }}
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: ${{ secrets.HASURA_GRAPHQL_UNAUTHORIZED_ROLE }}
HASURA_GRAPHQL_MIGRATIONS_DIR: /hasura-migrations
HASURA_GRAPHQL_ACTION_BASE_URL: http://monitor-hapi:9090

- name: Setup and deploy kubernetes environment
uses: steebchen/kubectl@master
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/push-master-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
HAPI_HASURA_URL: "http://monitor-hasura:8080/v1/graphql"
HAPI_HASURA_ADMIN_SECRET: ${{ secrets.HAPI_HASURA_ADMIN_SECRET }}
HAPI_SERVER_PORT: "9090"
HAPI_SERVER_ADDRESS: "127.0.0.1"
HAPI_SERVER_ADDRESS: "0.0.0.0"
HAPI_SYNC_PRODUCERS_INTERVAL: "86400"
HAPI_SYNC_PRODUCER_INFO_INTERVAL: "1"
HAPI_SYNC_PRODUCER_CPU_INTERVAL: "6"
Expand All @@ -113,6 +113,7 @@ jobs:
HASURA_GRAPHQL_ADMIN_SECRET: ${{ secrets.HASURA_GRAPHQL_ADMIN_SECRET }}
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: ${{ secrets.HASURA_GRAPHQL_UNAUTHORIZED_ROLE }}
HASURA_GRAPHQL_MIGRATIONS_DIR: /hasura-migrations
HASURA_GRAPHQL_ACTION_BASE_URL: http://monitor-hapi:9090

- name: Setup and deploy kubernetes environment
uses: steebchen/kubectl@master
Expand Down
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"arcanis.vscode-zipfs",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"editor.tabSize": 2,
"editor.renderWhitespace": "all",
"editor.formatOnSave": true
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.formatOnSave": true
}
}
6 changes: 5 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ services:
HAPI_SYNC_PRODUCERS_INTERVAL: '${HAPI_SYNC_PRODUCERS_INTERVAL}'
HAPI_SYNC_PRODUCER_INFO_INTERVAL: '${HAPI_SYNC_PRODUCER_INFO_INTERVAL}'
HAPI_SYNC_PRODUCER_CPU_INTERVAL: '${HAPI_SYNC_PRODUCER_CPU_INTERVAL}'
HAPI_COINGECKO_API_TOKEN_ID: '${HAPI_COINGECKO_API_TOKEN_ID}'
HAPI_SYNC_STATS_INTERVAL: '${HAPI_SYNC_STATS_INTERVAL}'
hasura:
container_name: '${STAGE}-${APP_NAME}-hasura'
image: hasura/graphql-engine:v1.3.3.cli-migrations-v2
image: hasura/graphql-engine:v2.0.0-alpha.9.cli-migrations-v2
ports:
- '8585:8080'
volumes:
Expand All @@ -66,6 +68,7 @@ services:
HASURA_GRAPHQL_ENABLE_CONSOLE: '${HASURA_GRAPHQL_ENABLE_CONSOLE}'
HASURA_GRAPHQL_ADMIN_SECRET: '${HASURA_GRAPHQL_ADMIN_SECRET}'
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: '${HASURA_GRAPHQL_UNAUTHORIZED_ROLE}'
HASURA_GRAPHQL_ACTION_BASE_URL: '${HASURA_GRAPHQL_ACTION_BASE_URL}'
webapp:
container_name: '${STAGE}-${APP_NAME}-webapp'
image: node:14.2.0
Expand Down Expand Up @@ -100,3 +103,4 @@ services:
REACT_APP_EOS_BP_JSON_ON_CHAIN_CONTRACT: '${REACT_APP_EOS_BP_JSON_ON_CHAIN_CONTRACT}'
REACT_APP_EOS_BP_JSON_ON_CHAIN_TABLE: '${REACT_APP_EOS_BP_JSON_ON_CHAIN_TABLE}'
REACT_APP_EOS_BP_JSON_ON_CHAIN_SCOPE: '${REACT_APP_EOS_BP_JSON_ON_CHAIN_SCOPE}'
REACT_APP_TOKEN_SYMBOL: '${REACT_APP_TOKEN_SYMBOL}'
2 changes: 2 additions & 0 deletions hapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"graphql-request": "^1.8.2",
"hapi-pino": "^6.5.0",
"http-status-codes": "^1.4.0",
"joi": "^17.4.0",
"moment": "^2.29.1",
"ws": "^7.4.4"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions hapi/src/config/eos.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
},
walletUrl: process.env.HAPI_EOS_WALLET_URL,
exchangeRateApi: process.env.HAPI_EOS_EXCHANGE_RATE_API,
coingeckoApiTokenId: process.env.HAPI_COINGECKO_API_TOKEN_ID,
bpJsonOnChain: process.env.HAPI_EOS_BP_JSON_ON_CHAIN === 'true',
bpJsonOnChainContract: process.env.HAPI_EOS_BP_JSON_ON_CHAIN_CONTRACT,
bpJsonOnChainTable: process.env.HAPI_EOS_BP_JSON_ON_CHAIN_TABLE,
Expand Down
1 change: 1 addition & 0 deletions hapi/src/config/workers.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = {
syncProducerCpuInterval: parseInt(
process.env.HAPI_SYNC_PRODUCER_CPU_INTERVAL || 0
),
syncStatsInterval: parseInt(process.env.HAPI_SYNC_STATS_INTERVAL || 60),
syncExchangeRate: parseInt(process.env.HAPI_SYNC_EXCHANGE_RATE || 86400)
}
20 changes: 20 additions & 0 deletions hapi/src/routes/block-distribution.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const Joi = require('joi')

const { statsService } = require('../services')

module.exports = {
method: 'POST',
path: '/block-distribution',
handler: ({ payload: { input } }) =>
statsService.getBlockDistribution(input.range),
options: {
validate: {
payload: Joi.object({
input: Joi.object({
range: Joi.string().required()
}).required()
}).options({ stripUnknown: true })
},
auth: false
}
}
3 changes: 2 additions & 1 deletion hapi/src/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const healthzRoute = require('./healthz/healthz.route')
const blockDistributionRoute = require('./block-distribution.route')

module.exports = [healthzRoute]
module.exports = [healthzRoute, blockDistributionRoute]
4 changes: 3 additions & 1 deletion hapi/src/services/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const producerService = require('./producer.service')
const settingService = require('./setting.service')
const stateHistoryPluginService = require('./state-history-plugin.service')
const statsService = require('./stats.service')

module.exports = {
producerService,
settingService,
stateHistoryPluginService
stateHistoryPluginService,
statsService
}
33 changes: 10 additions & 23 deletions hapi/src/services/producer.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,15 @@ const syncProducersInfo = async () => {
}

const syncCpuUsage = async () => {
const { block, transaction } = await eosmechanicsUtil.cpu()
await insertUsage('cpu', {
account: block.producer,
usage: transaction.processed.receipt.cpu_usage_us
})
try {
const { block, transaction } = await eosmechanicsUtil.cpu()
await insertUsage('cpu', {
account: block.producer,
usage: transaction.processed.receipt.cpu_usage_us
})
} catch (error) {
console.error(error)
}
}

const syncRamUsage = async () => {
Expand Down Expand Up @@ -625,7 +629,6 @@ const checkForMissedBlocks = async () => {

// wait until first turn change
while (currentProducer === lastProducer) {
console.log('waiting for first turn change')
info = await eosApi.getInfo({})
lastProducer = currentProducer
currentProducer = info.head_block_producer
Expand Down Expand Up @@ -665,11 +668,6 @@ const checkForMissedBlocks = async () => {
currentProducer === lastProducer
) {
// change producer in case that the currentProducer and the next one are missing blocks
console.log(
'check point',
lastProducerIndex + 1,
currentSchedule.active.producers.length
)
const nextProducerIndex =
lastProducerIndex + 1 >= currentSchedule.active.producers.length
? 0
Expand All @@ -680,28 +678,19 @@ const checkForMissedBlocks = async () => {

if (lastProducer !== currentProducer) {
// we have a new producer so we should save the missed blocks for the previous one
console.log(
`save data for ${lastProducer} missed bloks: ${missedBlocks} produced bloks: ${producedBlocks}`
)
await saveMissedBlocksFor(lastProducer, missedBlocks)
producedBlocks = 0
missedBlocks = 0
}

if (currentBlockNum === lastBlockNum) {
// when the previous block and the current block are equals we have a missed block
console.log(
`Houston, we have a problem: one missed block from ${currentProducer} will impact the network`
)
missedBlocks += 1
} else {
// when the previous block and the current block are diferent we have a new block
console.log(`new block from ${currentProducer}`)
producedBlocks += 1
}
console.log(
`current producer is: ${currentProducer} missedBlocks: ${missedBlocks} producedBlocks: ${producedBlocks}`
)

lastProducer = currentProducer
lastBlockNum = currentBlockNum
} catch (error) {
Expand All @@ -710,10 +699,8 @@ const checkForMissedBlocks = async () => {

const endTime = new Date()
const msDiff = endTime.getTime() - startTime.getTime()
console.log(`finished after ${msDiff}`)

if (msDiff < 500) {
console.log(`will run again in ${500 - msDiff}`)
await new Promise(resolve => setTimeout(() => resolve(), 501 - msDiff))
}
}
Expand Down
6 changes: 3 additions & 3 deletions hapi/src/services/setting.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { hasuraUtil, axiosUtil } = require('../utils')

const UPSERT = `
mutation ($setting: setting_insert_input!) {
insert_setting(objects: [$setting], on_conflict: {constraint: setting_pkey, update_columns: [eos_price]}) {
insert_setting(objects: [$setting], on_conflict: {constraint: setting_pkey, update_columns: [token_price]}) {
affected_rows
}
}
Expand All @@ -18,12 +18,12 @@ const syncEOSPrice = async () => {

const { data } = await axiosUtil.instance.get(eosConfig.exchangeRateApi)

if (!data || !data.success) {
if (!data) {
return
}

await hasuraUtil.request(UPSERT, {
setting: { id: 1, eos_price: data.rates.EOS }
setting: { id: 1, token_price: data[eosConfig.coingeckoApiTokenId].usd }
})
} catch (error) {
console.error(error)
Expand Down
Loading

0 comments on commit 6114c87

Please sign in to comment.