Skip to content

Commit

Permalink
Merge pull request #1214 from edenia/chore/temporal-block-history
Browse files Browse the repository at this point in the history
Chore/ block history
  • Loading branch information
xavier506 committed Jun 20, 2023
2 parents c03725d + d8d20ae commit 4a8887b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/deploy-libre-testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
REACT_APP_SYNC_TOLERANCE_INTERVAL: 180000
REACT_APP_TOKEN_SYMBOL: 'LIBRE'
REACT_APP_NETWORK_URL: '[{"label":"EOS","value":"https://eos.antelope.tools","mainnet":true,"pair":"eos","icon":"eos","order":1},{"label":"Proton","value":"https://proton.antelope.tools","mainnet":true,"pair":"proton","icon":"proton","order":2},{"label":"WAX","value":"https://wax.antelope.tools","mainnet":true,"pair":"wax","icon":"wax","order":3},{"label":"Telos","value":"https://telos.antelope.tools","mainnet":true,"pair":"telos","icon":"telos","order":4},{"label":"Libre","value":"https://libre.antelope.tools","mainnet":true,"pair":"libre","icon":"libre","order":5},{"label":"LACChain EOSIO","value":"https://lacchain.antelope.tools","mainnet":true,"pair":null,"icon":"lacchain","order":6},{"label":"Jungle4 Testnet","value":"https://jungle.antelope.tools","mainnet":false,"pair":"eos","icon":"jungle","order":1},{"label":"Proton Testnet","value":"https://proton-testnet.antelope.tools","mainnet":false,"pair":"proton","icon":"proton","order":2},{"label":"WAX Testnet","value":"https://wax-testnet.antelope.tools","mainnet":false,"pair":"wax","icon":"wax","order":3},{"label":"Telos Testnet","value":"https://telos-testnet.antelope.tools","mainnet":false,"pair":"telos","icon":"telos","order":4},{"label":"Libre Testnet","value":"https://libre-testnet.antelope.tools","mainnet":false,"pair":"libre","icon":"libre","order":5},{"label":"Ultra Testnet","value":"https://ultra-testnet.antelope.tools","mainnet":false,"pair":"ultra","icon":"ultra","order":6}]'
REACT_APP_DISABLED_MENU_ITEMS: '["/missed-blocks","/block-distribution"]'
REACT_APP_DISABLED_MENU_ITEMS: '["/missed-blocks"]'
REACT_APP_BLOCK_EXPLORER_URL: 'https://libre-testnet-explorer.edenia.cloud/transaction/(transaction)'
REACT_APP_STATE_HISTORY_ENABLED: 'false'
REACT_APP_GOOGLE_ANALITIC_PAGE_ID: 'G-E6Y0EC9FT8'
Expand All @@ -82,7 +82,8 @@ jobs:
# hapi
HAPI_EOS_API_NETWORK_NAME: libre
HAPI_EOS_API_ENDPOINTS: '["https://libre-testnet.edenia.cloud","https://api.testnet.libre.cryptobloks.io","https://libre-testnet.eosphere.io"]'
HAPI_EOS_STATE_HISTORY_PLUGIN_ENDPOINT: ''
HAPI_EOS_STATE_HISTORY_PLUGIN_ENDPOINT: 'ws://api-node.libre-testnet:8080'
HAPI_EOS_BLOCK_HISTORY_DAYS: 90
HAPI_EOS_API_CHAIN_ID: b64646740308df2ee06c6b72f34c0f7fa066d940e831f752db2006fcc2b78dee
HAPI_EOS_BASE_ACCOUNT: ${{ secrets.HAPI_EOS_BASE_ACCOUNT }}
HAPI_EOS_BASE_ACCOUNT_PASSWORD: ${{ secrets.HAPI_EOS_BASE_ACCOUNT_PASSWORD }}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ services:
HAPI_EOSRATE_GET_STATS_URL: '${HAPI_EOSRATE_GET_STATS_URL}'
HAPI_EOSRATE_GET_STATS_USER: '${HAPI_EOSRATE_GET_STATS_USER}'
HAPI_EOSRATE_GET_STATS_PASSWORD: '${HAPI_EOSRATE_GET_STATS_PASSWORD}'
HAPI_EOS_BLOCK_HISTORY_DAYS: '${HAPI_EOS_BLOCK_HISTORY_DAYS}'
hasura:
container_name: '${STAGE}-${APP_NAME}-hasura'
image: hasura/graphql-engine:v2.16.0.cli-migrations-v3
Expand Down
2 changes: 2 additions & 0 deletions hapi/src/config/eos.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module.exports = {
: '',
stateHistoryPluginEndpoint:
process.env.HAPI_EOS_STATE_HISTORY_PLUGIN_ENDPOINT,
keepBlockHistoryForDays:
parseInt(process.env.HAPI_EOS_BLOCK_HISTORY_DAYS) || 0,
chainId: process.env.HAPI_EOS_API_CHAIN_ID,
eosChainId:
'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
Expand Down
18 changes: 18 additions & 0 deletions hapi/src/services/state-history-plugin.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ const handleBlocksResult = async data => {
}
}

const cleanOldBlocks = async () => {
const date = new Date()
const days = eosConfig.keepBlockHistoryForDays

date.setSeconds(date.getSeconds() - 60 * 60 * 24 * days)

const mutation = `
mutation ($date: timestamptz) {
delete_block_history (where: {timestamp: {_lt: $date}}) {
affected_rows
}
}
`

await hasuraUtil.request(mutation, { date })
}

const init = async () => {
if (!eosConfig.stateHistoryPluginEndpoint) {
return
Expand Down Expand Up @@ -177,5 +194,6 @@ const init = async () => {
}

module.exports = {
cleanOldBlocks,
init
}
3 changes: 2 additions & 1 deletion hapi/src/services/transactions.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const getTransactions = async (range = '3 Hours') => {
FROM
interval
LEFT JOIN
block_history ON date_trunc('${granularity}', block_history.timestamp) = interval.value
( SELECT * FROM block_history WHERE transactions_length > 0 )
AS block_history ON date_trunc('${granularity}', block_history.timestamp) = interval.value
GROUP BY
1
ORDER BY
Expand Down
4 changes: 2 additions & 2 deletions hapi/src/workers/producers.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ const start = async () => {
run('CPU WORKER', cpuService.worker, workersConfig.cpuWorkerInterval)
run('CPU WORKER CLEANUP', cpuService.cleanOldBenchmarks, 86400)
}

if (eosConfig.stateHistoryPluginEndpoint) {
run('BLOCK HISTORY CLEANUP', stateHistoryPluginService.cleanOldBlocks, 43200)
run('SYNC BLOCK HISTORY', stateHistoryPluginService.init)
run('SYNC MISSED BLOCKS', missedBlocksService.syncMissedBlocks)
run('SYNC MISSED BLOCKS PER PRODUCER', statsService.getCurrentMissedBlock)
run('SYNC SCHEDULE HISTORY', demuxService.init)
run('SYNC TPS', statsService.syncTPSAllTimeHigh)
run('SYNC TRX BY INTERVALS', statsService.formatTransactionHistory, 10800)
run(
'SYNC TRANSACTIONS INFO',
statsService.syncTransactionsInfo,
Expand Down
1 change: 1 addition & 0 deletions kubernetes/configmap-dashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ data:
HAPI_EOSRATE_GET_STATS_URL: '${HAPI_EOSRATE_GET_STATS_URL}'
HAPI_EOSRATE_GET_STATS_USER: '${HAPI_EOSRATE_GET_STATS_USER}'
HAPI_EOSRATE_GET_STATS_PASSWORD: '${HAPI_EOSRATE_GET_STATS_PASSWORD}'
HAPI_EOS_BLOCK_HISTORY_DAYS: '${HAPI_EOS_BLOCK_HISTORY_DAYS}'
---
apiVersion: v1
kind: ConfigMap
Expand Down

0 comments on commit 4a8887b

Please sign in to comment.